#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double floor(double);
double fmod(double x, double y) {
  double i, f;
  if (y == 0.0)
    return 0.0;
  i = floor(x / y);
  f = x - i * y;
  if ((x < 0.0) != (y < 0.0))
    f = f - y;
  return f;
}


x86 assembly (clang, -O0):
<fmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <fmod+0x37>
jp     1147 <fmod+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d0 <fmod+0xc0>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
je     11c6 <fmod+0xb6>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1121 <fmod+0x11>
jp     1121 <fmod+0x11>
ret
sub    $0x18,%rsp
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
call   1030 <floor@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
mulsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
setbe  %al
ucomisd %xmm3,%xmm1
subsd  %xmm0,%xmm2
seta   %cl
xor    %al,%cl
lea    0x18(%rsp),%rsp
jne    1171 <fmod+0x61>
movapd %xmm3,%xmm1
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @fmod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %5
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %2
store double 0.000000e+00, double* %3
br label %34
11: ; preds = %2
%12 = load double, double* %4
%13 = load double, double* %5
%14 = fdiv double %12, %13
%15 = call double @llvm.floor.f64(double %14)
store double %15, double* %6
%16 = load double, double* %4
%17 = load double, double* %6
%18 = load double, double* %5
%19 = fneg double %17
%20 = call double @llvm.fmuladd.f64(double %19, double %18, double %16)
store double %20, double* %7
%21 = load double, double* %4
%22 = fcmp olt double %21, 0.000000e+00
%23 = zext i1 %22 to i32
%24 = load double, double* %5
%25 = fcmp olt double %24, 0.000000e+00
%26 = zext i1 %25 to i32
%27 = icmp ne i32 %23, %26
br i1 %27, label %28, label %32
28: ; preds = %11
%29 = load double, double* %7
%30 = load double, double* %5
%31 = fsub double %29, %30
store double %31, double* %7
br label %32
32: ; preds = %28, %11
%33 = load double, double* %7
store double %33, double* %3
br label %34
34: ; preds = %32, %10
%35 = load double, double* %3
ret double %35
}

LLVM IR (-O2):
define double @fmod(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = fdiv double %0, %1
%6 = tail call double @llvm.floor.f64(double %5)
%7 = fneg double %6
%8 = tail call double @llvm.fmuladd.f64(double %7, double %1, double %0)
%9 = fcmp uge double %0, 0.000000e+00
%10 = fcmp olt double %1, 0.000000e+00
%11 = xor i1 %9, %10
%12 = select i1 %11, double 0.000000e+00, double %1
%13 = fsub double %8, %12
br label %14
14: ; preds = %2, %4
%15 = phi double [ %13, %4 ], [ 0.000000e+00, %2 ]
ret double %15
}