#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 tint_module_vars_struct {
  threadgroup tint_array<int, 4>* v;
};

tint_array<int, 4> foo(tint_module_vars_struct tint_module_vars) {
  threadgroup_barrier(mem_flags::mem_threadgroup);
  tint_array<int, 4> const v_1 = (*tint_module_vars.v);
  threadgroup_barrier(mem_flags::mem_threadgroup);
  return v_1;
}
