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

struct tint_module_vars_struct {
  device tint_array<int, 10>* output;
};

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

kernel void foo(device tint_array<int, 10>* output [[buffer(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.output=output};
  int i = 0;
  {
    while(true) {
      TINT_ISOLATE_UB(tint_volatile_false)
      int x = (*tint_module_vars.output)[i];
      {
        int x_1 = (*tint_module_vars.output)[x];
        i = as_type<int>((as_type<uint>(i) + as_type<uint>(x_1)));
        if ((i > 10)) { break; }
      }
      continue;
    }
  }
  (*tint_module_vars.output)[0] = i;
}
