#include <metal_stdlib>

using namespace metal;

struct modf_result_vec2_f32 {
  float2 fract;
  float2 whole;
};
modf_result_vec2_f32 tint_modf(float2 param_0) {
  modf_result_vec2_f32 result;
  result.fract = modf(param_0, result.whole);
  return result;
}

void modf_2d50da() {
  float2 arg_0 = float2(-1.5f);
  modf_result_vec2_f32 res = tint_modf(arg_0);
}

fragment void fragment_main() {
  modf_2d50da();
  return;
}

kernel void compute_main() {
  modf_2d50da();
  return;
}

struct VertexOutput {
  float4 pos;
};

struct tint_symbol {
  float4 pos [[position]];
};

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  modf_2d50da();
  return out;
}

vertex tint_symbol vertex_main() {
  VertexOutput const inner_result = vertex_main_inner();
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  return wrapper_result;
}

