#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 = false; if (VOLATILE_NAME) break;}

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)));
    while(true) {
      TINT_ISOLATE_UB(tint_volatile_false)
      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;
    }
  }
}
