#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 = true; \
  if (VOLATILE_NAME)

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