#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 /*<<< orphan*/ ExcelSerialDateToDMY(int, int *, int *, int *);
double modf(double, double *);
int /*<<< orphan*/ sprintf(char *, char *, double, ...);
void format_double_2(unsigned char *buffer, double value, int date) {
  double tmp;
  if (date) {
    int day, month, year;
    ExcelSerialDateToDMY((int)value, &day, &month, &year);
    sprintf((char *)buffer, ":d:%04d-%02d-%02d", year, month, day);
  } else if (modf(value, &tmp) == 0.0)
    sprintf((char *)buffer, ":f:%.0f", value);
  else
    sprintf((char *)buffer, ":f:%g", value);
}


x86 assembly (clang, -O0):
<format_double_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1186 <format_double_2+0x56>
cvttsd2si -0x10(%rbp),%edi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <ExcelSerialDateToDMY@plt>
mov    -0x8(%rbp),%rdi
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe86(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    11df <format_double_2+0xaf>
movsd  -0x10(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1030 <modf@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c3 <format_double_2+0x93>
jp     11c3 <format_double_2+0x93>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe5b(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    11da <format_double_2+0xaa>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe47(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
jmp    11df <format_double_2+0xaf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_double_2>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
test   %esi,%esi
je     117c <format_double_2+0x4c>
cvttsd2si %xmm0,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1040 <ExcelSerialDateToDMY@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rsp),%xmm0
mov    0xc(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbx
ret
lea    0x18(%rsp),%rdi
movsd  %xmm0,0x10(%rsp)
call   1030 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a1 <format_double_2+0x71>
jp     11a1 <format_double_2+0x71>
lea    0xe73(%rip),%rsi
jmp    11a8 <format_double_2+0x78>
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
add    $0x20,%rsp
pop    %rbx
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c":d:%04d-%02d-%02d\00"
@.str.1 = [8 x i8] c":f:%.0f\00"
@.str.2 = [6 x i8] c":f:%g\00"
define void @format_double_2(i8* %0, double %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load double, double* %5
%15 = fptosi double %14 to i32
%16 = call i32 @ExcelSerialDateToDMY(i32 %15, i32* %8, i32* %9, i32* %10)
%17 = load i8*, i8** %4
%18 = load i32, i32* %10
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %19, i32 %20, i32 %21)
br label %36
23: ; preds = %3
%24 = load double, double* %5
%25 = call double @modf(double %24, double* %7)
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load double, double* %5
%30 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %29)
br label %35
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = load double, double* %5
%34 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %33)
br label %35
35: ; preds = %31, %27
br label %36
36: ; preds = %35, %13
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c":d:%04d-%02d-%02d\00"
@.str.1 = [8 x i8] c":f:%.0f\00"
@.str.2 = [6 x i8] c":f:%g\00"
define void @format_double_2(i8* nocapture writeonly %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast double* %4 to i8*
%9 = icmp eq i32 %2, 0
br i1 %9, label %21, label %10
10: ; preds = %3
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = fptosi double %1 to i32
%15 = call i32 @ExcelSerialDateToDMY(i32 %14, i32* %5, i32* %6, i32* %7)
%16 = load i32, i32* %7
%17 = sitofp i32 %16 to double
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %17, i32 %18, i32 %19)
br label %28
21: ; preds = %3
%22 = call double @modf(double %1, double* %4)
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %1)
br label %28
26: ; preds = %21
%27 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %1)
br label %28
28: ; preds = %24, %26, %10
ret void
}