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

#define TINT_ISOLATE_UB(VOLATILE_NAME) \
  {volatile bool VOLATILE_NAME = false; if (VOLATILE_NAME) break;}

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) {
      TINT_ISOLATE_UB(tint_volatile_false)
      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;
    }
  }
}
