#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 ceiling_double(double);
double floor_double(double d) {
  if (d >= 0.0) {
    if (d > 1.0)
      return (double)(int)d;
    else if (d > 0.5)
      return 0.5;
    else if (d > 0.2)
      return 0.2;
    else if (d > 0.1)
      return 0.1;
    else if (d > 0.05)
      return 0.05;
    else
      return 0.0;
  } else {
    return -ceiling_double(-d);
  }
}


x86 assembly (clang, -O0):
<floor_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     120a <floor_double+0xfa>
movsd  -0x10(%rbp),%xmm0
movsd  0xec4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1159 <floor_double+0x49>
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
movsd  -0x10(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1182 <floor_double+0x72>
movsd  0xe90(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
movsd  -0x10(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ab <floor_double+0x9b>
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
movsd  -0x10(%rbp),%xmm0
movsd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d4 <floor_double+0xc4>
movsd  0xe4e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
movsd  -0x10(%rbp),%xmm0
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11fd <floor_double+0xed>
movsd  0xe2d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <floor_double+0x137>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <ceiling_double@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floor_double>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    1136 <floor_double+0x26>
xorpd  0xf0d(%rip),%xmm0
call   1030 <ceiling_double@plt>
movapd %xmm0,%xmm1
xorpd  0xefc(%rip),%xmm1
jmp    1189 <floor_double+0x79>
ucomisd 0xec2(%rip),%xmm0
jbe    114a <floor_double+0x3a>
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm1
jmp    1189 <floor_double+0x79>
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1189 <floor_double+0x79>
movsd  0xeb0(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1189 <floor_double+0x79>
movsd  0xeaa(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1189 <floor_double+0x79>
movsd  0xea4(%rip),%xmm2
movapd %xmm2,%xmm1
cmpltsd %xmm0,%xmm1
andpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

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

LLVM IR (-O2):
define double @floor_double(double %0) {
%2 = fcmp ult double %0, 0.000000e+00
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = fcmp ogt double %0, 1.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = fptosi double %0 to i32
%7 = sitofp i32 %6 to double
br label %21
8: ; preds = %3
%9 = fcmp ogt double %0, 5.000000e-01
br i1 %9, label %21, label %10
10: ; preds = %8
%11 = fcmp ogt double %0, 2.000000e-01
br i1 %11, label %21, label %12
12: ; preds = %10
%13 = fcmp ogt double %0, 1.000000e-01
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = fcmp ogt double %0, 5.000000e-02
%16 = select i1 %15, double 5.000000e-02, double 0.000000e+00
br label %21
17: ; preds = %1
%18 = fneg double %0
%19 = tail call double @ceiling_double(double %18)
%20 = fneg double %19
br label %21
21: ; preds = %14, %12, %10, %8, %17, %5
%22 = phi double [ %7, %5 ], [ %20, %17 ], [ 5.000000e-01, %8 ], [ 2.000000e-01, %10 ], [ 1.000000e-01, %12 ], [ %16, %14 ]
ret double %22
}