#include <metal_stdlib>

using namespace metal;
struct tint_array_wrapper {
  int arr[10];
};
struct BinarySearchObject {
  tint_array_wrapper prime_numbers;
};
struct buf0 {
  /* 0x0000 */ packed_float2 injectionSwitch;
};
struct main_out {
  float4 x_GLF_color_1;
};
struct tint_symbol_1 {
  float4 x_GLF_color_1 [[color(0)]];
};

int binarySearch_struct_BinarySearchObject_i1_10_1_(constant buf0& x_8, thread BinarySearchObject* const obj) {
  int m = 0;
  while (true) {
    float const x_91 = x_8.injectionSwitch.x;
    if ((x_91 > 1.0f)) {
    } else {
      break;
    }
    float const x_95 = x_8.injectionSwitch.x;
    m = int(x_95);
    int const x_14 = m;
    int const x_15 = (*(obj)).prime_numbers.arr[x_14];
    if ((x_15 == 1)) {
      return 1;
    }
  }
  return 1;
}

void main_1(constant buf0& x_8, thread float4* const tint_symbol_4) {
  int i = 0;
  BinarySearchObject obj_1 = {};
  BinarySearchObject param = {};
  i = 0;
  while (true) {
    int const x_16 = i;
    if ((x_16 < 10)) {
    } else {
      break;
    }
    int const x_17 = i;
    if ((x_17 != 3)) {
      int const x_18 = i;
      float const x_67 = x_8.injectionSwitch.x;
      if (((x_18 - int(x_67)) == 4)) {
        int const x_21 = i;
        obj_1.prime_numbers.arr[x_21] = 11;
      } else {
        int const x_22 = i;
        if ((x_22 == 6)) {
          int const x_23 = i;
          obj_1.prime_numbers.arr[x_23] = 17;
        }
        {
          int const x_24 = i;
          i = (x_24 + 1);
        }
        continue;
      }
    }
    while (true) {
      {
        float const x_82 = x_8.injectionSwitch.y;
        if ((0.0f > x_82)) {
        } else {
          break;
        }
      }
    }
    {
      int const x_24 = i;
      i = (x_24 + 1);
    }
  }
  BinarySearchObject const x_84 = obj_1;
  param = x_84;
  int const x_26 = binarySearch_struct_BinarySearchObject_i1_10_1_(x_8, &(param));
  *(tint_symbol_4) = float4(1.0f, 0.0f, 0.0f, 1.0f);
  return;
}

fragment tint_symbol_1 tint_symbol(constant buf0& x_8 [[buffer(0)]]) {
  thread float4 tint_symbol_5 = 0.0f;
  main_1(x_8, &(tint_symbol_5));
  main_out const tint_symbol_2 = {.x_GLF_color_1=tint_symbol_5};
  tint_symbol_1 const tint_symbol_3 = {.x_GLF_color_1=tint_symbol_2.x_GLF_color_1};
  return tint_symbol_3;
}

