#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) {
  if ((local_idx < 1u)) {
    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) {
  atomic_compare_exchange_result_u32 res = atomicCompareExchangeWeak_1(tint_symbol_1, 1u, 1u);
}

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;
}

