#include <metal_stdlib>

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

void main_1(constant buf0& x_5, thread float4* const tint_symbol_3) {
  bool GLF_live12c5 = false;
  *(tint_symbol_3) = float4(1.0f, 0.0f, 0.0f, 1.0f);
  while (true) {
    float const x_31 = x_5.injectionSwitch.y;
    if ((x_31 < 0.0f)) {
      GLF_live12c5 = false;
      bool const x_35 = GLF_live12c5;
      if (x_35) {
        {
          if (false) {
          } else {
            break;
          }
        }
        continue;
      } else {
        {
          if (false) {
          } else {
            break;
          }
        }
        continue;
      }
      {
        if (false) {
        } else {
          break;
        }
      }
      continue;
    }
    break;
    {
      if (false) {
      } else {
        break;
      }
    }
  }
  return;
}

main_out tint_symbol_inner(constant buf0& x_5, thread float4* const tint_symbol_4) {
  main_1(x_5, tint_symbol_4);
  main_out const tint_symbol_2 = {.x_GLF_color_1=*(tint_symbol_4)};
  return tint_symbol_2;
}

fragment tint_symbol_1 tint_symbol(constant buf0& x_5 [[buffer(0)]]) {
  thread float4 tint_symbol_5 = 0.0f;
  main_out const inner_result = tint_symbol_inner(x_5, &(tint_symbol_5));
  tint_symbol_1 wrapper_result = {};
  wrapper_result.x_GLF_color_1 = inner_result.x_GLF_color_1;
  return wrapper_result;
}

