#include <metal_stdlib>

using namespace metal;
void textureLoad_b27c33(texture3d<int, access::read_write> tint_symbol_1, device int4* const tint_symbol_2) {
  int3 arg_1 = int3(1);
  int4 res = tint_symbol_1.read(uint3(arg_1));
  *(tint_symbol_2) = res;
}

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

float4 vertex_main_inner(texture3d<int, access::read_write> tint_symbol_3, device int4* const tint_symbol_4) {
  textureLoad_b27c33(tint_symbol_3, tint_symbol_4);
  return float4(0.0f);
}

vertex tint_symbol vertex_main(texture3d<int, access::read_write> tint_symbol_5 [[texture(0)]], device int4* 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(texture3d<int, access::read_write> tint_symbol_7 [[texture(0)]], device int4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_b27c33(tint_symbol_7, tint_symbol_8);
  return;
}

kernel void compute_main(texture3d<int, access::read_write> tint_symbol_9 [[texture(0)]], device int4* tint_symbol_10 [[buffer(0)]]) {
  textureLoad_b27c33(tint_symbol_9, tint_symbol_10);
  return;
}

