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

void atomicMax_beccfc(threadgroup atomic_uint* const tint_symbol_1, device uint* const tint_symbol_2) {
  uint arg_1 = 1u;
  uint res = atomic_fetch_max_explicit(tint_symbol_1, arg_1, memory_order_relaxed);
  *(tint_symbol_2) = res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_uint* const tint_symbol_3, device uint* const tint_symbol_4) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_3);
  atomicMax_beccfc(tint_symbol_3, tint_symbol_4);
}

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

