#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  thread int* counter;
};

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<int4, 4> a;
};

int foo(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.counter) = as_type<int>((as_type<uint>((*tint_module_vars.counter)) + as_type<uint>(1)));
  return (*tint_module_vars.counter);
}

int bar(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.counter) = as_type<int>((as_type<uint>((*tint_module_vars.counter)) + as_type<uint>(2)));
  return (*tint_module_vars.counter);
}

void tint_symbol(tint_module_vars_struct tint_module_vars) {
  S x = S{};
  thread S* const p = (&x);
  thread int4* const v = (&(*p).a[foo(tint_module_vars)]);
  int const v_1 = bar(tint_module_vars);
  (*v)[v_1] = as_type<int>((as_type<uint>((*v)[v_1]) + as_type<uint>(5)));
}
