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

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> dst = {};
  tint_array<int4, 4> const tint_symbol_4 = tint_array<int4, 4>{int4(1), int4(2), int4(3), int4(3)};
  dst = tint_symbol_4;
  dst = src_param;
  dst = ret_arr();
  tint_array<int4, 4> const src_let = tint_array<int4, 4>{};
  dst = src_let;
  dst = src_function;
  dst = (*(tint_private_vars)).src_private;
  dst = *(tint_symbol_6);
  S const tint_symbol_1 = ret_struct_arr();
  dst = tint_symbol_1.arr;
  dst = (*(tint_symbol_7)).arr;
  dst = (*(tint_symbol_8)).arr;
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> dst_nested = {};
  tint_array<tint_array<tint_array<int, 2>, 3>, 4> src_nested = {};
  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 val = tint_array<int4, 4>{};
  foo(val, 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;
}

