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

struct S {
  tint_array<int, 4> arr;
};

struct tint_module_vars_struct {
  device int* s;
};

int foo() {
  tint_array<int, 4> const src = tint_array<int, 4>{};
  tint_array<int, 4> dst = {};
  S dst_struct = {};
  tint_array<tint_array<int, 4>, 2> dst_array = {};
  thread tint_array<int, 4>* const dst_ptr = (&dst);
  thread S* const dst_struct_ptr = (&dst_struct);
  thread tint_array<tint_array<int, 4>, 2>* const dst_array_ptr = (&dst_array);
  dst_struct.arr = src;
  dst_array[1] = src;
  (*dst_ptr) = src;
  (*dst_struct_ptr).arr = src;
  (*dst_array_ptr)[0] = src;
  return as_type<int>((as_type<uint>(as_type<int>((as_type<uint>((*dst_ptr)[0]) + as_type<uint>((*dst_struct_ptr).arr[0])))) + as_type<uint>((*dst_array_ptr)[0][0])));
}

kernel void tint_symbol(device int* s [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.s=s};
  (*tint_module_vars.s) = foo();
}
