#version 310 es
#extension GL_AMD_gpu_shader_half_float : require
precision highp float;
precision highp int;

f16vec2 tint_bitcast_to_f16(uint src) {
  uint r = uint(src);
  return unpackFloat2x16(r);
}

layout(binding = 0, std430) buffer prevent_dce_block_ssbo {
  f16vec2 inner;
} prevent_dce;

f16vec2 bitcast_66e93d() {
  uint arg_0 = 1u;
  f16vec2 res = tint_bitcast_to_f16(arg_0);
  return res;
}

struct VertexOutput {
  vec4 pos;
  f16vec2 prevent_dce;
};

void fragment_main() {
  prevent_dce.inner = bitcast_66e93d();
}

void main() {
  fragment_main();
  return;
}
#version 310 es
#extension GL_AMD_gpu_shader_half_float : require

f16vec2 tint_bitcast_to_f16(uint src) {
  uint r = uint(src);
  return unpackFloat2x16(r);
}

layout(binding = 0, std430) buffer prevent_dce_block_ssbo {
  f16vec2 inner;
} prevent_dce;

f16vec2 bitcast_66e93d() {
  uint arg_0 = 1u;
  f16vec2 res = tint_bitcast_to_f16(arg_0);
  return res;
}

struct VertexOutput {
  vec4 pos;
  f16vec2 prevent_dce;
};

void compute_main() {
  prevent_dce.inner = bitcast_66e93d();
}

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
  compute_main();
  return;
}
#version 310 es
#extension GL_AMD_gpu_shader_half_float : require

f16vec2 tint_bitcast_to_f16(uint src) {
  uint r = uint(src);
  return unpackFloat2x16(r);
}

layout(location = 0) flat out f16vec2 prevent_dce_1;
f16vec2 bitcast_66e93d() {
  uint arg_0 = 1u;
  f16vec2 res = tint_bitcast_to_f16(arg_0);
  return res;
}

struct VertexOutput {
  vec4 pos;
  f16vec2 prevent_dce;
};

VertexOutput vertex_main() {
  VertexOutput tint_symbol = VertexOutput(vec4(0.0f, 0.0f, 0.0f, 0.0f), f16vec2(0.0hf, 0.0hf));
  tint_symbol.pos = vec4(0.0f);
  tint_symbol.prevent_dce = bitcast_66e93d();
  return tint_symbol;
}

void main() {
  gl_PointSize = 1.0;
  VertexOutput inner_result = vertex_main();
  gl_Position = inner_result.pos;
  prevent_dce_1 = inner_result.prevent_dce;
  gl_Position.y = -(gl_Position.y);
  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
  return;
}
