#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 int ulong;

/* Variables and functions */
int floor(double);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int);
char *ground(double d) {
  int neg = 0;
  static char res[30];
  ulong ival;
  ulong l;
  if (d < 0) {
    neg = 1;
    d = -d;
  }
  ival = floor(d);
  d -= ival;
  l = floor(d * 100000000);
  if (l % 10 >= 5)
    l = l / 10 + 1;
  else
    l = l / 10;
  sprintf(res, "%s%ld.%07ld", neg ? "-" : "", ival, l);
  return res;
}


x86 assembly (clang, -O0):
<ground>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    116a <ground+0x4a>
movl   $0x1,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe6e(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x5,%edx
jl     11c9 <ground+0xa9>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d7 <ground+0xb7>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%ecx
lea    0xe34(%rip),%rdx
lea    0xe2c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0x2e43(%rip),%rdi
lea    0xe04(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e30(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ground>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    113a <ground+0x1a>
xorpd  0xec6(%rip),%xmm0
movapd %xmm0,(%rsp)
lea    0xede(%rip),%rax
lea    0xed8(%rip),%rbx
cmova  %rax,%rbx
call   1040 <floor@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xea0(%rip),%xmm1
movapd %xmm1,%xmm0
call   1040 <floor@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
sar    $0x22,%rdx
shr    $0x3f,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%eax
xor    %r8d,%r8d
cmp    $0x5,%eax
setge  %r8b
add    %ecx,%r8d
lea    0x2e95(%rip),%r14
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1030 <sprintf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@ground.res = internal global [30 x i8] zeroinitializer
@.str = [12 x i8] c"%s%ld.%07ld\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @ground(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store double %0, double* %2
store i32 0, i32* %3
%6 = load double, double* %2
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %1
store i32 1, i32* %3
%9 = load double, double* %2
%10 = fneg double %9
store double %10, double* %2
br label %11
11: ; preds = %8, %1
%12 = load double, double* %2
%13 = call i32 @floor(double %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = sitofp i32 %14 to double
%16 = load double, double* %2
%17 = fsub double %16, %15
store double %17, double* %2
%18 = load double, double* %2
%19 = fmul double %18, 1.000000e+08
%20 = call i32 @floor(double %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = srem i32 %21, 10
%23 = icmp sge i32 %22, 5
br i1 %23, label %24, label %28
24: ; preds = %11
%25 = load i32, i32* %5
%26 = sdiv i32 %25, 10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %31
28: ; preds = %11
%29 = load i32, i32* %5
%30 = sdiv i32 %29, 10
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %24
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = call i32 @sprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @ground.res, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %35, i32 %36, i32 %37)
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @ground.res, i64 0, i64 0)
}

LLVM IR (-O2):
@ground.res = internal global [30 x i8] zeroinitializer
@.str = [12 x i8] c"%s%ld.%07ld\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @ground(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = tail call i32 @floor(double %4)
%6 = sitofp i32 %5 to double
%7 = fsub double %4, %6
%8 = fmul double %7, 1.000000e+08
%9 = tail call i32 @floor(double %8)
%10 = srem i32 %9, 10
%11 = icmp sgt i32 %10, 4
%12 = sdiv i32 %9, 10
%13 = zext i1 %11 to i32
%14 = add nsw i32 %12, %13
%15 = select i1 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%16 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @ground.res, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %5, i32 %14)
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @ground.res, i64 0, i64 0)
}