#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*/ jul2greg(double, int *, int *, int *, int *, int *,
                            double *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
char *julian_to_yyyy_mm_dd(double julian) {
  char buffer[128];
  int year, month, day, hour, minute;
  double seconds;
  if (!julian) {
    strcpy(buffer, "0000-00-00");
  } else {
    jul2greg(julian, &month, &day, &year, &hour, &minute, &seconds);
    sprintf(buffer, "%d-%.2d-%.2d", year, month, day);
  }
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<julian_to_yyyy_mm_dd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1180 <julian_to_yyyy_mm_dd+0x40>
jp     1180 <julian_to_yyyy_mm_dd+0x40>
lea    -0x90(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11da <julian_to_yyyy_mm_dd+0x9a>
movsd  -0x8(%rbp),%xmm0
lea    -0x98(%rbp),%rdi
lea    -0x9c(%rbp),%rsi
lea    -0x94(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
lea    -0xa4(%rbp),%r8
lea    -0xb0(%rbp),%r9
call   1040 <jul2greg@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%edx
mov    -0x98(%rbp),%ecx
mov    -0x9c(%rbp),%r8d
lea    0xe36(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <strdup@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<julian_to_yyyy_mm_dd>:
sub    $0xa8,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1153 <julian_to_yyyy_mm_dd+0x13>
jnp    1196 <julian_to_yyyy_mm_dd+0x56>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x18(%rsp),%r9
call   1040 <jul2greg@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
lea    0xe81(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1050 <sprintf@plt>
jmp    11a7 <julian_to_yyyy_mm_dd+0x67>
lea    0xe63(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x20(%rsp),%rdi
call   1060 <strdup@plt>
add    $0xa8,%rsp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0000-00-00\00"
@.str.1 = [13 x i8] c"%d-%.2d-%.2d\00"
define i8* @julian_to_yyyy_mm_dd(double %0) {
%2 = alloca double
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double %0, double* %2
%10 = load double, double* %2
%11 = fcmp une double %10, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %23
15: ; preds = %1
%16 = load double, double* %2
%17 = call i32 @jul2greg(double %16, i32* %5, i32* %6, i32* %4, i32* %7, i32* %8, double* %9)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
br label %23
23: ; preds = %15, %12
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%25 = call i8* @strdup(i8* %24)
ret i8* %25
}

LLVM IR (-O2):
@.str = [11 x i8] c"0000-00-00\00"
@.str.1 = [13 x i8] c"%d-%.2d-%.2d\00"
define noalias i8* @julian_to_yyyy_mm_dd(double %0) {
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast double* %8 to i8*
%16 = fcmp une double %0, 0.000000e+00
br i1 %16, label %19, label %17
17: ; preds = %1
%18 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %25
19: ; preds = %1
%20 = call i32 @jul2greg(double %0, i32* %4, i32* %5, i32* %3, i32* %6, i32* %7, double* %8)
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22, i32 %23)
br label %25
25: ; preds = %19, %17
%26 = call i8* @strdup(i8* %9)
ret i8* %26
}