#include <metal_stdlib>

using namespace metal;
void textureStore_48eae1(texture2d<float, access::write> tint_symbol_1) {
  tint_symbol_1.write(float4(1.0f), uint2(int2(1)));
}

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

float4 vertex_main_inner(texture2d<float, access::write> tint_symbol_2) {
  textureStore_48eae1(tint_symbol_2);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d<float, access::write> tint_symbol_3 [[texture(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(texture2d<float, access::write> tint_symbol_4 [[texture(0)]]) {
  textureStore_48eae1(tint_symbol_4);
  return;
}

kernel void compute_main(texture2d<float, access::write> tint_symbol_5 [[texture(0)]]) {
  textureStore_48eae1(tint_symbol_5);
  return;
}

