#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 */
typedef double int32_t;

/* Variables and functions */
double const copysignk(double, double);
double fabsk(double);
scalar_t__ xisinf(double);
__attribute__((visibility("default"))) const double xfloor(double x) {
  double fr = x - (double)(1LL << 31) * (int32_t)(x * (1.0 / (1LL << 31)));
  fr = fr - (int32_t)fr;
  fr = fr < 0 ? fr + 1.0 : fr;
  return (xisinf(x) || fabsk(x) >= (double)(1LL << 52)) ? x
                                                        : copysignk(x - fr, x);
}


x86 assembly (clang, -O0):
<xfloor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xebe(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xea9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1198 <xfloor+0x68>
movsd  0xe87(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11a2 <xfloor+0x72>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xisinf@plt>
cmp    $0x0,%rax
jne    11dc <xfloor+0xac>
movsd  -0x8(%rbp),%xmm0
call   1050 <fabsk@plt>
movsd  0xe46(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11eb <xfloor+0xbb>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1204 <xfloor+0xd4>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <copysignk@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfloor>:
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <xisinf@plt>
test   %rax,%rax
jne    11a8 <xfloor+0x78>
movsd  (%rsp),%xmm0
call   1050 <fabsk@plt>
ucomisd 0xec6(%rip),%xmm0
jae    11a8 <xfloor+0x78>
movsd  0xea4(%rip),%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  0xe9b(%rip),%xmm0
addsd  %xmm1,%xmm0
subsd  %xmm0,%xmm0
movsd  0xe93(%rip),%xmm4
addsd  %xmm0,%xmm4
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm4
andnpd %xmm0,%xmm3
orpd   %xmm4,%xmm3
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
pop    %rax
jmp    1030 <copysignk@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @xfloor(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = load double, double* %2
%6 = fmul double %5, 0x3E00000000000000
%7 = call double @llvm.fmuladd.f64(double 0xC1E0000000000000, double %6, double %4)
store double %7, double* %3
%8 = load double, double* %3
%9 = load double, double* %3
%10 = fsub double %8, %9
store double %10, double* %3
%11 = load double, double* %3
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load double, double* %3
%15 = fadd double %14, 1.000000e+00
br label %18
16: ; preds = %1
%17 = load double, double* %3
br label %18
18: ; preds = %16, %13
%19 = phi double [ %15, %13 ], [ %17, %16 ]
store double %19, double* %3
%20 = load double, double* %2
%21 = call i64 @xisinf(double %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load double, double* %2
%25 = call double @fabsk(double %24)
%26 = fcmp oge double %25, 0x4330000000000000
br i1 %26, label %27, label %29
27: ; preds = %23, %18
%28 = load double, double* %2
br label %35
29: ; preds = %23
%30 = load double, double* %2
%31 = load double, double* %3
%32 = fsub double %30, %31
%33 = load double, double* %2
%34 = call double @copysignk(double %32, double %33)
br label %35
35: ; preds = %29, %27
%36 = phi double [ %28, %27 ], [ %34, %29 ]
ret double %36
}

LLVM IR (-O2):
define double @xfloor(double %0) {
%2 = fmul double %0, 0x3E00000000000000
%3 = tail call double @llvm.fmuladd.f64(double %2, double 0xC1E0000000000000, double %0)
%4 = fsub double %3, %3
%5 = fcmp olt double %4, 0.000000e+00
%6 = fadd double %4, 1.000000e+00
%7 = select i1 %5, double %6, double %4
%8 = tail call i64 @xisinf(double %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = tail call double @fabsk(double %0)
%12 = fcmp ult double %11, 0x4330000000000000
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = fsub double %0, %7
%15 = tail call double @copysignk(double %14, double %0)
br label %16
16: ; preds = %1, %10, %13
%17 = phi double [ %15, %13 ], [ %0, %10 ], [ %0, %1 ]
ret double %17
}