#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) {
  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;
};

struct S_nested {
  /* 0x0000 */ tint_array<tint_array<tint_array<int, 2>, 3>, 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, device S* const tint_symbol_6, threadgroup tint_array<int4, 4>* const tint_symbol_7, const constant S* const tint_symbol_8, device S* const tint_symbol_9, device S_nested* const tint_symbol_10) {
  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_6)).arr = tint_symbol_4;
  (*(tint_symbol_6)).arr = src_param;
  (*(tint_symbol_6)).arr = ret_arr();
  tint_array<int4, 4> const src_let = tint_array<int4, 4>{};
  (*(tint_symbol_6)).arr = src_let;
  (*(tint_symbol_6)).arr = src_function;
  (*(tint_symbol_6)).arr = (*(tint_private_vars)).src_private;
  (*(tint_symbol_6)).arr = *(tint_symbol_7);
  S const tint_symbol_1 = ret_struct_arr();
  (*(tint_symbol_6)).arr = tint_symbol_1.arr;
  (*(tint_symbol_6)).arr = (*(tint_symbol_8)).arr;
  (*(tint_symbol_6)).arr = (*(tint_symbol_9)).arr;
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> src_nested = {};
  (*(tint_symbol_10)).arr = 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_11, device S* const tint_symbol_12, const constant S* const tint_symbol_13, device S* const tint_symbol_14, device S_nested* const tint_symbol_15) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_11);
  tint_array<int4, 4> const ary = tint_array<int4, 4>{};
  foo(ary, tint_private_vars, tint_symbol_12, tint_symbol_11, tint_symbol_13, tint_symbol_14, tint_symbol_15);
}

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

