void f(unsigned& i, unsigned& j) __attribute__ ((noinline));
void f(unsigned& i, unsigned& j)
{
if (i == j) {
j = 0;
i++;
} else {
j++;
}
}
void g(unsigned& i, unsigned& j) __attribute__ ((noinline));
void g(unsigned& i, unsigned& j)
{
const bool eq = i == j;
i += eq;
j = (j + 1) * (1 - eq);
}
void h(unsigned& i, unsigned& j) __attribute__ ((noinline));
void h(unsigned& i, unsigned& j)
{
const bool eq = i == j;
i += eq;
j = (j + 1) & (eq - 1);
}
#include <iostream>
int main()
{
unsigned i = 0, j = 0;
while (i < 5) { std::cout << i << ':' << j << ' '; f(i, j); }
std::cout << '\n'; i = 0; j = 0;
while (i < 5) { std::cout << i << ':' << j << ' '; g(i, j); }
std::cout << '\n'; i = 0; j = 0;
while (i < 5) { std::cout << i << ':' << j << ' '; h(i, j); }
std::cout << '\n'; i = 0; j = 0;
for (int rep = 0; rep < 1000000; ++rep) {
i = 0; j = 0;
while (i < 19) { f(i, j); g(i, j); h(i, j); }
}
std::cout << j << '\n';
}
dm9pZCBmKHVuc2lnbmVkJiBpLCB1bnNpZ25lZCYgaikgX19hdHRyaWJ1dGVfXyAoKG5vaW5saW5lKSk7CnZvaWQgZih1bnNpZ25lZCYgaSwgdW5zaWduZWQmIGopCnsKaWYgKGkgPT0gaikgewogICAgaiA9IDA7CiAgICBpKys7CiAgfSBlbHNlIHsKICAgIGorKzsKICB9Cn0KCnZvaWQgZyh1bnNpZ25lZCYgaSwgdW5zaWduZWQmIGopIF9fYXR0cmlidXRlX18gKChub2lubGluZSkpOwp2b2lkIGcodW5zaWduZWQmIGksIHVuc2lnbmVkJiBqKQp7CiAgY29uc3QgYm9vbCBlcSA9IGkgPT0gajsKICBpICs9IGVxOwogIGogPSAoaiArIDEpICogKDEgLSBlcSk7Cn0KCnZvaWQgaCh1bnNpZ25lZCYgaSwgdW5zaWduZWQmIGopIF9fYXR0cmlidXRlX18gKChub2lubGluZSkpOwp2b2lkIGgodW5zaWduZWQmIGksIHVuc2lnbmVkJ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