#include <metal_stdlib>

using namespace metal;
void textureLoad_216c37(texture1d<uint, access::sample> tint_symbol_1, device uint4* const tint_symbol_2) {
  uint4 res = tint_symbol_1.read(uint(1u), 0);
  *(tint_symbol_2) = res;
}

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

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

vertex tint_symbol vertex_main(texture1d<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(texture1d<uint, access::sample> tint_symbol_7 [[texture(0)]], device uint4* tint_symbol_8 [[buffer(0)]]) {
  textureLoad_216c37(tint_symbol_7, tint_symbol_8);
  return;
}

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

