#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device uint* prevent_dce;
  threadgroup atomic_uint* arg_0;
};

struct tint_symbol_1 {
  atomic_uint tint_symbol;
};

uint atomicLoad_361bf1(tint_module_vars_struct tint_module_vars) {
  uint 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, 0u, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
  (*tint_module_vars.prevent_dce) = atomicLoad_361bf1(tint_module_vars);
}

kernel void compute_main(uint tint_local_index [[thread_index_in_threadgroup]], device uint* 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);
}
