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

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

struct tint_private_vars_struct {
  uint i;
};

struct S {
  int a;
  float4 b;
  float2x2 c;
};

int idx1(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 1u);
  return 1;
}

int idx2(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 2u);
  return 1;
}

int idx3(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 3u);
  return 1;
}

void foo(thread tint_private_vars_struct* const tint_private_vars) {
  tint_array<float, 4> a = tint_array<float, 4>{};
  {
    int const tint_symbol_2 = idx1(tint_private_vars);
    int const tint_symbol_save = tint_symbol_2;
    a[tint_symbol_save] = (a[tint_symbol_save] * 2.0f);
    while(true) {
      TINT_ISOLATE_UB(tint_volatile_false);
      int const tint_symbol_3 = idx2(tint_private_vars);
      if (!((a[tint_symbol_3] < 10.0f))) {
        break;
      }
      {
      }
      {
        int const tint_symbol_4 = idx3(tint_private_vars);
        int const tint_symbol_1_save = tint_symbol_4;
        a[tint_symbol_1_save] = (a[tint_symbol_1_save] + 1.0f);
      }
    }
  }
}

