#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 atomicMin_278235(threadgroup atomic_int* const tint_symbol_1) {
  int res = atomic_fetch_min_explicit(tint_symbol_1, 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) = atomicMin_278235(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;
}

