#include <metal_stdlib>

using namespace metal;

#define TINT_ISOLATE_UB(VOLATILE_NAME) \
  volatile bool VOLATILE_NAME = true; \
  if (VOLATILE_NAME)

struct tint_private_vars_struct {
  bool tint_discarded;
};

int f(int x, thread tint_private_vars_struct* const tint_private_vars) {
  if ((x == 10)) {
    (*(tint_private_vars)).tint_discarded = true;
  }
  return x;
}

struct tint_symbol_2 {
  int3 x [[user(locn1)]] [[flat]];
};

struct tint_symbol_3 {
  int value [[color(2)]];
};

int tint_symbol_inner(int3 x, thread tint_private_vars_struct* const tint_private_vars) {
  int y = x[0];
  TINT_ISOLATE_UB(tint_volatile_true) while(true) {
    int const r = f(y, tint_private_vars);
    if ((r == 0)) {
      break;
    }
  }
  return y;
}

fragment tint_symbol_3 tint_symbol(tint_symbol_2 tint_symbol_1 [[stage_in]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  tint_private_vars.tint_discarded = false;
  int const inner_result = tint_symbol_inner(tint_symbol_1.x, &(tint_private_vars));
  tint_symbol_3 wrapper_result = {};
  wrapper_result.value = inner_result;
  if (tint_private_vars.tint_discarded) {
    discard_fragment();
  }
  return wrapper_result;
}

