#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 frexp(double, int *);
scalar_t__ ldexp(double, int);
double fmod(double x, double y) {
  int sign = 0, yexp;
  double r, yfr;
  if (y == 0)
    return 0;
  if (y < 0)
    y = -y;
  yfr = frexp(y, &yexp);
  if (x < 0) {
    sign = 1;
    r = -x;
  } else
    r = x;
  while (r >= y) {
    int rexp;
    double rfr = frexp(r, &rexp);
    r -= ldexp(y, rexp - yexp - (rfr < yfr));
  }
  if (sign)
    r = -r;
  return r;
}


x86 assembly (clang, -O0):
<fmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115e <fmod+0x3e>
jp     115e <fmod+0x3e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1282 <fmod+0x162>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    118d <fmod+0x6d>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11db <fmod+0xbb>
movl   $0x1,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11e5 <fmod+0xc5>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ea <fmod+0xca>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     124d <fmod+0x12d>
movsd  -0x28(%rbp),%xmm0
lea    -0x34(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x34(%rbp),%edi
sub    -0x20(%rbp),%edi
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
ucomisd %xmm2,%xmm1
seta   %al
and    $0x1,%al
movzbl %al,%eax
sub    %eax,%edi
call   1030 <ldexp@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11ea <fmod+0xca>
cmpl   $0x0,-0x1c(%rbp)
je     1278 <fmod+0x158>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1131 <fmod+0x11>
jp     1131 <fmod+0x11>
ret
push   %rbp
push   %rbx
sub    $0x58,%rsp
movapd %xmm1,%xmm3
xorpd  0xebd(%rip),%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm1,%xmm0
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm1,%xmm0
orpd   %xmm3,%xmm0
movapd %xmm0,0x20(%rsp)
lea    0xc(%rsp),%rdi
movapd %xmm2,0x10(%rsp)
call   1040 <frexp@plt>
movapd 0xe86(%rip),%xmm2
movapd 0x10(%rsp),%xmm3
xorpd  %xmm3,%xmm2
movapd %xmm3,%xmm1
movapd %xmm3,%xmm4
cmpltsd 0xe7b(%rip),%xmm1
andpd  %xmm1,%xmm2
movapd %xmm2,%xmm3
movapd %xmm1,0x40(%rsp)
movapd %xmm1,%xmm2
movapd 0x20(%rsp),%xmm1
andnpd %xmm4,%xmm2
orpd   %xmm3,%xmm2
ucomisd %xmm1,%xmm2
jb     1221 <fmod+0x101>
mov    0xc(%rsp),%ebp
lea    0x8(%rsp),%rbx
movsd  %xmm0,0x38(%rsp)
nopw   0x0(%rax,%rax,1)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
mov    %rbx,%rdi
call   1040 <frexp@plt>
mov    0x8(%rsp),%edi
sub    %ebp,%edi
xor    %eax,%eax
movsd  0x38(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
sub    %eax,%edi
movaps 0x20(%rsp),%xmm0
call   1030 <ldexp@plt>
movapd 0x10(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  %xmm0,%xmm2
movapd 0x20(%rsp),%xmm1
ucomisd %xmm1,%xmm2
jae    11d0 <fmod+0xb0>
movapd 0xdd7(%rip),%xmm1
xorpd  %xmm2,%xmm1
movapd 0x40(%rsp),%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @fmod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32 0, i32* %6
%12 = load double, double* %5
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %2
store double 0.000000e+00, double* %3
br label %60
15: ; preds = %2
%16 = load double, double* %5
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load double, double* %5
%20 = fneg double %19
store double %20, double* %5
br label %21
21: ; preds = %18, %15
%22 = load double, double* %5
%23 = call double @frexp(double %22, i32* %7)
store double %23, double* %9
%24 = load double, double* %4
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %21
store i32 1, i32* %6
%27 = load double, double* %4
%28 = fneg double %27
store double %28, double* %8
br label %31
29: ; preds = %21
%30 = load double, double* %4
store double %30, double* %8
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %36, %31
%33 = load double, double* %8
%34 = load double, double* %5
%35 = fcmp oge double %33, %34
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = load double, double* %8
%38 = call double @frexp(double %37, i32* %10)
store double %38, double* %11
%39 = load double, double* %5
%40 = load i32, i32* %10
%41 = load i32, i32* %7
%42 = sub nsw i32 %40, %41
%43 = load double, double* %11
%44 = load double, double* %9
%45 = fcmp olt double %43, %44
%46 = zext i1 %45 to i32
%47 = sub nsw i32 %42, %46
%48 = call i64 @ldexp(double %39, i32 %47)
%49 = sitofp i64 %48 to double
%50 = load double, double* %8
%51 = fsub double %50, %49
store double %51, double* %8
br label %32
52: ; preds = %32
%53 = load i32, i32* %6
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load double, double* %8
%57 = fneg double %56
store double %57, double* %8
br label %58
58: ; preds = %55, %52
%59 = load double, double* %8
store double %59, double* %3
br label %60
60: ; preds = %58, %14
%61 = load double, double* %3
ret double %61
}

LLVM IR (-O2):
define double @fmod(double %0, double %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = fcmp oeq double %1, 0.000000e+00
br i1 %6, label %35, label %7
7: ; preds = %2
%8 = fcmp olt double %1, 0.000000e+00
%9 = fneg double %1
%10 = select i1 %8, double %9, double %1
%11 = call double @frexp(double %10, i32* %3)
%12 = fcmp olt double %0, 0.000000e+00
%13 = fneg double %0
%14 = select i1 %12, double %13, double %0
%15 = fcmp ult double %14, %10
br i1 %15, label %31, label %16
16: ; preds = %7
%17 = bitcast i32* %4 to i8*
%18 = load i32, i32* %3
br label %19
19: ; preds = %16, %19
%20 = phi double [ %14, %16 ], [ %29, %19 ]
%21 = call double @frexp(double %20, i32* %4)
%22 = load i32, i32* %4
%23 = sub i32 %22, %18
%24 = fcmp olt double %21, %11
%25 = sext i1 %24 to i32
%26 = add i32 %23, %25
%27 = tail call i64 @ldexp(double %10, i32 %26)
%28 = sitofp i64 %27 to double
%29 = fsub double %20, %28
%30 = fcmp ult double %29, %10
br i1 %30, label %31, label %19
31: ; preds = %19, %7
%32 = phi double [ %14, %7 ], [ %29, %19 ]
%33 = fneg double %32
%34 = select i1 %12, double %33, double %32
br label %35
35: ; preds = %2, %31
%36 = phi double [ %34, %31 ], [ 0.000000e+00, %2 ]
ret double %36
}