#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 */
int fabs(int /*<<< orphan*/);
int /*<<< orphan*/ fmod(double, int);
int /*<<< orphan*/ output_logfile(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, double);
void output_double(char *name, double value) {
  char data[2048];
  if (value > 1e7) {
    sprintf(data, "%-35s =         %10e\n", name, value);
  } else {
    if (fabs(fmod(value, 1.)) > 1e-9) {
      sprintf(data, "%-35s = %20.10f\n", name, value);
    } else {
      sprintf(data, "%-35s = %11.1f\n", name, value);
    }
  }
  output_logfile(data);
}


x86 assembly (clang, -O0):
<output_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118c <output_double+0x4c>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
lea    0xe8e(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11fa <output_double+0xba>
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%edi
call   1030 <fmod@plt>
mov    %eax,%edi
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe5a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d9 <output_double+0x99>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
lea    0xe57(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11f5 <output_double+0xb5>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
lea    0xe47(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11fa <output_double+0xba>
lea    -0x810(%rbp),%rdi
call   1050 <output_logfile@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_double>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r14
ucomisd 0xeab(%rip),%xmm0
jbe    1160 <output_double+0x20>
lea    0xeaa(%rip),%rsi
jmp    1197 <output_double+0x57>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0x1,%edi
call   1030 <fmod@plt>
mov    %eax,%edi
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm0
test   %eax,%eax
lea    0xe92(%rip),%rax
lea    0xe9c(%rip),%rsi
cmovg  %rax,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <output_logfile@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%-35s = %10e\0A\00"
@.str.1 = [17 x i8] c"%-35s = %20.10f\0A\00"
@.str.2 = [16 x i8] c"%-35s = %11.1f\0A\00"
define void @output_double(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca [2048 x i8]
store i8* %0, i8** %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp ogt double %6, 1.000000e+07
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = load double, double* %4
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10, double %11)
br label %30
13: ; preds = %2
%14 = load double, double* %4
%15 = call i32 @fmod(double %14, i32 1)
%16 = call i32 @fabs(i32 %15)
%17 = sitofp i32 %16 to double
%18 = fcmp ogt double %17, 1.000000e-09
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = load double, double* %4
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %21, double %22)
br label %29
24: ; preds = %13
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = load double, double* %4
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %26, double %27)
br label %29
29: ; preds = %24, %19
br label %30
30: ; preds = %29, %8
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%32 = call i32 @output_logfile(i8* %31)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"%-35s = %10e\0A\00"
@.str.1 = [17 x i8] c"%-35s = %20.10f\0A\00"
@.str.2 = [16 x i8] c"%-35s = %11.1f\0A\00"
define void @output_double(i8* %0, double %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = fcmp ogt double %1, 1.000000e+07
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @fmod(double %1, i32 1)
%8 = tail call i32 @fabs(i32 %7)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0)
br label %11
11: ; preds = %6, %2
%12 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %2 ], [ %10, %6 ]
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) %12, i8* %0, double %1)
%14 = call i32 @output_logfile(i8* %4)
ret void
}