#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 ceil(double);
int clip_f15(long);
double floor(double);
int /*<<< orphan*/ printf(char *, double);
void printval(double val, int fixed) {
  if (fixed) {
    double new_val = val * (double)(1 << 15);
    new_val = new_val >= 0 ? floor(new_val + 0.5) : ceil(new_val - 0.5);
    printf(" "
           "%6d"
           ",",
           clip_f15((long int)new_val));
  } else {
    printf(" "
           "%.18e"
           ",",
           val);
  }
}


x86 assembly (clang, -O0):
<printval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11df <printval+0x9f>
movsd  0xe9e(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     119a <printval+0x5a>
movsd  0xe82(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11b5 <printval+0x75>
movsd  -0x18(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%rdi
call   1050 <clip_f15@plt>
cvtsi2sd %eax,%xmm0
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
jmp    11f0 <printval+0xb0>
movsd  -0x8(%rbp),%xmm0
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printval>:
test   %edi,%edi
je     1166 <printval+0x26>
push   %rax
mulsd  0xeb3(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    1172 <printval+0x32>
addsd  0xeb1(%rip),%xmm0
call   1030 <ceil@plt>
jmp    117f <printval+0x3f>
lea    0xeb1(%rip),%rdi
jmp    1040 <printf@plt>
addsd  0xe8e(%rip),%xmm0
call   1060 <floor@plt>
cvttsd2si %xmm0,%rdi
call   1050 <clip_f15@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe81(%rip),%rdi
pop    %rax
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" %6d,\00"
@.str.1 = [8 x i8] c" %.18e,\00"
define void @printval(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = load double, double* %3
%10 = fmul double %9, 3.276800e+04
store double %10, double* %5
%11 = load double, double* %5
%12 = fcmp oge double %11, 0.000000e+00
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load double, double* %5
%15 = fadd double %14, 5.000000e-01
%16 = call double @llvm.floor.f64(double %15)
br label %21
17: ; preds = %8
%18 = load double, double* %5
%19 = fsub double %18, 5.000000e-01
%20 = call double @llvm.ceil.f64(double %19)
br label %21
21: ; preds = %17, %13
%22 = phi double [ %16, %13 ], [ %20, %17 ]
store double %22, double* %5
%23 = load double, double* %5
%24 = fptosi double %23 to i64
%25 = call i32 @clip_f15(i64 %24)
%26 = sitofp i32 %25 to double
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %26)
br label %31
28: ; preds = %2
%29 = load double, double* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %29)
br label %31
31: ; preds = %28, %21
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" %6d,\00"
@.str.1 = [8 x i8] c" %.18e,\00"
define void @printval(double %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = fmul double %0, 3.276800e+04
%6 = fcmp ult double %5, 0.000000e+00
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = fadd double %5, 5.000000e-01
%9 = tail call double @llvm.floor.f64(double %8)
br label %13
10: ; preds = %4
%11 = fadd double %5, -5.000000e-01
%12 = tail call double @llvm.ceil.f64(double %11)
br label %13
13: ; preds = %10, %7
%14 = phi double [ %9, %7 ], [ %12, %10 ]
%15 = fptosi double %14 to i64
%16 = tail call i32 @clip_f15(i64 %15)
%17 = sitofp i32 %16 to double
%18 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %17)
br label %21
19: ; preds = %2
%20 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %21
21: ; preds = %19, %13
ret void
}