#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 S {
  tint_array<int4, 4> a;
};

struct tint_module_vars_struct {
  device tint_array<S, 1>* tint_symbol;
  thread uint* v;
};

#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.v) = ((*tint_module_vars.v) - 1u);
  return 1;
}

int idx2(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.v) = ((*tint_module_vars.v) - 1u);
  return 2;
}

int idx3(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.v) = ((*tint_module_vars.v) - 1u);
  return 3;
}

int idx4(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.v) = ((*tint_module_vars.v) - 1u);
  return 4;
}

int idx5(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.v) = ((*tint_module_vars.v) - 1u);
  return 0;
}

int idx6(tint_module_vars_struct tint_module_vars) {
  (*tint_module_vars.v) = ((*tint_module_vars.v) - 1u);
  return 2;
}

void tint_symbol_1(tint_module_vars_struct tint_module_vars) {
  {
    int const v_1 = idx1(tint_module_vars);
    device int4* const v_2 = (&(*tint_module_vars.tint_symbol)[v_1].a[idx2(tint_module_vars)]);
    int const v_3 = idx3(tint_module_vars);
    (*v_2)[v_3] = as_type<int>((as_type<uint>((*v_2)[v_3]) - as_type<uint>(1)));
    TINT_ISOLATE_UB(tint_volatile_true) while(true) {
      if (((*tint_module_vars.v) < 10u)) {
      } else {
        break;
      }
      {
        int const v_4 = idx4(tint_module_vars);
        device int4* const v_5 = (&(*tint_module_vars.tint_symbol)[v_4].a[idx5(tint_module_vars)]);
        int const v_6 = idx6(tint_module_vars);
        (*v_5)[v_6] = as_type<int>((as_type<uint>((*v_5)[v_6]) - as_type<uint>(1)));
      }
      continue;
    }
  }
}
