#include <metal_stdlib>
using namespace metal;

template<typename T, size_t N>
struct tint_array {
  const constant T& operator[](size_t i) const constant { return elements[i]; }
  device T& operator[](size_t i) device { return elements[i]; }
  const device T& operator[](size_t i) const device { return elements[i]; }
  thread T& operator[](size_t i) thread { return elements[i]; }
  const thread T& operator[](size_t i) const thread { return elements[i]; }
  threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
  const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
  T elements[N];
};

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

struct frag_main_outputs {
  float4 tint_symbol_1 [[color(0)]];
};

float4 vtx_main_inner(uint VertexIndex) {
  return float4(tint_array<float2, 3>{float2(0.0f, 0.5f), float2(-0.5f), float2(0.5f, -0.5f)}[VertexIndex], 0.0f, 1.0f);
}

float4 frag_main_inner() {
  return float4(1.0f, 0.0f, 0.0f, 1.0f);
}

vertex vtx_main_outputs vtx_main(uint VertexIndex [[vertex_id]]) {
  vtx_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.tint_symbol = vtx_main_inner(VertexIndex);
  return tint_wrapper_result;
}

fragment frag_main_outputs frag_main() {
  frag_main_outputs tint_wrapper_result = {};
  tint_wrapper_result.tint_symbol_1 = frag_main_inner();
  return tint_wrapper_result;
}
