#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  float4 gl_Position;
};

void main_1(thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).gl_Position = float4(0.0f);
  return;
}

struct main_out {
  float4 gl_Position;
};

struct tint_symbol_1 {
  float4 gl_Position [[position]];
};

main_out tint_symbol_inner(thread tint_private_vars_struct* const tint_private_vars) {
  main_1(tint_private_vars);
  main_out const tint_symbol_2 = main_out{.gl_Position=(*(tint_private_vars)).gl_Position};
  return tint_symbol_2;
}

vertex tint_symbol_1 tint_symbol() {
  thread tint_private_vars_struct tint_private_vars = {};
  main_out const inner_result = tint_symbol_inner(&(tint_private_vars));
  tint_symbol_1 wrapper_result = {};
  wrapper_result.gl_Position = inner_result.gl_Position;
  return wrapper_result;
}

