#version 310 es
precision highp float;
precision highp int;

layout(binding = 0, std430)
buffer tint_symbol_1_1_ssbo {
  ivec4 tint_symbol;
} v;
ivec4 unpack4xI8_830900() {
  uint arg_0 = 1u;
  uint v_1 = arg_0;
  uvec4 v_2 = uvec4(24u, 16u, 8u, 0u);
  ivec4 v_3 = ivec4((uvec4(v_1) << v_2));
  ivec4 res = (v_3 >> uvec4(24u));
  return res;
}
void main() {
  v.tint_symbol = unpack4xI8_830900();
}
#version 310 es

layout(binding = 0, std430)
buffer tint_symbol_1_1_ssbo {
  ivec4 tint_symbol;
} v;
ivec4 unpack4xI8_830900() {
  uint arg_0 = 1u;
  uint v_1 = arg_0;
  uvec4 v_2 = uvec4(24u, 16u, 8u, 0u);
  ivec4 v_3 = ivec4((uvec4(v_1) << v_2));
  ivec4 res = (v_3 >> uvec4(24u));
  return res;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
  v.tint_symbol = unpack4xI8_830900();
}
#version 310 es


struct VertexOutput {
  vec4 pos;
  ivec4 prevent_dce;
};

layout(location = 0) flat out ivec4 vertex_main_loc0_Output;
ivec4 unpack4xI8_830900() {
  uint arg_0 = 1u;
  uint v = arg_0;
  uvec4 v_1 = uvec4(24u, 16u, 8u, 0u);
  ivec4 v_2 = ivec4((uvec4(v) << v_1));
  ivec4 res = (v_2 >> uvec4(24u));
  return res;
}
VertexOutput vertex_main_inner() {
  VertexOutput tint_symbol = VertexOutput(vec4(0.0f), ivec4(0));
  tint_symbol.pos = vec4(0.0f);
  tint_symbol.prevent_dce = unpack4xI8_830900();
  return tint_symbol;
}
void main() {
  VertexOutput v_3 = vertex_main_inner();
  gl_Position = v_3.pos;
  gl_Position[1u] = -(gl_Position.y);
  gl_Position[2u] = ((2.0f * gl_Position.z) - gl_Position.w);
  vertex_main_loc0_Output = v_3.prevent_dce;
  gl_PointSize = 1.0f;
}
