#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 tint_private_vars_struct {
  float3 position_1;
  float2 vUV;
  float2 uv;
  float3 normal;
  float4 gl_Position;
};

struct strided_arr {
  /* 0x0000 */ float el;
  /* 0x0004 */ tint_array<int8_t, 12> tint_pad;
};

struct LeftOver {
  /* 0x0000 */ float4x4 worldViewProjection;
  /* 0x0040 */ float time;
  /* 0x0044 */ tint_array<int8_t, 12> tint_pad_1;
  /* 0x0050 */ tint_array<float4x4, 2> test2;
  /* 0x00d0 */ tint_array<strided_arr, 4> test;
};

void main_1(thread tint_private_vars_struct* const tint_private_vars, const constant LeftOver* const tint_symbol_5) {
  float4 q = 0.0f;
  float3 p = 0.0f;
  q = float4((*(tint_private_vars)).position_1[0], (*(tint_private_vars)).position_1[1], (*(tint_private_vars)).position_1[2], 1.0f);
  p = q.xyz;
  p[0] = (p[0] + sin((((*(tint_symbol_5)).test[0].el * (*(tint_private_vars)).position_1[1]) + (*(tint_symbol_5)).time)));
  p[1] = (p[1] + sin(((*(tint_symbol_5)).time + 4.0f)));
  (*(tint_private_vars)).gl_Position = ((*(tint_symbol_5)).worldViewProjection * float4(p[0], p[1], p[2], 1.0f));
  (*(tint_private_vars)).vUV = (*(tint_private_vars)).uv;
  (*(tint_private_vars)).gl_Position[1] = ((*(tint_private_vars)).gl_Position[1] * -1.0f);
  return;
}

struct main_out {
  float4 gl_Position;
  float2 vUV_1;
};

struct tint_symbol_2 {
  float3 position_1_param [[attribute(0)]];
  float3 normal_param [[attribute(1)]];
  float2 uv_param [[attribute(2)]];
};

struct tint_symbol_3 {
  float2 vUV_1 [[user(locn0)]];
  float4 gl_Position [[position]];
};

main_out tint_symbol_inner(float3 position_1_param, float2 uv_param, float3 normal_param, thread tint_private_vars_struct* const tint_private_vars, const constant LeftOver* const tint_symbol_6) {
  (*(tint_private_vars)).position_1 = position_1_param;
  (*(tint_private_vars)).uv = uv_param;
  (*(tint_private_vars)).normal = normal_param;
  main_1(tint_private_vars, tint_symbol_6);
  main_out const tint_symbol_4 = {.gl_Position=(*(tint_private_vars)).gl_Position, .vUV_1=(*(tint_private_vars)).vUV};
  return tint_symbol_4;
}

vertex tint_symbol_3 tint_symbol(const constant LeftOver* tint_symbol_7 [[buffer(0)]], tint_symbol_2 tint_symbol_1 [[stage_in]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  main_out const inner_result = tint_symbol_inner(tint_symbol_1.position_1_param, tint_symbol_1.uv_param, tint_symbol_1.normal_param, &(tint_private_vars), tint_symbol_7);
  tint_symbol_3 wrapper_result = {};
  wrapper_result.gl_Position = inner_result.gl_Position;
  wrapper_result.vUV_1 = inner_result.vUV_1;
  return wrapper_result;
}

