#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 HourFromTime(double);
int MinFromTime(double);
int SecFromTime(double);
double fabs(double);
int /*<<< orphan*/ isfinite(double);
int msFromTime(double);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, ...);
char *fmttime(char *buf, double t, double tza) {
  int H = HourFromTime(t);
  int M = MinFromTime(t);
  int S = SecFromTime(t);
  int ms = msFromTime(t);
  int tzh = HourFromTime(fabs(tza));
  int tzm = MinFromTime(fabs(tza));
  if (!isfinite(t))
    return "Invalid Date";
  if (tza == 0)
    sprintf(buf, "%02d:%02d:%02d.%03dZ", H, M, S, ms);
  else if (tza < 0)
    sprintf(buf, "%02d:%02d:%02d.%03d-%02d:%02d", H, M, S, ms, tzh, tzm);
  else
    sprintf(buf, "%02d:%02d:%02d.%03d+%02d:%02d", H, M, S, ms, tzh, tzm);
  return buf;
}


x86 assembly (clang, -O0):
<fmttime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <HourFromTime@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1080 <MinFromTime@plt>
mov    %eax,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <SecFromTime@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <msFromTime@plt>
mov    %eax,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movaps 0xe4a(%rip),%xmm1
pand   %xmm1,%xmm0
call   1040 <HourFromTime@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x20(%rbp),%xmm0
movaps 0xe32(%rip),%xmm1
pand   %xmm1,%xmm0
call   1080 <MinFromTime@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <isfinite@plt>
cmp    $0x0,%eax
jne    11fd <fmttime+0x9d>
lea    0xe1c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b8 <fmttime+0x158>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    123a <fmttime+0xda>
jp     123a <fmttime+0xda>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12b0 <fmttime+0x150>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    127c <fmttime+0x11c>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
lea    0xdca(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12ab <fmttime+0x14b>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
lea    0xdb4(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12b0 <fmttime+0x150>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmttime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movapd %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdi,%rbx
call   1040 <HourFromTime@plt>
mov    %eax,%r14d
movsd  (%rsp),%xmm0
call   1080 <MinFromTime@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
call   1060 <SecFromTime@plt>
mov    %eax,%r12d
movsd  (%rsp),%xmm0
call   1030 <msFromTime@plt>
mov    %eax,%ebp
movaps 0xe4f(%rip),%xmm0
andps  0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
call   1040 <HourFromTime@plt>
mov    %rax,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
call   1080 <MinFromTime@plt>
mov    %eax,%r13d
movsd  (%rsp),%xmm0
call   1050 <isfinite@plt>
test   %eax,%eax
je     1211 <fmttime+0xb1>
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    121a <fmttime+0xba>
jp     121a <fmttime+0xba>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    1250 <fmttime+0xf0>
lea    0xdf8(%rip),%rbx
jmp    1250 <fmttime+0xf0>
ucomisd %xmm1,%xmm0
jbe    1229 <fmttime+0xc9>
lea    0xe0b(%rip),%rsi
jmp    1230 <fmttime+0xd0>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
push   %r13
push   0x10(%rsp)
call   1070 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Invalid Date\00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%03dZ\00"
@.str.2 = [30 x i8] c"%02d:%02d:%02d.%03d-%02d:%02d\00"
@.str.3 = [30 x i8] c"%02d:%02d:%02d.%03d+%02d:%02d\00"
define i8* @fmttime(i8* %0, double %1, double %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store double %1, double* %6
store double %2, double* %7
%14 = load double, double* %6
%15 = call i32 @HourFromTime(double %14)
store i32 %15, i32* %8
%16 = load double, double* %6
%17 = call i32 @MinFromTime(double %16)
store i32 %17, i32* %9
%18 = load double, double* %6
%19 = call i32 @SecFromTime(double %18)
store i32 %19, i32* %10
%20 = load double, double* %6
%21 = call i32 @msFromTime(double %20)
store i32 %21, i32* %11
%22 = load double, double* %7
%23 = call double @llvm.fabs.f64(double %22)
%24 = call i32 @HourFromTime(double %23)
store i32 %24, i32* %12
%25 = load double, double* %7
%26 = call double @llvm.fabs.f64(double %25)
%27 = call i32 @MinFromTime(double %26)
store i32 %27, i32* %13
%28 = load double, double* %6
%29 = call i32 @isfinite(double %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %3
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %4
br label %66
32: ; preds = %3
%33 = load double, double* %7
%34 = fcmp oeq double %33, 0.000000e+00
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %38, i32 %39, i32 %40)
br label %64
42: ; preds = %32
%43 = load double, double* %7
%44 = fcmp olt double %43, 0.000000e+00
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = load i32, i32* %13
%53 = call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %48, i32 %49, i32 %50, i32 %51, i32 %52)
br label %63
54: ; preds = %42
%55 = load i8*, i8** %5
%56 = load i32, i32* %8
%57 = load i32, i32* %9
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = load i32, i32* %13
%62 = call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61)
br label %63
63: ; preds = %54, %45
br label %64
64: ; preds = %63, %35
%65 = load i8*, i8** %5
store i8* %65, i8** %4
br label %66
66: ; preds = %64, %31
%67 = load i8*, i8** %4
ret i8* %67
}

LLVM IR (-O2):
@.str = [13 x i8] c"Invalid Date\00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%03dZ\00"
@.str.2 = [30 x i8] c"%02d:%02d:%02d.%03d-%02d:%02d\00"
@.str.3 = [30 x i8] c"%02d:%02d:%02d.%03d+%02d:%02d\00"
define i8* @fmttime(i8* writeonly %0, double %1, double %2) {
%4 = tail call i32 @HourFromTime(double %1)
%5 = tail call i32 @MinFromTime(double %1)
%6 = tail call i32 @SecFromTime(double %1)
%7 = tail call i32 @msFromTime(double %1)
%8 = tail call double @llvm.fabs.f64(double %2)
%9 = tail call i32 @HourFromTime(double %8)
%10 = tail call i32 @MinFromTime(double %8)
%11 = tail call i32 @isfinite(double %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %3
%14 = fcmp oeq double %2, 0.000000e+00
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5, i32 %6, i32 %7)
br label %23
17: ; preds = %13
%18 = fcmp olt double %2, 0.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = tail call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %5, i32 %6, i32 %7, i32 %9, i32 %10)
br label %23
21: ; preds = %17
%22 = tail call i32 (i8*, i8*, i32, i32, i32, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 %5, i32 %6, i32 %7, i32 %9, i32 %10)
br label %23
23: ; preds = %15, %21, %19, %3
%24 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %3 ], [ %0, %19 ], [ %0, %21 ], [ %0, %15 ]
ret i8* %24
}