#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 *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
char *ut2fd() {
  int year, month, day, hour, minute, second;
  time_t tsec;
  struct timeval tp;
  struct timezone tzp;
  struct tm *ts;
  char *isotime;
  gettimeofday(&tp, &tzp);
  tsec = tp.tv_sec;
  ts = gmtime(&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):
<ut2fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    1189 <ut2fd+0x49>
mov    -0x4(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%r10d
mov    -0x18(%rbp),%eax
lea    0xe0f(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut2fd>:
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   1030 <gettimeofday@plt>
mov    %rbx,%rdi
call   1050 <gmtime@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   1040 <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.timeval = type { i32 }
%struct.timezone = 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* @ut2fd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.timezone
%10 = alloca %struct.tm*
%11 = alloca i8*
%12 = call i32 @gettimeofday(%struct.timeval* %8, %struct.timezone* %9)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %7
%15 = call %struct.tm* @gmtime(i32* %7)
store %struct.tm* %15, %struct.tm** %10
%16 = load %struct.tm*, %struct.tm** %10
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %1
%19 = load i32, i32* %1
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1900
store i32 %23, i32* %1
br label %24
24: ; preds = %21, %0
%25 = load %struct.tm*, %struct.tm** %10
%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* %2
%29 = load %struct.tm*, %struct.tm** %10
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 2
%31 = load i32, i32* %30
store i32 %31, i32* %3
%32 = load %struct.tm*, %struct.tm** %10
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 3
%34 = load i32, i32* %33
store i32 %34, i32* %4
%35 = load %struct.tm*, %struct.tm** %10
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 4
%37 = load i32, i32* %36
store i32 %37, i32* %5
%38 = load %struct.tm*, %struct.tm** %10
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 5
%40 = load i32, i32* %39
store i32 %40, i32* %6
%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* %1
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%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* @ut2fd() {
%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* @gmtime(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
}