#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 /*<<< orphan*/ FILE;

/* Variables and functions */
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
void WriteReal(FILE *f, double x) {
  long ix1, ix2, ix;
  ix1 = fabs(x) * 10000. + 0.5;
  ix2 = (fabs(x) + 0.5);
  ix2 = ix2 * 10000;
  if (ix1 == ix2) {
    if (x > 0) {
      ix = x + 0.5;
    } else {
      ix = -x + 0.5;
      ix = -ix;
    }
    fprintf(f, " %2ld", ix);
  } else
    fprintf(f, " % .9E", x);
}


x86 assembly (clang, -O0):
<WriteReal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xee3(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xecf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xebb(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xeb2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe96(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
imul   $0x2710,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1214 <WriteReal+0x104>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11be <WriteReal+0xae>
movsd  0xe55(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x28(%rbp)
jmp    11f9 <WriteReal+0xe9>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe1e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
sub    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x28(%rbp),%xmm0
lea    0xe16(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1229 <WriteReal+0x119>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe02(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteReal>:
movapd 0xee8(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xeec(%rip),%xmm3
mulsd  %xmm2,%xmm3
movsd  0xee8(%rip),%xmm1
addsd  %xmm1,%xmm3
cvttsd2si %xmm3,%rax
addsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rcx
imul   $0x2710,%rcx,%rcx
cmp    %rax,%rcx
jne    1167 <WriteReal+0x57>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    1173 <WriteReal+0x63>
addsd  0xeb8(%rip),%xmm0
cvttsd2si %xmm0,%rax
jmp    117f <WriteReal+0x6f>
lea    0xeb8(%rip),%rsi
jmp    1030 <fprintf@plt>
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
neg    %rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
lea    0xe92(%rip),%rsi
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" %2ld\00"
@.str.1 = [7 x i8] c" % .9E\00"
define void @WriteReal(i32* %0, double %1) {
%3 = alloca i32*
%4 = alloca double
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %3
store double %1, double* %4
%8 = load double, double* %4
%9 = call double @llvm.fabs.f64(double %8)
%10 = call double @llvm.fmuladd.f64(double %9, double 1.000000e+04, double 5.000000e-01)
%11 = fptosi double %10 to i64
store i64 %11, i64* %5
%12 = load double, double* %4
%13 = call double @llvm.fabs.f64(double %12)
%14 = fadd double %13, 5.000000e-01
%15 = fptosi double %14 to i64
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = mul nsw i64 %16, 10000
store i64 %17, i64* %6
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %2
%22 = load double, double* %4
%23 = fcmp ogt double %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load double, double* %4
%26 = fadd double %25, 5.000000e-01
%27 = fptosi double %26 to i64
store i64 %27, i64* %7
br label %35
28: ; preds = %21
%29 = load double, double* %4
%30 = fneg double %29
%31 = fadd double %30, 5.000000e-01
%32 = fptosi double %31 to i64
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = sub nsw i64 0, %33
store i64 %34, i64* %7
br label %35
35: ; preds = %28, %24
%36 = load i32*, i32** %3
%37 = load i64, i64* %7
%38 = sitofp i64 %37 to double
%39 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %38)
br label %44
40: ; preds = %2
%41 = load i32*, i32** %3
%42 = load double, double* %4
%43 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %42)
br label %44
44: ; preds = %40, %35
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" %2ld\00"
@.str.1 = [7 x i8] c" % .9E\00"
define void @WriteReal(i32* nocapture %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %1)
%4 = tail call double @llvm.fmuladd.f64(double %3, double 1.000000e+04, double 5.000000e-01)
%5 = fptosi double %4 to i64
%6 = fadd double %3, 5.000000e-01
%7 = fptosi double %6 to i64
%8 = mul nsw i64 %7, 10000
%9 = icmp eq i64 %8, %5
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = fcmp ogt double %1, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = fadd double %1, 5.000000e-01
%14 = fptosi double %13 to i64
br label %19
15: ; preds = %10
%16 = fsub double 5.000000e-01, %1
%17 = fptosi double %16 to i64
%18 = sub nsw i64 0, %17
br label %19
19: ; preds = %15, %12
%20 = phi i64 [ %14, %12 ], [ %18, %15 ]
%21 = sitofp i64 %20 to double
%22 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %21)
br label %25
23: ; preds = %2
%24 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %1)
br label %25
25: ; preds = %23, %19
ret void
}