#include <metal_stdlib>

using namespace metal;

int tint_unary_minus(const int v) {
  return select(-v, v, v == -2147483648);
}

struct buf0 {
  /* 0x0000 */ float2 resolution;
};
struct tint_array_wrapper {
  float4 arr[16];
};
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_6, thread float4* const tint_symbol_4, thread float4* const tint_symbol_5) {
  tint_array_wrapper indexable = {};
  int2 x_76 = 0;
  int2 x_109 = 0;
  int x_115 = 0;
  int2 x_76_phi = 0;
  int x_79_phi = 0;
  int2 x_110_phi = 0;
  int2 x_112_phi = 0;
  float4 const x_55 = *(tint_symbol_4);
  float2 const x_58 = x_6.resolution;
  float2 const x_59 = (float2(x_55.x, x_55.y) / x_58);
  int const x_62 = int((x_59.x * 8.0f));
  int const x_65 = int((x_59.y * 8.0f));
  int2 const x_74 = int2(as_type<int>((as_type<uint>(as_type<int>((as_type<uint>(((x_62 & 5) | (x_65 & 10))) * as_type<uint>(8)))) + as_type<uint>(((x_65 & 5) | (x_62 & 10))))), 0);
  x_76_phi = x_74;
  x_79_phi = 0;
  while (true) {
    int2 x_90 = 0;
    int2 x_98 = 0;
    int x_80 = 0;
    int2 x_91_phi = 0;
    int2 x_99_phi = 0;
    x_76 = x_76_phi;
    int const x_79 = x_79_phi;
    if ((x_79 < 100)) {
    } else {
      break;
    }
    x_91_phi = x_76;
    if ((x_76.x > 0)) {
      x_90 = x_76;
      x_90.y = as_type<int>((as_type<uint>(x_76.y) - as_type<uint>(1)));
      x_91_phi = x_90;
    }
    int2 const x_91 = x_91_phi;
    x_99_phi = x_91;
    if ((x_91.x < 0)) {
      x_98 = x_91;
      x_98.y = as_type<int>((as_type<uint>(x_91.y) + as_type<uint>(1)));
      x_99_phi = x_98;
    }
    int2 const x_99 = x_99_phi;
    int2 x_77_1 = x_99;
    x_77_1.x = as_type<int>((as_type<uint>(x_99.x) + as_type<uint>((x_99.y / 2))));
    int2 const x_77 = x_77_1;
    {
      x_80 = as_type<int>((as_type<uint>(x_79) + as_type<uint>(1)));
      x_76_phi = x_77;
      x_79_phi = x_80;
    }
  }
  int const x_104 = x_76.x;
  x_110_phi = x_76;
  if ((x_104 < 0)) {
    x_109 = x_76;
    x_109.x = tint_unary_minus(x_104);
    x_110_phi = x_109;
  }
  int2 const x_110 = x_110_phi;
  x_112_phi = x_110;
  while (true) {
    int2 x_113 = 0;
    int2 const x_112 = x_112_phi;
    x_115 = x_112.x;
    if ((x_115 > 15)) {
    } else {
      break;
    }
    {
      x_113 = x_112;
      x_113.x = as_type<int>(as_type<int>((as_type<uint>(x_115) - as_type<uint>(as_type<int>(16)))));
      x_112_phi = x_113;
    }
  }
  tint_array_wrapper const tint_symbol_2 = {.arr={float4(0.0f, 0.0f, 0.0f, 1.0f), float4(0.5f, 0.0f, 0.0f, 1.0f), float4(0.0f, 0.5f, 0.0f, 1.0f), float4(0.5f, 0.5f, 0.0f, 1.0f), float4(0.0f, 0.0f, 0.5f, 1.0f), float4(0.5f, 0.0f, 0.5f, 1.0f), float4(0.0f, 0.5f, 0.5f, 1.0f), float4(0.5f, 0.5f, 0.5f, 1.0f), float4(0.0f, 0.0f, 0.0f, 1.0f), float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(1.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 0.0f, 1.0f, 1.0f), float4(0.0f, 1.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}};
  indexable = tint_symbol_2;
  float4 const x_120 = indexable.arr[x_115];
  *(tint_symbol_5) = x_120;
  return;
}

main_out tint_symbol_inner(constant buf0& x_6, 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_6, tint_symbol_6, tint_symbol_7);
  main_out const tint_symbol_3 = {.x_GLF_color_1=*(tint_symbol_7)};
  return tint_symbol_3;
}

fragment tint_symbol_1 tint_symbol(float4 gl_FragCoord_param [[position]], constant buf0& x_6 [[buffer(0)]]) {
  thread float4 tint_symbol_8 = 0.0f;
  thread float4 tint_symbol_9 = 0.0f;
  main_out const inner_result = tint_symbol_inner(x_6, 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;
}

