Very interesting. That first stanza is indeed wrongly placed. But when you move it, does it start working?
I tried a couple of things without success. So, what code should be placed in where?
And why does it seem that ./configure is not getting the --with-tcmalloc option at all?
No idea.