#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 atomicAnd_34edd3(threadgroup atomic_uint* const tint_symbol_1) {
  uint res = atomic_fetch_and_explicit(tint_symbol_1, 1u, 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) = atomicAnd_34edd3(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;
}

