#include <metal_stdlib>

using namespace metal;
void textureStore_9e5bc2(texture2d<float, access::write> tint_symbol_1) {
  uint2 arg_1 = uint2(1u);
  float4 arg_2 = float4(1.0f);
  tint_symbol_1.write(arg_2, uint2(arg_1));
}

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

float4 vertex_main_inner(texture2d<float, access::write> tint_symbol_2) {
  textureStore_9e5bc2(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_9e5bc2(tint_symbol_4);
  return;
}

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

