#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;
  tint_array<int4, 4> dst;
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> dst_nested;
};

void tint_zero_workgroup_memory(uint local_idx, threadgroup tint_array<int4, 4>* const tint_symbol_5) {
  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);
  }
  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_6, const constant S* const tint_symbol_7, device S* const tint_symbol_8) {
  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_private_vars)).dst = tint_symbol_4;
  (*(tint_private_vars)).dst = src_param;
  (*(tint_private_vars)).dst = ret_arr();
  tint_array<int4, 4> const src_let = tint_array<int4, 4>{};
  (*(tint_private_vars)).dst = src_let;
  (*(tint_private_vars)).dst = src_function;
  (*(tint_private_vars)).dst = (*(tint_private_vars)).src_private;
  (*(tint_private_vars)).dst = *(tint_symbol_6);
  S const tint_symbol_1 = ret_struct_arr();
  (*(tint_private_vars)).dst = tint_symbol_1.arr;
  (*(tint_private_vars)).dst = (*(tint_symbol_7)).arr;
  (*(tint_private_vars)).dst = (*(tint_symbol_8)).arr;
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> src_nested = {};
  (*(tint_private_vars)).dst_nested = 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_9, const constant S* const tint_symbol_10, device S* const tint_symbol_11) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_9);
  tint_array<int4, 4> const a = tint_array<int4, 4>{};
  foo(a, tint_private_vars, tint_symbol_9, tint_symbol_10, tint_symbol_11);
}

kernel void tint_symbol(const constant S* tint_symbol_13 [[buffer(0)]], device S* tint_symbol_14 [[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_12;
  tint_symbol_inner(local_invocation_index, &(tint_private_vars), &(tint_symbol_12), tint_symbol_13, tint_symbol_14);
  return;
}

