#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timezone {
  int dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
char *lt2fd() {
  time_t tsec;
  struct tm *ts;
  struct timeval tp;
  struct timezone tzp;
  int month, day, year, hour, minute, second;
  char *isotime;
  gettimeofday(&tp, &tzp);
  tsec = tp.tv_sec;
  ts = localtime(&tsec);
  year = ts->tm_year;
  if (year < 1000)
    year = year + 1900;
  month = ts->tm_mon + 1;
  day = ts->tm_mday;
  hour = ts->tm_hour;
  minute = ts->tm_min;
  second = ts->tm_sec;
  isotime = (char *)calloc(32, sizeof(char));
  sprintf(isotime, "%04d-%02d-%02dT%02d:%02d:%02d", year, month, day, hour,
          minute, second);
  return (isotime);
}


x86 assembly (clang, -O0):
<lt2fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x3e8,-0x2c(%rbp)
jge    1189 <lt2fd+0x49>
mov    -0x2c(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
lea    0xe0f(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lt2fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <gettimeofday@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%ebx
lea    0x76c(%rcx),%ebp
cmp    $0x3e8,%ecx
cmovge %ecx,%ebp
add    $0x1,%ebx
mov    0x8(%rax),%r14d
mov    0xc(%rax),%r15d
mov    0x10(%rax),%ecx
mov    %rcx,0x8(%rsp)
mov    0x14(%rax),%r13d
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
lea    0xe54(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
mov    %r15d,%r9d
push   %r13
push   0x10(%rsp)
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [30 x i8] c"%04d-%02d-%02dT%02d:%02d:%02d\00"
define i8* @lt2fd() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %1
%15 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %15, %struct.tm** %2
%16 = load %struct.tm*, %struct.tm** %2
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1900
store i32 %23, i32* %7
br label %24
24: ; preds = %21, %0
%25 = load %struct.tm*, %struct.tm** %2
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
%29 = load %struct.tm*, %struct.tm** %2
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 2
%31 = load i32, i32* %30
store i32 %31, i32* %6
%32 = load %struct.tm*, %struct.tm** %2
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 3
%34 = load i32, i32* %33
store i32 %34, i32* %8
%35 = load %struct.tm*, %struct.tm** %2
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 4
%37 = load i32, i32* %36
store i32 %37, i32* %9
%38 = load %struct.tm*, %struct.tm** %2
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 5
%40 = load i32, i32* %39
store i32 %40, i32* %10
%41 = call i64 @calloc(i32 32, i32 1)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %11
%43 = load i8*, i8** %11
%44 = load i32, i32* %7
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45, i32 %46, i32 %47, i32 %48, i32 %49)
%51 = load i8*, i8** %11
ret i8* %51
}

LLVM IR (-O2):
%struct.timezone = type { i32 }
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [30 x i8] c"%04d-%02d-%02dT%02d:%02d:%02d\00"
define i8* @lt2fd() {
%1 = alloca i32
%2 = alloca %struct.timezone
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = bitcast i32* %1 to %struct.timeval*
%6 = call i32 @gettimeofday(%struct.timeval* %5, %struct.timezone* %2)
%7 = call %struct.tm* @localtime(i32* %1)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 1000
%11 = add nsw i32 %9, 1900
%12 = select i1 %10, i32 %11, i32 %9
%13 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%23 = load i32, i32* %22
%24 = call i64 @calloc(i32 32, i32 1)
%25 = inttoptr i64 %24 to i8*
%26 = call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
ret i8* %25
}