#include <metal_stdlib>

using namespace metal;

struct atomic_compare_exchange_result_i32 {
  int old_value;
  bool exchanged;
};
atomic_compare_exchange_result_i32 atomicCompareExchangeWeak_1(threadgroup atomic_int* atomic, int compare, int value) {
  int 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_int* const tint_symbol) {
  if ((local_idx < 1u)) {
    atomic_store_explicit(tint_symbol, 0, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

void atomicCompareExchangeWeak_e88938(threadgroup atomic_int* const tint_symbol_1) {
  atomic_compare_exchange_result_i32 res = atomicCompareExchangeWeak_1(tint_symbol_1, 1, 1);
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_int* const tint_symbol_2) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
  atomicCompareExchangeWeak_e88938(tint_symbol_2);
}

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

