#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  float4 x_GLF_color;
};

struct buf0 {
  /* 0x0000 */ float4 r;
};

void main_1(thread tint_private_vars_struct* const tint_private_vars, const constant buf0* const tint_symbol_3) {
  float f = 0.0f;
  float4 v = 0.0f;
  f = 1.0f;
  v = float4(sin(f), cos(f), exp2(f), log(f));
  if ((distance(v, (*(tint_symbol_3)).r) < 0.10000000149011611938f)) {
    (*(tint_private_vars)).x_GLF_color = float4(1.0f, 0.0f, 0.0f, 1.0f);
  } else {
    (*(tint_private_vars)).x_GLF_color = float4(0.0f);
  }
  return;
}

struct main_out {
  float4 x_GLF_color_1;
};

struct tint_symbol_1 {
  float4 x_GLF_color_1 [[color(0)]];
};

main_out tint_symbol_inner(thread tint_private_vars_struct* const tint_private_vars, const constant buf0* const tint_symbol_4) {
  main_1(tint_private_vars, tint_symbol_4);
  main_out const tint_symbol_2 = {.x_GLF_color_1=(*(tint_private_vars)).x_GLF_color};
  return tint_symbol_2;
}

fragment tint_symbol_1 tint_symbol(const constant buf0* tint_symbol_5 [[buffer(0)]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  main_out const inner_result = tint_symbol_inner(&(tint_private_vars), tint_symbol_5);
  tint_symbol_1 wrapper_result = {};
  wrapper_result.x_GLF_color_1 = inner_result.x_GLF_color_1;
  return wrapper_result;
}

