#include <metal_stdlib>

using namespace metal;
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);
}

int atomicExchange_e114ba(threadgroup atomic_int* const tint_symbol_1) {
  int arg_1 = 1;
  int res = atomic_exchange_explicit(tint_symbol_1, arg_1, memory_order_relaxed);
  return res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_int* const tint_symbol_2, device int* const tint_symbol_3) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
  *(tint_symbol_3) = atomicExchange_e114ba(tint_symbol_2);
}

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

