#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 atomicLoad_afcc03(tint_module_vars_struct tint_module_vars) {
  int res = atomic_load_explicit(tint_module_vars.arg_0, 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) = atomicLoad_afcc03(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);
}
