#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 */
int /*<<< orphan*/ EDOM;
int /*<<< orphan*/ errno;
double frexp(double, int *);
double ldexp(double, int);
double(fmod)(double x, double y) {
  double t;
  int n, neg;
  int ychar, xchar;
  if (y == 0.0) {
    errno = EDOM;
    return 0.0;
  }
  if (y < 0.0)
    y = -y;
  if (x < 0.0)
    x = -x, neg = 1;
  else
    neg = 0;
  t = frexp(y, &ychar);
  t = frexp(x, &xchar);
  for (n = xchar - ychar; 0 <= n; --n) {
    t = ldexp(y, n);
    if (t <= x)
      x -= t;
  }
  return (neg ? -x : x);
}


x86 assembly (clang, -O0):
<fmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1169 <fmod+0x49>
jp     1169 <fmod+0x49>
mov    0x2e97(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a4 <fmod+0x184>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1198 <fmod+0x78>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d3 <fmod+0xb3>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11da <fmod+0xba>
movl   $0x0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    -0x2c(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jg     1260 <fmod+0x140>
movsd  -0x18(%rbp),%xmm0
mov    -0x24(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     124d <fmod+0x12d>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1252 <fmod+0x132>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <fmod+0xe9>
cmpl   $0x0,-0x28(%rbp)
je     1290 <fmod+0x170>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    129a <fmod+0x17a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
push   %rbx
sub    $0x40,%rsp
movapd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114c <fmod+0x2c>
jp     114c <fmod+0x2c>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    0x2e93(%rip),%rcx
mov    %eax,(%rcx)
jmp    1232 <fmod+0x112>
movapd 0xeac(%rip),%xmm2
movapd %xmm1,%xmm3
xorpd  %xmm2,%xmm3
movapd %xmm1,%xmm5
cmpltsd %xmm0,%xmm5
andpd  %xmm5,%xmm3
andnpd %xmm1,%xmm5
orpd   %xmm3,%xmm5
xorpd  %xmm4,%xmm2
movapd %xmm4,%xmm1
cmpltsd %xmm0,%xmm1
andpd  %xmm1,%xmm2
movapd %xmm4,0x20(%rsp)
andnpd %xmm4,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,0x10(%rsp)
lea    0xc(%rsp),%rdi
movapd %xmm5,0x30(%rsp)
movapd %xmm5,%xmm0
call   1040 <frexp@plt>
lea    0x8(%rsp),%rdi
movapd 0x10(%rsp),%xmm0
call   1040 <frexp@plt>
mov    0x8(%rsp),%ebx
sub    0xc(%rsp),%ebx
js     1201 <fmod+0xe1>
movapd 0x10(%rsp),%xmm3
nopw   0x0(%rax,%rax,1)
movapd %xmm3,0x10(%rsp)
movapd 0x30(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <ldexp@plt>
movapd 0x10(%rsp),%xmm3
movapd %xmm0,%xmm1
cmpnlesd %xmm3,%xmm1
andnpd %xmm0,%xmm1
subsd  %xmm1,%xmm3
add    $0xffffffff,%ebx
jb     11d0 <fmod+0xb0>
jmp    1207 <fmod+0xe7>
movapd 0x10(%rsp),%xmm3
movapd 0xdf1(%rip),%xmm0
xorpd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm2
cmpltsd %xmm1,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm3,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EDOM = global i32 0
@errno = global i32 0
define double @fmod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store double %0, double* %4
store double %1, double* %5
%11 = load double, double* %5
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* @EDOM
store i32 %14, i32* @errno
store double 0.000000e+00, double* %3
br label %64
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* %4
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load double, double* %4
%26 = fneg double %25
store double %26, double* %4
store i32 1, i32* %8
br label %28
27: ; preds = %21
store i32 0, i32* %8
br label %28
28: ; preds = %27, %24
%29 = load double, double* %5
%30 = call double @frexp(double %29, i32* %9)
store double %30, double* %6
%31 = load double, double* %4
%32 = call double @frexp(double %31, i32* %10)
store double %32, double* %6
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = sub nsw i32 %33, %34
store i32 %35, i32* %7
br label %36
36: ; preds = %51, %28
%37 = load i32, i32* %7
%38 = icmp sle i32 0, %37
br i1 %38, label %39, label %54
39: ; preds = %36
%40 = load double, double* %5
%41 = load i32, i32* %7
%42 = call double @ldexp(double %40, i32 %41)
store double %42, double* %6
%43 = load double, double* %6
%44 = load double, double* %4
%45 = fcmp ole double %43, %44
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load double, double* %6
%48 = load double, double* %4
%49 = fsub double %48, %47
store double %49, double* %4
br label %50
50: ; preds = %46, %39
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, -1
store i32 %53, i32* %7
br label %36
54: ; preds = %36
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load double, double* %4
%59 = fneg double %58
br label %62
60: ; preds = %54
%61 = load double, double* %4
br label %62
62: ; preds = %60, %57
%63 = phi double [ %59, %57 ], [ %61, %60 ]
store double %63, double* %3
br label %64
64: ; preds = %62, %13
%65 = load double, double* %3
ret double %65
}

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