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

layout(binding = 0, std430)
buffer prevent_dce_block_1_ssbo {
  float inner;
} v;
float tint_quantize_to_f16(float val) {
  return unpackHalf2x16(packHalf2x16(vec2(val))).x;
}
float quantizeToF16_12e50e() {
  float arg_0 = 1.0f;
  float res = tint_quantize_to_f16(arg_0);
  return res;
}
void main() {
  v.inner = quantizeToF16_12e50e();
}
#version 310 es

layout(binding = 0, std430)
buffer prevent_dce_block_1_ssbo {
  float inner;
} v;
float tint_quantize_to_f16(float val) {
  return unpackHalf2x16(packHalf2x16(vec2(val))).x;
}
float quantizeToF16_12e50e() {
  float arg_0 = 1.0f;
  float res = tint_quantize_to_f16(arg_0);
  return res;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
  v.inner = quantizeToF16_12e50e();
}
#version 310 es


struct VertexOutput {
  vec4 pos;
  float prevent_dce;
};

layout(location = 0) flat out float vertex_main_loc0_Output;
float tint_quantize_to_f16(float val) {
  return unpackHalf2x16(packHalf2x16(vec2(val))).x;
}
float quantizeToF16_12e50e() {
  float arg_0 = 1.0f;
  float res = tint_quantize_to_f16(arg_0);
  return res;
}
VertexOutput vertex_main_inner() {
  VertexOutput tint_symbol = VertexOutput(vec4(0.0f), 0.0f);
  tint_symbol.pos = vec4(0.0f);
  tint_symbol.prevent_dce = quantizeToF16_12e50e();
  return tint_symbol;
}
void main() {
  VertexOutput v = vertex_main_inner();
  gl_Position = v.pos;
  gl_Position[1u] = -(gl_Position.y);
  gl_Position[2u] = ((2.0f * gl_Position.z) - gl_Position.w);
  vertex_main_loc0_Output = v.prevent_dce;
  gl_PointSize = 1.0f;
}
