#include <metal_stdlib>

using namespace metal;
void tint_zero_workgroup_memory(uint local_idx, threadgroup atomic_int* const tint_symbol) {
  {
    atomic_store_explicit(tint_symbol, 0, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

void atomicLoad_afcc03(threadgroup atomic_int* const tint_symbol_1, device int* const tint_symbol_2) {
  int res = atomic_load_explicit(tint_symbol_1, memory_order_relaxed);
  *(tint_symbol_2) = res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_int* const tint_symbol_3, device int* const tint_symbol_4) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_3);
  atomicLoad_afcc03(tint_symbol_3, tint_symbol_4);
}

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

