#include <metal_stdlib>

using namespace metal;

template<typename T, size_t N>
struct tint_array {
    const constant T& operator[](size_t i) const constant { return elements[i]; }
    device T& operator[](size_t i) device { return elements[i]; }
    const device T& operator[](size_t i) const device { return elements[i]; }
    thread T& operator[](size_t i) thread { return elements[i]; }
    const thread T& operator[](size_t i) const thread { return elements[i]; }
    threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
    const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
    T elements[N];
};

#define TINT_ISOLATE_UB(VOLATILE_NAME) \
  {volatile bool VOLATILE_NAME = false; if (VOLATILE_NAME) break;}

struct tint_private_vars_struct {
  tint_array<int4, 4> src_private;
};

void tint_zero_workgroup_memory(uint local_idx, threadgroup tint_array<int4, 4>* const tint_symbol_5, threadgroup tint_array<int4, 4>* const tint_symbol_6, threadgroup tint_array<tint_array<tint_array<int, 2>, 3>, 4>* const tint_symbol_7) {
  for(uint idx = local_idx; (idx < 4u); idx = (idx + 1u)) {
    TINT_ISOLATE_UB(tint_volatile_false);
    uint const i = idx;
    (*(tint_symbol_5))[i] = int4(0);
    (*(tint_symbol_6))[i] = int4(0);
  }
  for(uint idx_1 = local_idx; (idx_1 < 24u); idx_1 = (idx_1 + 1u)) {
    TINT_ISOLATE_UB(tint_volatile_false_1);
    uint const i_1 = (idx_1 / 6u);
    uint const i_2 = ((idx_1 % 6u) / 2u);
    uint const i_3 = (idx_1 % 2u);
    (*(tint_symbol_7))[i_1][i_2][i_3] = 0;
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

struct S {
  /* 0x0000 */ tint_array<int4, 4> arr;
};

tint_array<int4, 4> ret_arr() {
  tint_array<int4, 4> const tint_symbol_2 = tint_array<int4, 4>{};
  return tint_symbol_2;
}

S ret_struct_arr() {
  S const tint_symbol_3 = S{};
  return tint_symbol_3;
}

void foo(tint_array<int4, 4> src_param, thread tint_private_vars_struct* const tint_private_vars, threadgroup tint_array<int4, 4>* const tint_symbol_8, threadgroup tint_array<int4, 4>* const tint_symbol_9, const constant S* const tint_symbol_10, device S* const tint_symbol_11, threadgroup tint_array<tint_array<tint_array<int, 2>, 3>, 4>* const tint_symbol_12) {
  tint_array<int4, 4> src_function = {};
  tint_array<int4, 4> const tint_symbol_4 = tint_array<int4, 4>{int4(1), int4(2), int4(3), int4(3)};
  *(tint_symbol_8) = tint_symbol_4;
  *(tint_symbol_8) = src_param;
  *(tint_symbol_8) = ret_arr();
  tint_array<int4, 4> const src_let = tint_array<int4, 4>{};
  *(tint_symbol_8) = src_let;
  *(tint_symbol_8) = src_function;
  *(tint_symbol_8) = (*(tint_private_vars)).src_private;
  *(tint_symbol_8) = *(tint_symbol_9);
  S const tint_symbol_1 = ret_struct_arr();
  *(tint_symbol_8) = tint_symbol_1.arr;
  *(tint_symbol_8) = (*(tint_symbol_10)).arr;
  *(tint_symbol_8) = (*(tint_symbol_11)).arr;
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> src_nested = {};
  *(tint_symbol_12) = src_nested;
}

void tint_symbol_inner(uint local_invocation_index, thread tint_private_vars_struct* const tint_private_vars, threadgroup tint_array<int4, 4>* const tint_symbol_13, threadgroup tint_array<int4, 4>* const tint_symbol_14, threadgroup tint_array<tint_array<tint_array<int, 2>, 3>, 4>* const tint_symbol_15, const constant S* const tint_symbol_16, device S* const tint_symbol_17) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_13, tint_symbol_14, tint_symbol_15);
  tint_array<int4, 4> const val = tint_array<int4, 4>{};
  foo(val, tint_private_vars, tint_symbol_13, tint_symbol_14, tint_symbol_16, tint_symbol_17, tint_symbol_15);
}

kernel void tint_symbol(const constant S* tint_symbol_21 [[buffer(0)]], device S* tint_symbol_22 [[buffer(1)]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  threadgroup tint_array<int4, 4> tint_symbol_18;
  threadgroup tint_array<int4, 4> tint_symbol_19;
  threadgroup tint_array<tint_array<tint_array<int, 2>, 3>, 4> tint_symbol_20;
  tint_symbol_inner(local_invocation_index, &(tint_private_vars), &(tint_symbol_18), &(tint_symbol_19), &(tint_symbol_20), tint_symbol_21, tint_symbol_22);
  return;
}

