#include <metal_stdlib>

using namespace metal;
void textureLoad_6154d4(texture2d<uint, access::sample> tint_symbol_1, device uint4* const tint_symbol_2) {
  int2 arg_1 = int2(1);
  int arg_2 = 1;
  uint4 res = tint_symbol_1.read(uint2(arg_1), arg_2);
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture2d<uint, access::sample> tint_symbol_3, device uint4* const tint_symbol_4) {
  textureLoad_6154d4(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture2d<uint, access::sample> tint_symbol_5 [[texture(0)]], device uint4* tint_symbol_6 [[buffer(0)]]) {
  float4 const inner_result = vertex_main_inner(tint_symbol_5, tint_symbol_6);
  tint_symbol wrapper_result = {};
  wrapper_result.value = inner_result;
  return wrapper_result;
}

fragment void fragment_main(texture2d<uint, access::sample> tint_symbol_7 [[texture(0)]], device uint4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_6154d4(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(texture2d<uint, access::sample> tint_symbol_9 [[texture(0)]], device uint4* tint_symbol_10 [[buffer(0)]]) {
  textureLoad_6154d4(tint_symbol_9, tint_symbol_10);
  return;
}

