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

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] = ((*v_2)[v_3] + 1);
    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] = ((*v_5)[v_6] + 1);
      }
      continue;
    }
  }
}
