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


x86 assembly (clang, -O0):
<ceil>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
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    1157 <ceil+0x47>
jp     1157 <ceil+0x47>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <ceil+0xd5>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b2 <ceil+0xa2>
movsd  0xe92(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b2 <ceil+0xa2>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a5 <ceil+0x95>
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <ceil+0xd5>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <ceil+0xd5>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11db <ceil+0xcb>
movsd  0xe3c(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <ceil+0xd5>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ceil>:
sub    $0x28,%rsp
lea    0x8(%rsp),%rdi
movapd %xmm0,0x10(%rsp)
call   1030 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    113a <ceil+0x2a>
jp     113a <ceil+0x2a>
movaps 0x10(%rsp),%xmm0
add    $0x28,%rsp
ret
movapd 0x10(%rsp),%xmm1
ucomisd 0xeb8(%rip),%xmm1
jbe    1172 <ceil+0x62>
movsd  0xeb6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1172 <ceil+0x62>
xorpd  %xmm2,%xmm2
cmpltsd %xmm1,%xmm2
movsd  0xe9f(%rip),%xmm0
andpd  %xmm2,%xmm0
add    $0x28,%rsp
ret
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
jbe    118a <ceil+0x7a>
addsd  0xe7e(%rip),%xmm0
add    $0x28,%rsp
ret

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

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