#include <metal_stdlib>

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

uint atomicLoad_361bf1(threadgroup atomic_uint* const tint_symbol_1) {
  uint res = atomic_load_explicit(tint_symbol_1, memory_order_relaxed);
  return res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_uint* const tint_symbol_2, device uint* const tint_symbol_3) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
  *(tint_symbol_3) = atomicLoad_361bf1(tint_symbol_2);
}

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

