#include <metal_stdlib>
using namespace metal;

struct tint_module_vars_struct {
  device int4* prevent_dce;
  texture2d<int, access::read_write> arg_0;
};

int4 textureLoad_5cd3fc(tint_module_vars_struct tint_module_vars) {
  int2 arg_1 = int2(1);
  int4 res = tint_module_vars.arg_0.read(uint2(arg_1));
  return res;
}

fragment void fragment_main(device int4* prevent_dce [[buffer(0)]], texture2d<int, access::read_write> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce, .arg_0=arg_0};
  (*tint_module_vars.prevent_dce) = textureLoad_5cd3fc(tint_module_vars);
}

kernel void compute_main(device int4* prevent_dce [[buffer(0)]], texture2d<int, access::read_write> arg_0 [[texture(0)]]) {
  tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.prevent_dce=prevent_dce, .arg_0=arg_0};
  (*tint_module_vars.prevent_dce) = textureLoad_5cd3fc(tint_module_vars);
}
