#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device int* prevent_dce;
  threadgroup atomic_int* arg_0;
};

struct tint_symbol_1 {
  atomic_int tint_symbol;
};

int atomicMin_278235(tint_module_vars_struct tint_module_vars) {
  int arg_1 = 1;
  int res = atomic_fetch_min_explicit(tint_module_vars.arg_0, arg_1, memory_order_relaxed);
  return res;
}

void compute_main_inner(uint tint_local_index, tint_module_vars_struct tint_module_vars) {
  if ((tint_local_index == 0u)) {
    atomic_store_explicit(tint_module_vars.arg_0, 0, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  (*tint_module_vars.prevent_dce) = atomicMin_278235(tint_module_vars);
}

kernel void compute_main(uint tint_local_index [[thread_index_in_threadgroup]], device int* prevent_dce [[buffer(0)]], threadgroup tint_symbol_1* v [[threadgroup(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce, .arg_0=(&(*v).tint_symbol)};
  compute_main_inner(tint_local_index, tint_module_vars);
}
