#include <metal_stdlib>

using namespace metal;
float4 textureLoad_1373dc(texture1d<float, access::sample> tint_symbol_1) {
  uint arg_1 = 1u;
  int arg_2 = 1;
  float4 res = tint_symbol_1.read(uint(arg_1), 0);
  return res;
}

fragment void fragment_main(device float4* tint_symbol_2 [[buffer(0)]], texture1d<float, access::sample> tint_symbol_3 [[texture(0)]]) {
  *(tint_symbol_2) = textureLoad_1373dc(tint_symbol_3);
  return;
}

kernel void compute_main(device float4* tint_symbol_4 [[buffer(0)]], texture1d<float, access::sample> tint_symbol_5 [[texture(0)]]) {
  *(tint_symbol_4) = textureLoad_1373dc(tint_symbol_5);
  return;
}

struct VertexOutput {
  float4 pos;
  float4 prevent_dce;
};

struct tint_symbol {
  float4 prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

VertexOutput vertex_main_inner(texture1d<float, access::sample> tint_symbol_6) {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = textureLoad_1373dc(tint_symbol_6);
  return out;
}

vertex tint_symbol vertex_main(texture1d<float, access::sample> tint_symbol_7 [[texture(0)]]) {
  VertexOutput const inner_result = vertex_main_inner(tint_symbol_7);
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

