#include <metal_stdlib>

using namespace metal;
struct buf1 {
  /* 0x0000 */ float2 injectionSwitch;
};
struct buf0 {
  /* 0x0000 */ float2 resolution;
};
struct main_out {
  float4 x_GLF_color_1;
};
struct tint_symbol_1 {
  float4 x_GLF_color_1 [[color(0)]];
};

int pointInTriangle_vf2_vf2_vf2_vf2_(constant buf1& x_11, thread float2* const p, thread float2* const a, thread float2* const b, thread float2* const c, thread float4* const tint_symbol_3) {
  float x_78 = 0.0f;
  float x_79 = 0.0f;
  float x_80 = 0.0f;
  float2 param = 0.0f;
  float2 param_1 = 0.0f;
  float2 param_2 = 0.0f;
  float2 param_3 = 0.0f;
  float2 param_4 = 0.0f;
  float2 param_5 = 0.0f;
  bool x_147 = false;
  bool x_203 = false;
  bool x_148_phi = false;
  bool x_204_phi = false;
  float const x_82 = (*(p)).x;
  float const x_84 = (*(a)).x;
  float const x_87 = (*(p)).y;
  float const x_89 = (*(a)).y;
  float const x_93 = (*(b)).x;
  float const x_94 = (*(a)).x;
  float const x_97 = (*(b)).y;
  float const x_98 = (*(a)).y;
  param = float2((x_82 - x_84), (x_87 - x_89));
  param_1 = float2((x_93 - x_94), (x_97 - x_98));
  float const x_102 = param.x;
  float const x_104 = param_1.y;
  float const x_107 = param_1.x;
  float const x_109 = param.y;
  float const x_111 = ((x_102 * x_104) - (x_107 * x_109));
  x_80 = x_111;
  float const x_112 = (*(p)).x;
  float const x_113 = (*(b)).x;
  float const x_115 = (*(p)).y;
  float const x_116 = (*(b)).y;
  float const x_120 = (*(c)).x;
  float const x_121 = (*(b)).x;
  float const x_124 = (*(c)).y;
  float const x_125 = (*(b)).y;
  param_2 = float2((x_112 - x_113), (x_115 - x_116));
  param_3 = float2((x_120 - x_121), (x_124 - x_125));
  float const x_129 = param_2.x;
  float const x_131 = param_3.y;
  float const x_134 = param_3.x;
  float const x_136 = param_2.y;
  float const x_138 = ((x_129 * x_131) - (x_134 * x_136));
  x_79 = x_138;
  bool const x_139 = (x_111 < 0.0f);
  bool const x_141 = (x_139 && (x_138 < 0.0f));
  x_148_phi = x_141;
  if (!(x_141)) {
    x_147 = ((x_111 >= 0.0f) && (x_138 >= 0.0f));
    x_148_phi = x_147;
  }
  int x_153_phi = 0;
  bool const x_148 = x_148_phi;
  if (!(x_148)) {
    x_153_phi = 0;
    while (true) {
      int x_154 = 0;
      int x_164_phi = 0;
      int const x_153 = x_153_phi;
      float const x_159 = x_11.injectionSwitch.y;
      int const x_160 = int(x_159);
      if ((x_153 < x_160)) {
      } else {
        break;
      }
      *(tint_symbol_3) = float4(1.0f, 1.0f, 1.0f, 1.0f);
      x_164_phi = 0;
      while (true) {
        int x_165 = 0;
        int const x_164 = x_164_phi;
        if ((x_164 < x_160)) {
        } else {
          break;
        }
        *(tint_symbol_3) = float4(1.0f, 1.0f, 1.0f, 1.0f);
        {
          x_165 = as_type<int>((as_type<uint>(x_164) + as_type<uint>(1)));
          x_164_phi = x_165;
        }
      }
      {
        x_154 = as_type<int>((as_type<uint>(x_153) + as_type<uint>(1)));
        x_153_phi = x_154;
      }
    }
    return 0;
  }
  float const x_171 = (*(p)).x;
  float const x_172 = (*(c)).x;
  float const x_174 = (*(p)).y;
  float const x_175 = (*(c)).y;
  float const x_178 = (*(a)).x;
  float const x_179 = (*(c)).x;
  float const x_181 = (*(a)).y;
  float const x_182 = (*(c)).y;
  param_4 = float2((x_171 - x_172), (x_174 - x_175));
  param_5 = float2((x_178 - x_179), (x_181 - x_182));
  float const x_186 = param_4.x;
  float const x_188 = param_5.y;
  float const x_191 = param_5.x;
  float const x_193 = param_4.y;
  float const x_195 = ((x_186 * x_188) - (x_191 * x_193));
  x_78 = x_195;
  bool const x_197 = (x_139 && (x_195 < 0.0f));
  x_204_phi = x_197;
  if (!(x_197)) {
    x_203 = ((x_111 >= 0.0f) && (x_195 >= 0.0f));
    x_204_phi = x_203;
  }
  bool const x_204 = x_204_phi;
  if (!(x_204)) {
    return 0;
  }
  return 1;
}

void main_1(constant buf0& x_19, constant buf1& x_11, thread float4* const tint_symbol_4, thread float4* const tint_symbol_5) {
  float2 param_6 = 0.0f;
  float2 param_7 = 0.0f;
  float2 param_8 = 0.0f;
  float2 param_9 = 0.0f;
  float4 const x_60 = *(tint_symbol_4);
  float2 const x_63 = x_19.resolution;
  param_6 = (float2(x_60.x, x_60.y) / x_63);
  param_7 = float2(0.699999988f, 0.300000012f);
  param_8 = float2(0.5f, 0.899999976f);
  param_9 = float2(0.100000001f, 0.400000006f);
  int const x_65 = pointInTriangle_vf2_vf2_vf2_vf2_(x_11, &(param_6), &(param_7), &(param_8), &(param_9), tint_symbol_5);
  if ((x_65 == 1)) {
    float const x_71 = x_11.injectionSwitch.y;
    float const x_73 = x_11.injectionSwitch.x;
    if ((x_71 >= x_73)) {
      *(tint_symbol_5) = float4(1.0f, 0.0f, 0.0f, 1.0f);
    }
  } else {
    *(tint_symbol_5) = float4(0.0f, 0.0f, 0.0f, 1.0f);
  }
  return;
}

main_out tint_symbol_inner(constant buf0& x_19, constant buf1& x_11, float4 gl_FragCoord_param, thread float4* const tint_symbol_6, thread float4* const tint_symbol_7) {
  *(tint_symbol_6) = gl_FragCoord_param;
  main_1(x_19, x_11, tint_symbol_6, tint_symbol_7);
  main_out const tint_symbol_2 = {.x_GLF_color_1=*(tint_symbol_7)};
  return tint_symbol_2;
}

fragment tint_symbol_1 tint_symbol(float4 gl_FragCoord_param [[position]], constant buf0& x_19 [[buffer(0)]], constant buf1& x_11 [[buffer(1)]]) {
  thread float4 tint_symbol_8 = 0.0f;
  thread float4 tint_symbol_9 = 0.0f;
  main_out const inner_result = tint_symbol_inner(x_19, x_11, gl_FragCoord_param, &(tint_symbol_8), &(tint_symbol_9));
  tint_symbol_1 wrapper_result = {};
  wrapper_result.x_GLF_color_1 = inner_result.x_GLF_color_1;
  return wrapper_result;
}

