#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>{};
  {
    uint2 tint_loop_idx = 0u;
    thread float* const v_1 = (&a[min(uint(idx1(tint_module_vars)), 3u)]);
    (*v_1) = ((*v_1) * 2.0f);
    while(true) {
      if (all((tint_loop_idx == uint2(4294967295u)))) {
        break;
      }
      if ((a[min(uint(idx2(tint_module_vars)), 3u)] < 10.0f)) {
      } else {
        break;
      }
      {
        uint const tint_low_inc = (tint_loop_idx.x + 1u);
        tint_loop_idx.x = tint_low_inc;
        uint const tint_carry = uint((tint_low_inc == 0u));
        tint_loop_idx.y = (tint_loop_idx.y + tint_carry);
        thread float* const v_2 = (&a[min(uint(idx3(tint_module_vars)), 3u)]);
        (*v_2) = ((*v_2) + 1.0f);
      }
      continue;
    }
  }
}
