#include <metal_stdlib>

using namespace metal;
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 atomicExchange_0a5dca(threadgroup atomic_uint* const tint_symbol_1, device uint* const tint_symbol_2) {
  uint arg_1 = 1u;
  uint res = atomic_exchange_explicit(tint_symbol_1, arg_1, memory_order_relaxed);
  *(tint_symbol_2) = res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_uint* const tint_symbol_3, device uint* const tint_symbol_4) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_3);
  atomicExchange_0a5dca(tint_symbol_3, tint_symbol_4);
}

kernel void compute_main(device uint* tint_symbol_6 [[buffer(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
  threadgroup atomic_uint tint_symbol_5;
  compute_main_inner(local_invocation_index, &(tint_symbol_5), tint_symbol_6);
  return;
}

