#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  texture2d<int, access::sample> arg_0;
};

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

int4 textureLoad2d(texture2d<int, access::sample> tint_symbol, int2 coords, int level) {
  return tint_symbol.read(uint2(coords), level);
}

void doTextureLoad(tint_module_vars_struct tint_module_vars) {
  int4 res = textureLoad2d(tint_module_vars.arg_0, int2(0), 0);
}

float4 vertex_main_inner(tint_module_vars_struct tint_module_vars) {
  doTextureLoad(tint_module_vars);
  return float4(0.0f);
}

fragment void fragment_main(texture2d<int, access::sample> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  doTextureLoad(tint_module_vars);
}

kernel void compute_main(texture2d<int, access::sample> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  doTextureLoad(tint_module_vars);
}

vertex vertex_main_outputs vertex_main(texture2d<int, access::sample> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.arg_0=arg_0};
  vertex_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.tint_symbol_1 = vertex_main_inner(tint_module_vars);
  return tint_wrapper_result;
}
