#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);
int /*<<< orphan*/ mtherr(char *, int);
double fmod(double x, double y) {
  if (y == 0) {
    mtherr("fmod", 1);
    return 0.0;
  } else {
    double div;
    div = x / y;
    if (div < 0)
      div = -floor(-div);
    else
      div = floor(div);
    return (x - div * y);
  }
}


x86 assembly (clang, -O0):
<fmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1168 <fmod+0x48>
jp     1168 <fmod+0x48>
lea    0xeaf(%rip),%rdi
mov    $0x1,%esi
call   1030 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1209 <fmod+0xe9>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11c7 <fmod+0xa7>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <floor@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11d6 <fmod+0xb6>
movsd  -0x20(%rbp),%xmm0
call   1040 <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,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1149 <fmod+0x29>
jp     1149 <fmod+0x29>
lea    0xed9(%rip),%rdi
mov    $0x1,%esi
call   1030 <mtherr@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
ret
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
jbe    1176 <fmod+0x56>
xorpd  0xe99(%rip),%xmm0
call   1040 <floor@plt>
xorpd  0xe8c(%rip),%xmm0
jmp    117b <fmod+0x5b>
call   1040 <floor@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"fmod\00"
define double @fmod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %5
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @mtherr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
store double 0.000000e+00, double* %3
br label %31
11: ; preds = %2
%12 = load double, double* %4
%13 = load double, double* %5
%14 = fdiv double %12, %13
store double %14, double* %6
%15 = load double, double* %6
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load double, double* %6
%19 = fneg double %18
%20 = call double @llvm.floor.f64(double %19)
%21 = fneg double %20
store double %21, double* %6
br label %25
22: ; preds = %11
%23 = load double, double* %6
%24 = call double @llvm.floor.f64(double %23)
store double %24, double* %6
br label %25
25: ; preds = %22, %17
%26 = load double, double* %4
%27 = load double, double* %6
%28 = load double, double* %5
%29 = fneg double %27
%30 = call double @llvm.fmuladd.f64(double %29, double %28, double %26)
store double %30, double* %3
br label %31
31: ; preds = %25, %9
%32 = load double, double* %3
ret double %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"fmod\00"
define double @fmod(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @mtherr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
br label %19
6: ; preds = %2
%7 = fdiv double %0, %1
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = fneg double %7
%11 = tail call double @llvm.floor.f64(double %10)
%12 = fneg double %11
br label %15
13: ; preds = %6
%14 = tail call double @llvm.floor.f64(double %7)
br label %15
15: ; preds = %13, %9
%16 = phi double [ %12, %9 ], [ %14, %13 ]
%17 = fneg double %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %1, double %0)
br label %19
19: ; preds = %15, %4
%20 = phi double [ 0.000000e+00, %4 ], [ %18, %15 ]
ret double %20
}