local variable resets to zero
I think I found the problem, see code comments:

int main(void){
   int loopTimes = 0;

   for(;;) {

   // compiler knows that this condition MUST be true the first time 
   // it runs, since loopTimes is 0
   if (loopTimes &gt;= 0) { 
      loopTimes--;
   }

   // loopTime is now -1 !

   if(TWI_has_data()) {

       twi_read_data(rxBuffer,2);

       // this condition is NEVER true, because loopTime is -1 and will 
       // never be changed again since there are no further assignments
       if (loopTimes == 0) { 
           loopTimes = rxBuffer[0];
       }
   }
}
}


As a result, the compiler optimizes a whole bunch of code away, because it will never be executed or useful anyway. If the variable is global, the compiler can not make this assumption that easily.

Fix your problem by either changing 

if (loopTimes &gt;= 0)


to 

if (loopTimes &gt; 0)


or change

if (loopTimes == 0)


accordingly.