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

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

struct tint_private_vars_struct {
  uint v;
};

struct S {
  /* 0x0000 */ tint_array<int4, 4> a;
};

int idx1(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 1;
}

int idx2(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 2;
}

int idx3(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 3;
}

int idx4(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 4;
}

int idx5(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 0;
}

int idx6(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).v = ((*(tint_private_vars)).v - 1u);
  return 2;
}

void tint_symbol_1(thread tint_private_vars_struct* const tint_private_vars, device tint_array<S, 1>* const tint_symbol_10) {
  {
    int const tint_symbol_6 = idx1(tint_private_vars);
    int const tint_symbol_7 = idx2(tint_private_vars);
    int const tint_symbol_2_save = tint_symbol_6;
    int const tint_symbol_2_save_1 = tint_symbol_7;
    int const tint_symbol_3 = idx3(tint_private_vars);
    (*(tint_symbol_10))[tint_symbol_2_save].a[tint_symbol_2_save_1][tint_symbol_3] = as_type<int>((as_type<uint>((*(tint_symbol_10))[tint_symbol_2_save].a[tint_symbol_2_save_1][tint_symbol_3]) - as_type<uint>(1)));
    while(true) {
      TINT_ISOLATE_UB(tint_volatile_false);
      if (!(((*(tint_private_vars)).v < 10u))) {
        break;
      }
      {
      }
      {
        int const tint_symbol_8 = idx4(tint_private_vars);
        int const tint_symbol_9 = idx5(tint_private_vars);
        int const tint_symbol_4_save = tint_symbol_8;
        int const tint_symbol_4_save_1 = tint_symbol_9;
        int const tint_symbol_5 = idx6(tint_private_vars);
        (*(tint_symbol_10))[tint_symbol_4_save].a[tint_symbol_4_save_1][tint_symbol_5] = as_type<int>((as_type<uint>((*(tint_symbol_10))[tint_symbol_4_save].a[tint_symbol_4_save_1][tint_symbol_5]) - as_type<uint>(1)));
      }
    }
  }
}

