#include <metal_stdlib>
using namespace metal;
struct S {
  int a;
  float4 b;
  float2x2 c;
};
struct tint_module_vars_struct {
  device S* v;
  thread uint* i;
};
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];
};


int idx1(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.i) = ((*tint_module_vars.i) + 1u);
  return 1;
}
int idx2(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.i) = ((*tint_module_vars.i) + 2u);
  return 1;
}
int idx3(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.i) = ((*tint_module_vars.i) + 3u);
  return 1;
}
void foo(tint_module_vars_struct tint_module_vars) {
  tint_array<float, 4> a = tint_array<float, 4>{};
  {
    thread float* const v_1 = (&a[idx1(tint_module_vars)]);
    (*v_1) = ((*v_1) * 2.0f);
    while(true) {
      if ((a[idx2(tint_module_vars)] < 10.0f)) {
      } else {
        break;
      }
      {
        thread float* const v_2 = (&a[idx3(tint_module_vars)]);
        (*v_2) = ((*v_2) + 1.0f);
      }
      continue;
    }
  }
}
