#include <metal_stdlib>
using namespace metal;
struct atomic_compare_exchange_result_i32 {
  int old_value;
  bool exchanged;
};
struct tint_module_vars_struct {
  threadgroup atomic_int* arg_0;
};
struct tint_symbol_1 {
  atomic_int tint_symbol;
};

atomic_compare_exchange_result_i32 v(threadgroup 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};
}
void atomicCompareExchangeWeak_e88938(tint_module_vars_struct tint_module_vars) {
  int arg_1 = 1;
  int arg_2 = 1;
  atomic_compare_exchange_result_i32 res = v(tint_module_vars.arg_0, arg_1, arg_2);
}
void compute_main_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    atomic_store_explicit(tint_module_vars.arg_0, 0, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  atomicCompareExchangeWeak_e88938(tint_module_vars);
}
kernel void compute_main(uint tint_local_index [[thread_index_in_threadgroup]], threadgroup tint_symbol_1* v_2 [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=(&(*v_2).tint_symbol)};
  compute_main_inner(tint_local_index, tint_module_vars);
}
