double fmod(x, y)
double x, y;
{
  int ir, iy;
  double r, w;
  if (y == (double)0 || isnan(y) || !finite(x))
    return (x * y) / (x * y);
  r = fabs(x);
  y = fabs(y);
  (void)frexp(y, &iy);
  while (r >= y) {
    (void)frexp(r, &ir);
    w = ldexp(y, ir - iy);
    r -= w <= r ? w : w * (double)0.5;
  }
  return x >= (double)0 ? r : -r;
}


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    115f <fmod+0x2f>
jp     115f <fmod+0x2f>
jmp    1196 <fmod+0x66>
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%al
call   1050 <isnan@plt>
cmp    $0x0,%eax
jne    1196 <fmod+0x66>
movsd  -0x10(%rbp),%xmm0
movaps 0xe90(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11b8 <fmod+0x88>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bc <fmod+0x18c>
movsd  -0x10(%rbp),%xmm0
movaps 0xe4c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe37(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <frexp@plt>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1270 <fmod+0x140>
movsd  -0x28(%rbp),%xmm0
lea    -0x1c(%rbp),%rdi
call   1040 <frexp@plt>
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
sub    -0x20(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1246 <fmod+0x116>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1258 <fmod+0x128>
movsd  0xdba(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11f0 <fmod+0xc0>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1291 <fmod+0x161>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12b2 <fmod+0x182>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmod>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1159 <fmod+0x29>
jp     1159 <fmod+0x29>
mulsd  %xmm1,%xmm2
divsd  %xmm2,%xmm2
movapd %xmm2,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
movapd %xmm1,%xmm0
mov    $0x1,%al
movapd %xmm2,0x30(%rsp)
movapd %xmm1,0x10(%rsp)
call   1050 <isnan@plt>
movapd 0x10(%rsp),%xmm1
movapd 0x30(%rsp),%xmm2
test   %eax,%eax
jne    1146 <fmod+0x16>
movapd 0xe78(%rip),%xmm3
andpd  %xmm2,%xmm3
ucomisd 0xe8c(%rip),%xmm3
je     1146 <fmod+0x16>
andpd  0xe62(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
lea    0x8(%rsp),%rdi
movapd %xmm1,%xmm0
movapd %xmm3,0x20(%rsp)
call   1040 <frexp@plt>
movapd 0x20(%rsp),%xmm3
ucomisd 0x10(%rsp),%xmm3
jb     1226 <fmod+0xf6>
mov    0x8(%rsp),%ebp
lea    0xc(%rsp),%rbx
nop
movapd %xmm3,0x20(%rsp)
movapd %xmm3,%xmm0
mov    %rbx,%rdi
call   1040 <frexp@plt>
mov    0xc(%rsp),%edi
sub    %ebp,%edi
movapd 0x10(%rsp),%xmm0
call   1030 <ldexp@plt>
movapd 0x20(%rsp),%xmm3
movapd %xmm0,%xmm1
mulsd  0xe23(%rip),%xmm1
movapd %xmm0,%xmm2
cmplesd %xmm3,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
subsd  %xmm2,%xmm3
ucomisd 0x10(%rsp),%xmm3
jae    11d0 <fmod+0xa0>
movapd 0xde2(%rip),%xmm0
xorpd  %xmm3,%xmm0
xorpd  %xmm2,%xmm2
cmplesd 0x30(%rsp),%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm0,%xmm2
orpd   %xmm3,%xmm2
jmp    114e <fmod+0x1e>

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
store double %0, double* %4
store double %1, double* %5
%10 = load double, double* %5
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load double, double* %5
%14 = call i32 (double, ...) bitcast (i32 (...)* @isnan to i32 (double, ...)*)(double %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load double, double* %4
%18 = call double @llvm.fabs.f64(double %17)
%19 = fcmp one double %18, 0x7FF0000000000000
br i1 %19, label %28, label %20
20: ; preds = %16, %12, %2
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fmul double %21, %22
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fmul double %24, %25
%27 = fdiv double %23, %26
store double %27, double* %3
br label %69
28: ; preds = %16
%29 = load double, double* %4
%30 = call double @llvm.fabs.f64(double %29)
store double %30, double* %8
%31 = load double, double* %5
%32 = call double @llvm.fabs.f64(double %31)
store double %32, double* %5
%33 = load double, double* %5
%34 = call double @frexp(double %33, i32* %7)
br label %35
35: ; preds = %55, %28
%36 = load double, double* %8
%37 = load double, double* %5
%38 = fcmp oge double %36, %37
br i1 %38, label %39, label %59
39: ; preds = %35
%40 = load double, double* %8
%41 = call double @frexp(double %40, i32* %6)
%42 = load double, double* %5
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = sub nsw i32 %43, %44
%46 = call double @ldexp(double %42, i32 %45)
store double %46, double* %9
%47 = load double, double* %9
%48 = load double, double* %8
%49 = fcmp ole double %47, %48
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = load double, double* %9
br label %55
52: ; preds = %39
%53 = load double, double* %9
%54 = fmul double %53, 5.000000e-01
br label %55
55: ; preds = %52, %50
%56 = phi double [ %51, %50 ], [ %54, %52 ]
%57 = load double, double* %8
%58 = fsub double %57, %56
store double %58, double* %8
br label %35
59: ; preds = %35
%60 = load double, double* %4
%61 = fcmp oge double %60, 0.000000e+00
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = load double, double* %8
br label %67
64: ; preds = %59
%65 = load double, double* %8
%66 = fneg double %65
br label %67
67: ; preds = %64, %62
%68 = phi double [ %63, %62 ], [ %66, %64 ]
store double %68, double* %3
br label %69
69: ; preds = %67, %20
%70 = load double, double* %3
ret double %70
}

LLVM IR (-O2):
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 %14, label %8
8: ; preds = %2
%9 = tail call i32 (double, ...) bitcast (i32 (...)* @isnan to i32 (double, ...)*)(double %1)
%10 = icmp ne i32 %9, 0
%11 = tail call double @llvm.fabs.f64(double %0)
%12 = fcmp ueq double %11, 0x7FF0000000000000
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %17
14: ; preds = %8, %2
%15 = fmul double %0, %1
%16 = fdiv double %15, %15
br label %39
17: ; preds = %8
%18 = tail call double @llvm.fabs.f64(double %1)
%19 = call double @frexp(double %18, i32* %4)
%20 = fcmp ult double %11, %18
br i1 %20, label %34, label %21
21: ; preds = %17
%22 = load i32, i32* %4
br label %23
23: ; preds = %21, %23
%24 = phi double [ %11, %21 ], [ %32, %23 ]
%25 = call double @frexp(double %24, i32* %3)
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, %22
%28 = tail call double @ldexp(double %18, i32 %27)
%29 = fcmp ole double %28, %24
%30 = fmul double %28, 5.000000e-01
%31 = select i1 %29, double %28, double %30
%32 = fsub double %24, %31
%33 = fcmp ult double %32, %18
br i1 %33, label %34, label %23
34: ; preds = %23, %17
%35 = phi double [ %11, %17 ], [ %32, %23 ]
%36 = fcmp oge double %0, 0.000000e+00
%37 = fneg double %35
%38 = select i1 %36, double %35, double %37
br label %39
39: ; preds = %34, %14
%40 = phi double [ %16, %14 ], [ %38, %34 ]
ret double %40
}