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';
}
