#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  uint local_invocation_index_1;
};

struct S0_atomic {
  int x;
  atomic_uint a;
  int y;
  int z;
};

struct S1_atomic {
  int x;
  S0_atomic a;
  int y;
  int z;
};

struct S2_atomic {
  int x;
  int y;
  int z;
  S1_atomic a;
};

void tint_zero_workgroup_memory(uint local_idx, threadgroup S2_atomic* const tint_symbol) {
  {
    (*(tint_symbol)).x = 0;
    (*(tint_symbol)).y = 0;
    (*(tint_symbol)).z = 0;
    (*(tint_symbol)).a.x = 0;
    (*(tint_symbol)).a.a.x = 0;
    atomic_store_explicit(&((*(tint_symbol)).a.a.a), 0u, memory_order_relaxed);
    (*(tint_symbol)).a.a.y = 0;
    (*(tint_symbol)).a.a.z = 0;
    (*(tint_symbol)).a.y = 0;
    (*(tint_symbol)).a.z = 0;
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

struct S0 {
  int x;
  uint a;
  int y;
  int z;
};

struct S1 {
  int x;
  S0 a;
  int y;
  int z;
};

struct S2 {
  int x;
  int y;
  int z;
  S1 a;
};

void compute_main_inner(uint local_invocation_index_2, threadgroup S2_atomic* const tint_symbol_1) {
  (*(tint_symbol_1)).x = 0;
  (*(tint_symbol_1)).y = 0;
  (*(tint_symbol_1)).z = 0;
  (*(tint_symbol_1)).a.x = 0;
  (*(tint_symbol_1)).a.a.x = 0;
  atomic_store_explicit(&((*(tint_symbol_1)).a.a.a), 0u, memory_order_relaxed);
  (*(tint_symbol_1)).a.a.y = 0;
  (*(tint_symbol_1)).a.a.z = 0;
  (*(tint_symbol_1)).a.y = 0;
  (*(tint_symbol_1)).a.z = 0;
  threadgroup_barrier(mem_flags::mem_threadgroup);
  atomic_store_explicit(&((*(tint_symbol_1)).a.a.a), 1u, memory_order_relaxed);
  return;
}

void compute_main_1(thread tint_private_vars_struct* const tint_private_vars, threadgroup S2_atomic* const tint_symbol_2) {
  uint const x_44 = (*(tint_private_vars)).local_invocation_index_1;
  compute_main_inner(x_44, tint_symbol_2);
  return;
}

void compute_main_inner_1(uint local_invocation_index_1_param, thread tint_private_vars_struct* const tint_private_vars, threadgroup S2_atomic* const tint_symbol_3) {
  tint_zero_workgroup_memory(local_invocation_index_1_param, tint_symbol_3);
  (*(tint_private_vars)).local_invocation_index_1 = local_invocation_index_1_param;
  compute_main_1(tint_private_vars, tint_symbol_3);
}

kernel void compute_main(uint local_invocation_index_1_param [[thread_index_in_threadgroup]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  threadgroup S2_atomic tint_symbol_4;
  compute_main_inner_1(local_invocation_index_1_param, &(tint_private_vars), &(tint_symbol_4));
  return;
}

