#include <metal_stdlib>

using namespace metal;
half3 saturate_462535() {
  half3 res = half3(1.0h);
  return res;
}

fragment void fragment_main(device packed_half3* tint_symbol_1 [[buffer(0)]]) {
  *(tint_symbol_1) = packed_half3(saturate_462535());
  return;
}

kernel void compute_main(device packed_half3* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = packed_half3(saturate_462535());
  return;
}

struct VertexOutput {
  float4 pos;
  half3 prevent_dce;
};

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

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = saturate_462535();
  return out;
}

vertex tint_symbol vertex_main() {
  VertexOutput const inner_result = vertex_main_inner();
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

