#include <metal_stdlib>

using namespace metal;
struct tint_padded_array_element {
  /* 0x0000 */ int el;
  /* 0x0004 */ int8_t tint_pad[12];
};
struct tint_array_wrapper {
  /* 0x0000 */ tint_padded_array_element arr[3];
};
struct buf0 {
  /* 0x0000 */ tint_array_wrapper x_GLF_uniform_int_values;
};
struct tint_padded_array_element_1 {
  /* 0x0000 */ float el;
  /* 0x0004 */ int8_t tint_pad_1[12];
};
struct tint_array_wrapper_1 {
  /* 0x0000 */ tint_padded_array_element_1 arr[2];
};
struct buf1 {
  /* 0x0000 */ tint_array_wrapper_1 x_GLF_uniform_float_values;
};
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, constant buf1& x_9, thread float4* const tint_symbol_3, thread float4* const tint_symbol_4) {
  int i = 0;
  int const x_37 = x_6.x_GLF_uniform_int_values.arr[1].el;
  float const x_38 = float(x_37);
  *(tint_symbol_3) = float4(x_38, x_38, x_38, x_38);
  int const x_41 = x_6.x_GLF_uniform_int_values.arr[1].el;
  i = x_41;
  while (true) {
    int const x_46 = i;
    int const x_48 = x_6.x_GLF_uniform_int_values.arr[2].el;
    if ((x_46 < x_48)) {
    } else {
      break;
    }
    float const x_52 = (*(tint_symbol_4)).y;
    float const x_54 = x_9.x_GLF_uniform_float_values.arr[0].el;
    if ((x_52 < x_54)) {
      float const x_59 = (*(tint_symbol_4)).x;
      float const x_61 = x_9.x_GLF_uniform_float_values.arr[0].el;
      if ((x_59 < x_61)) {
        return;
      }
      float const x_66 = x_9.x_GLF_uniform_float_values.arr[1].el;
      float const x_68 = x_9.x_GLF_uniform_float_values.arr[1].el;
      if ((x_66 > x_68)) {
        return;
      }
      discard_fragment();
    }
    float const x_73 = x_9.x_GLF_uniform_float_values.arr[1].el;
    float const x_75 = x_9.x_GLF_uniform_float_values.arr[0].el;
    if ((x_73 > x_75)) {
      int const x_80 = x_6.x_GLF_uniform_int_values.arr[0].el;
      int const x_83 = x_6.x_GLF_uniform_int_values.arr[1].el;
      int const x_86 = x_6.x_GLF_uniform_int_values.arr[1].el;
      int const x_89 = x_6.x_GLF_uniform_int_values.arr[0].el;
      *(tint_symbol_3) = float4(float(x_80), float(x_83), float(x_86), float(x_89));
      break;
    }
    float const x_93 = x_9.x_GLF_uniform_float_values.arr[0].el;
    if ((x_93 < 0.0f)) {
      discard_fragment();
    }
    {
      int const x_97 = i;
      i = as_type<int>((as_type<uint>(x_97) + as_type<uint>(1)));
    }
  }
  return;
}

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

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

