Is it required to declare mem/tmp as volatile? That seems to help, and doing printf(tmp) also helps to avoid endless loop. Even SLE_12 gets this wrong...