double floor(d)
double d;
{
  double fract;
  if (d < 0.0) {
    d = -d;
    fract = modf(d, &d);
    if (fract != 0.0)
      d += 1;
    d = -d;
  } else
    modf(d, &d);
  return (d);
}


x86 assembly (clang, -O0):
<floor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11b4 <floor+0xa4>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x8(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117c <floor+0x6c>
jp     117c <floor+0x6c>
jmp    118e <floor+0x7e>
movsd  0xe7c(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c2 <floor+0xb2>
movsd  -0x8(%rbp),%xmm0
lea    -0x8(%rbp),%rdi
call   1030 <modf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floor>:
push   %rax
movsd  %xmm0,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    116e <floor+0x5e>
xorpd  0xed8(%rip),%xmm0
movlpd %xmm0,(%rsp)
mov    %rsp,%rdi
call   1030 <modf@plt>
movsd  (%rsp),%xmm1
movsd  0xece(%rip),%xmm2
addsd  %xmm1,%xmm2
cmpneqsd 0xec9(%rip),%xmm0
movapd %xmm0,%xmm3
andnpd %xmm1,%xmm3
andpd  %xmm2,%xmm0
orpd   %xmm3,%xmm0
xorpd  0xe99(%rip),%xmm0
movlpd %xmm0,(%rsp)
pop    %rax
ret
mov    %rsp,%rdi
call   1030 <modf@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @floor(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = fcmp olt double %4, 0.000000e+00
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = load double, double* %2
%8 = fneg double %7
store double %8, double* %2
%9 = load double, double* %2
%10 = call double @modf(double %9, double* %2)
store double %10, double* %3
%11 = load double, double* %3
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load double, double* %2
%15 = fadd double %14, 1.000000e+00
store double %15, double* %2
br label %16
16: ; preds = %13, %6
%17 = load double, double* %2
%18 = fneg double %17
store double %18, double* %2
br label %22
19: ; preds = %1
%20 = load double, double* %2
%21 = call double @modf(double %20, double* %2)
br label %22
22: ; preds = %19, %16
%23 = load double, double* %2
ret double %23
}

LLVM IR (-O2):
define double @floor(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = fcmp olt double %0, 0.000000e+00
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = fneg double %0
store double %5, double* %2
%6 = call double @modf(double %5, double* %2)
%7 = fcmp une double %6, 0.000000e+00
%8 = load double, double* %2
%9 = fadd double %8, 1.000000e+00
%10 = select i1 %7, double %9, double %8
%11 = fneg double %10
store double %11, double* %2
br label %15
12: ; preds = %1
%13 = call double @modf(double %0, double* %2)
%14 = load double, double* %2
br label %15
15: ; preds = %12, %4
%16 = phi double [ %14, %12 ], [ %11, %4 ]
ret double %16
}