#include <metal_stdlib>
using namespace metal;

struct atomic_compare_exchange_result_u32 {
  uint old_value;
  bool exchanged;
};

struct tint_module_vars_struct {
  threadgroup atomic_uint* arg_0;
};

struct tint_symbol_1 {
  atomic_uint tint_symbol;
};

atomic_compare_exchange_result_u32 v(threadgroup atomic_uint* const atomic_ptr, uint cmp, uint val) {
  uint 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_u32{.old_value=old_value, .exchanged=v_1};
}

void atomicCompareExchangeWeak_83580d(tint_module_vars_struct tint_module_vars) {
  atomic_compare_exchange_result_u32 res = v(tint_module_vars.arg_0, 1u, 1u);
}

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, 0u, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  atomicCompareExchangeWeak_83580d(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);
}
