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

struct tint_symbol_1 {
  uint texture_builtin_value_0;
  uint pad;
  uint pad_1;
  uint pad_2;
};

layout(binding = 0, std140) uniform tint_symbol_2_block_ubo {
  tint_symbol_1 inner;
} tint_symbol_2;

uint textureNumSamples_dbb799() {
  uint res = tint_symbol_2.inner.texture_builtin_value_0;
  return res;
}

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

struct VertexOutput {
  vec4 pos;
  uint prevent_dce;
};

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

void main() {
  fragment_main();
  return;
}
#version 310 es

struct tint_symbol_1 {
  uint texture_builtin_value_0;
  uint pad;
  uint pad_1;
  uint pad_2;
};

layout(binding = 0, std140) uniform tint_symbol_2_block_ubo {
  tint_symbol_1 inner;
} tint_symbol_2;

uint textureNumSamples_dbb799() {
  uint res = tint_symbol_2.inner.texture_builtin_value_0;
  return res;
}

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

struct VertexOutput {
  vec4 pos;
  uint prevent_dce;
};

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

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

layout(location = 0) flat out uint prevent_dce_1;
struct tint_symbol_1 {
  uint texture_builtin_value_0;
  uint pad;
  uint pad_1;
  uint pad_2;
};

layout(binding = 0, std140) uniform tint_symbol_2_block_ubo {
  tint_symbol_1 inner;
} tint_symbol_2;

uint textureNumSamples_dbb799() {
  uint res = tint_symbol_2.inner.texture_builtin_value_0;
  return res;
}

struct VertexOutput {
  vec4 pos;
  uint prevent_dce;
};

VertexOutput vertex_main() {
  VertexOutput tint_symbol = VertexOutput(vec4(0.0f, 0.0f, 0.0f, 0.0f), 0u);
  tint_symbol.pos = vec4(0.0f);
  tint_symbol.prevent_dce = textureNumSamples_dbb799();
  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;
}
