double floor(double x) {
  double y;
  int ix;
  y = 0.0;
  while (x >= 32768.0) {
    y += 32768.0;
    x -= 32768.0;
  }
  while (x <= -32768.0) {
    y -= 32768.0;
    x += 32768.0;
  }
  if (x > 0.0)
    ix = (int)x;
  else
    ix = (int)(x - 0.9999999999);
  return (y + (double)ix);
}


x86 assembly (clang, -O0):
<floor>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xee2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1155 <floor+0x55>
movsd  0xed0(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1111 <floor+0x11>
jmp    115a <floor+0x5a>
movsd  0xea6(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     119a <floor+0x9a>
movsd  -0x10(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe75(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    115a <floor+0x5a>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b9 <floor+0xb9>
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11d1 <floor+0xd1>
movsd  -0x8(%rbp),%xmm0
movsd  0xe4a(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<floor>:
xorpd  %xmm1,%xmm1
ucomisd 0xef4(%rip),%xmm0
jb     113e <floor+0x3e>
xorpd  %xmm1,%xmm1
movsd  0xee6(%rip),%xmm2
movsd  0xee6(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm2,%xmm1
addsd  %xmm3,%xmm0
ucomisd %xmm2,%xmm0
jae    1130 <floor+0x30>
movsd  0xec2(%rip),%xmm2
ucomisd %xmm0,%xmm2
jb     116e <floor+0x6e>
movsd  0xeac(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  %xmm2,%xmm1
addsd  %xmm3,%xmm0
ucomisd %xmm0,%xmm2
jae    1160 <floor+0x60>
movsd  0xe9a(%rip),%xmm2
addsd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm0,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm2,%xmm3
orpd   %xmm0,%xmm3
cvttpd2dq %xmm3,%xmm0
cvtdq2pd %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @floor(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %2
store double 0.000000e+00, double* %3
br label %5
5: ; preds = %8, %1
%6 = load double, double* %2
%7 = fcmp oge double %6, 3.276800e+04
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load double, double* %3
%10 = fadd double %9, 3.276800e+04
store double %10, double* %3
%11 = load double, double* %2
%12 = fsub double %11, 3.276800e+04
store double %12, double* %2
br label %5
13: ; preds = %5
br label %14
14: ; preds = %17, %13
%15 = load double, double* %2
%16 = fcmp ole double %15, -3.276800e+04
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load double, double* %3
%19 = fsub double %18, 3.276800e+04
store double %19, double* %3
%20 = load double, double* %2
%21 = fadd double %20, 3.276800e+04
store double %21, double* %2
br label %14
22: ; preds = %14
%23 = load double, double* %2
%24 = fcmp ogt double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load double, double* %2
%27 = fptosi double %26 to i32
store i32 %27, i32* %4
br label %32
28: ; preds = %22
%29 = load double, double* %2
%30 = fsub double %29, 0x3FEFFFFFFFF24190
%31 = fptosi double %30 to i32
store i32 %31, i32* %4
br label %32
32: ; preds = %28, %25
%33 = load double, double* %3
%34 = load i32, i32* %4
%35 = sitofp i32 %34 to double
%36 = fadd double %33, %35
ret double %36
}

LLVM IR (-O2):
define double @floor(double %0) {
%2 = fcmp ult double %0, 3.276800e+04
br i1 %2, label %3, label %7
3: ; preds = %7, %1
%4 = phi double [ %0, %1 ], [ %11, %7 ]
%5 = phi double [ 0.000000e+00, %1 ], [ %10, %7 ]
%6 = fcmp ugt double %4, -3.276800e+04
br i1 %6, label %19, label %13
7: ; preds = %1, %7
%8 = phi double [ %10, %7 ], [ 0.000000e+00, %1 ]
%9 = phi double [ %11, %7 ], [ %0, %1 ]
%10 = fadd double %8, 3.276800e+04
%11 = fadd double %9, -3.276800e+04
%12 = fcmp ult double %11, 3.276800e+04
br i1 %12, label %3, label %7
13: ; preds = %3, %13
%14 = phi double [ %16, %13 ], [ %5, %3 ]
%15 = phi double [ %17, %13 ], [ %4, %3 ]
%16 = fadd double %14, -3.276800e+04
%17 = fadd double %15, 3.276800e+04
%18 = fcmp ugt double %17, -3.276800e+04
br i1 %18, label %19, label %13
19: ; preds = %13, %3
%20 = phi double [ %4, %3 ], [ %17, %13 ]
%21 = phi double [ %5, %3 ], [ %16, %13 ]
%22 = fcmp ogt double %20, 0.000000e+00
%23 = fadd double %20, 0xBFEFFFFFFFF24190
%24 = select i1 %22, double %20, double %23
%25 = fptosi double %24 to i32
%26 = sitofp i32 %25 to double
%27 = fadd double %21, %26
ret double %27
}