#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 DateFromTime(double);
int MonthFromTime(double);
int YearFromTime(double);
int /*<<< orphan*/ isfinite(double);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
char *fmtdate(char *buf, double t) {
  int y = YearFromTime(t);
  int m = MonthFromTime(t);
  int d = DateFromTime(t);
  if (!isfinite(t))
    return "Invalid Date";
  sprintf(buf, "%04d-%02d-%02d", y, m + 1, d);
  return buf;
}


x86 assembly (clang, -O0):
<fmtdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <YearFromTime@plt>
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <MonthFromTime@plt>
mov    %eax,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <DateFromTime@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <isfinite@plt>
cmp    $0x0,%eax
jne    11ab <fmtdate+0x5b>
lea    0xe5e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <fmtdate+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    -0x24(%rbp),%r8d
lea    0xe4a(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmtdate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rdi,%rbx
call   1050 <YearFromTime@plt>
mov    %eax,%r14d
movsd  (%rsp),%xmm0
call   1070 <MonthFromTime@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1040 <DateFromTime@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
call   1030 <isfinite@plt>
test   %eax,%eax
je     11aa <fmtdate+0x5a>
add    $0x1,%ebp
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1060 <sprintf@plt>
jmp    11b1 <fmtdate+0x61>
lea    0xe4f(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Invalid Date\00"
@.str.1 = [15 x i8] c"%04d-%02d-%02d\00"
define i8* @fmtdate(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
%9 = load double, double* %5
%10 = call i32 @YearFromTime(double %9)
store i32 %10, i32* %6
%11 = load double, double* %5
%12 = call i32 @MonthFromTime(double %11)
store i32 %12, i32* %7
%13 = load double, double* %5
%14 = call i32 @DateFromTime(double %13)
store i32 %14, i32* %8
%15 = load double, double* %5
%16 = call i32 @isfinite(double %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %3
br label %27
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %8
%25 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %23, i32 %24)
%26 = load i8*, i8** %4
store i8* %26, i8** %3
br label %27
27: ; preds = %19, %18
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [13 x i8] c"Invalid Date\00"
@.str.1 = [15 x i8] c"%04d-%02d-%02d\00"
define i8* @fmtdate(i8* writeonly %0, double %1) {
%3 = tail call i32 @YearFromTime(double %1)
%4 = tail call i32 @MonthFromTime(double %1)
%5 = tail call i32 @DateFromTime(double %1)
%6 = tail call i32 @isfinite(double %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = add nsw i32 %4, 1
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %9, i32 %5)
br label %11
11: ; preds = %2, %8
%12 = phi i8* [ %0, %8 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %12
}