#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 */
double modf(double, double *);
double floor(double x) {
  double f, y;
  if (x > -1.0 && x < 1.0) {
    if (x >= 0) {
      return 0.0;
    } else {
      return -1.0;
    }
  }
  y = modf(x, &f);
  if (y == 0.0)
    return (x);
  if (x >= 0) {
    return f;
  } else {
    return f - 1.0;
  }
}


x86 assembly (clang, -O0):
<floor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1178 <floor+0x68>
movsd  0xecc(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1178 <floor+0x68>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1166 <floor+0x56>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e9 <floor+0xd9>
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e9 <floor+0xd9>
movsd  -0x10(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b2 <floor+0xa2>
jp     11b2 <floor+0xa2>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e9 <floor+0xd9>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d3 <floor+0xc3>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e9 <floor+0xd9>
movsd  -0x18(%rbp),%xmm0
movsd  0xe28(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floor>:
sub    $0x28,%rsp
ucomisd 0xee4(%rip),%xmm0
jbe    1146 <floor+0x36>
movsd  0xee2(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1146 <floor+0x36>
xorpd  %xmm1,%xmm1
cmpnlesd %xmm0,%xmm1
movsd  0xec3(%rip),%xmm0
andpd  %xmm1,%xmm0
add    $0x28,%rsp
ret
lea    0x8(%rsp),%rdi
movapd %xmm0,0x10(%rsp)
call   1030 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116c <floor+0x5c>
jp     116c <floor+0x5c>
movaps 0x10(%rsp),%xmm0
add    $0x28,%rsp
ret
movapd 0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
movsd  0x8(%rsp),%xmm0
jae    1186 <floor+0x76>
addsd  0xe7a(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @floor(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp ogt double %6, -1.000000e+00
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load double, double* %3
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load double, double* %3
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0.000000e+00, double* %2
br label %31
15: ; preds = %11
store double -1.000000e+00, double* %2
br label %31
16: ; preds = %8, %1
%17 = load double, double* %3
%18 = call double @modf(double %17, double* %4)
store double %18, double* %5
%19 = load double, double* %5
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load double, double* %3
store double %22, double* %2
br label %31
23: ; preds = %16
%24 = load double, double* %3
%25 = fcmp oge double %24, 0.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load double, double* %4
store double %27, double* %2
br label %31
28: ; preds = %23
%29 = load double, double* %4
%30 = fsub double %29, 1.000000e+00
store double %30, double* %2
br label %31
31: ; preds = %28, %26, %21, %15, %14
%32 = load double, double* %2
ret double %32
}

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