#include <metal_stdlib>

using namespace metal;

struct atomic_compare_exchange_result_u32 {
  uint old_value;
  bool exchanged;
};
atomic_compare_exchange_result_u32 atomicCompareExchangeWeak_1(threadgroup atomic_uint* atomic, uint compare, uint value) {
  uint old_value = compare;
  bool exchanged = atomic_compare_exchange_weak_explicit(atomic, &old_value, value, memory_order_relaxed, memory_order_relaxed);
  return {old_value, exchanged};
}

void tint_zero_workgroup_memory(uint local_idx, threadgroup atomic_uint* const tint_symbol) {
  {
    atomic_store_explicit(tint_symbol, 0u, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

void atomicCompareExchangeWeak_83580d(threadgroup atomic_uint* const tint_symbol_1) {
  uint arg_1 = 1u;
  uint arg_2 = 1u;
  atomic_compare_exchange_result_u32 res = atomicCompareExchangeWeak_1(tint_symbol_1, arg_1, arg_2);
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_uint* const tint_symbol_2) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
  atomicCompareExchangeWeak_83580d(tint_symbol_2);
}

kernel void compute_main(uint local_invocation_index [[thread_index_in_threadgroup]]) {
  threadgroup atomic_uint tint_symbol_3;
  compute_main_inner(local_invocation_index, &(tint_symbol_3));
  return;
}

