#include <metal_stdlib>
using namespace metal;

struct atomic_compare_exchange_result_i32 {
  int old_value;
  bool exchanged;
};

struct tint_module_vars_struct {
  device atomic_int* a;
  thread bool* continue_execution;
};

struct foo_outputs {
  int tint_symbol [[color(0)]];
};

atomic_compare_exchange_result_i32 v(device atomic_int* const atomic_ptr, int cmp, int val) {
  int old_value = cmp;
  bool const v_1 = atomic_compare_exchange_weak_explicit(atomic_ptr, (&old_value), val, memory_order_relaxed, memory_order_relaxed);
  return atomic_compare_exchange_result_i32{.old_value=old_value, .exchanged=v_1};
}

int foo_inner(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.continue_execution) = false;
  int x = 0;
  atomic_compare_exchange_result_i32 v_2 = {};
  if ((*tint_module_vars.continue_execution)) {
    v_2 = v(tint_module_vars.a, 0, 1);
  }
  atomic_compare_exchange_result_i32 const result = v_2;
  if (result.exchanged) {
    x = result.old_value;
  }
  if (!((*tint_module_vars.continue_execution))) {
    discard_fragment();
  }
  return x;
}

fragment foo_outputs foo(device atomic_int* a [[buffer(0)]]) {
  thread bool continue_execution = true;
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.a=a, .continue_execution=(&continue_execution)};
  return foo_outputs{.tint_symbol=foo_inner(tint_module_vars)};
}
