#version 310 es


struct S {
  ivec4 a[4];
};

layout(binding = 0, std430)
buffer tint_symbol_block_1_ssbo {
  S inner[];
} v_1;
uint v = 0u;
int idx1() {
  v = (v - 1u);
  return 1;
}
int idx2() {
  v = (v - 1u);
  return 2;
}
int idx3() {
  v = (v - 1u);
  return 3;
}
int idx4() {
  v = (v - 1u);
  return 4;
}
int idx5() {
  v = (v - 1u);
  return 0;
}
int idx6() {
  v = (v - 1u);
  return 2;
}
void tint_symbol_1() {
  {
    int v_2 = idx1();
    int v_3 = idx2();
    int v_4 = idx3();
    v_1.inner[v_2].a[v_3][v_4] = (v_1.inner[v_2].a[v_3][v_4] - 1);
    while(true) {
      if ((v < 10u)) {
      } else {
        break;
      }
      {
        int v_5 = idx4();
        int v_6 = idx5();
        int v_7 = idx6();
        v_1.inner[v_5].a[v_6][v_7] = (v_1.inner[v_5].a[v_6][v_7] - 1);
      }
      continue;
    }
  }
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
}
