#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);
}

void atomicStore_8bea94(threadgroup atomic_int* const tint_symbol_1) {
  atomic_store_explicit(tint_symbol_1, 1, memory_order_relaxed);
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_int* const tint_symbol_2) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
  atomicStore_8bea94(tint_symbol_2);
}

kernel void compute_main(uint local_invocation_index [[thread_index_in_threadgroup]]) {
  threadgroup atomic_int tint_symbol_3;
  compute_main_inner(local_invocation_index, &(tint_symbol_3));
  return;
}

