#include <metal_stdlib>

using namespace metal;
void bitcast_66e93d(device half2* const tint_symbol_1) {
  uint arg_0 = 1u;
  half2 res = as_type<half2>(arg_0);
  *(tint_symbol_1) = res;
}

struct tint_symbol {
  float4 value [[position]];
};

float4 vertex_main_inner(device half2* const tint_symbol_2) {
  bitcast_66e93d(tint_symbol_2);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(device half2* tint_symbol_3 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_3);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

fragment void fragment_main(device half2* tint_symbol_4 [[buffer(0)]]) {
  bitcast_66e93d(tint_symbol_4);
  return;
}

kernel void compute_main(device half2* tint_symbol_5 [[buffer(0)]]) {
  bitcast_66e93d(tint_symbol_5);
  return;
}

