#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;
};

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
size_t strftime(char *, int const, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  const static int bufSize = 128;
  time_t t = time(NULL);
  struct tm gmt = *gmtime(&t);
  struct tm localt = *localtime(&t);
  printf("direct from struct tm:\n");
  printf("universal time is now %04d-%02d-%02d %02d:%02d:%02d\n",
         gmt.tm_year + 1900, gmt.tm_mon, gmt.tm_mday, gmt.tm_hour, gmt.tm_min,
         gmt.tm_sec);
  char buf[bufSize];
  size_t len = strftime(buf, bufSize, "%Y-%m-%d %H:%M:%S", &gmt);
  printf("from strftime (gmt):\n");
  printf("universal time is now %s (%ld characters)\n", buf, len);
  len = strftime(buf, bufSize, "%Y-%m-%d %H:%M:%S %Z", &localt);
  printf("from strftime (localt):\n");
  printf("local time is now %s (%ld characters)\n", buf, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <gmtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x48(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x40(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%esi
add    $0x76c,%esi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xe38(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    %rsp,%rax
mov    %rax,-0x50(%rbp)
lea    -0xe0(%rbp),%rdi
mov    $0x80,%esi
lea    0xe49(%rip),%rdx
lea    -0x30(%rbp),%rcx
call   1060 <strftime@plt>
mov    %rax,-0x58(%rbp)
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdx
lea    0xe4b(%rip),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    $0x80,%esi
lea    0xe55(%rip),%rdx
lea    -0x48(%rbp),%rcx
call   1060 <strftime@plt>
mov    %rax,-0x58(%rbp)
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdx
lea    0xe5d(%rip),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xd0,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <gmtime@plt>
movups (%rax),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x20(%rsp)
mov    %rbx,%rdi
call   1030 <localtime@plt>
movups (%rax),%xmm0
movaps %xmm0,0x30(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x40(%rsp)
lea    0xef9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x76c,%esi
add    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    0x20(%rsp),%r9d
mov    0x24(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r15
lea    0xe41(%rip),%rdx
lea    0x50(%rsp),%r14
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    $0x80,%esi
call   1070 <strftime@plt>
mov    %rax,%rbx
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe26(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3d(%rip),%rdx
lea    0x30(%rsp),%rcx
mov    %r14,%rdi
mov    $0x80,%esi
call   1070 <strftime@plt>
mov    %rax,%rbx
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2a(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@main.bufSize = internal constant i32 128
@.str = [24 x i8] c"direct from struct tm:\0A\00"
@.str.1 = [53 x i8] c"universal time is now %04d-%02d-%02d %02d:%02d:%02d\0A\00"
@.str.2 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.3 = [22 x i8] c"from strftime (gmt):\0A\00"
@.str.4 = [43 x i8] c"universal time is now %s (%ld characters)\0A\00"
@.str.5 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.6 = [25 x i8] c"from strftime (localt):\0A\00"
@.str.7 = [39 x i8] c"local time is now %s (%ld characters)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca %struct.tm
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @time(i32* null)
store i32 %11, i32* %6
%12 = call %struct.tm* @gmtime(i32* %6)
%13 = bitcast %struct.tm* %7 to i8*
%14 = bitcast %struct.tm* %12 to i8*
%15 = call %struct.tm* @localtime(i32* %6)
%16 = bitcast %struct.tm* %8 to i8*
%17 = bitcast %struct.tm* %15 to i8*
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1900
%22 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %9
%34 = alloca i8, i64 128
%35 = call i64 @strftime(i8* %34, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %7)
store i64 %35, i64* %10
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%37 = load i64, i64* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %34, i64 %37)
%39 = call i64 @strftime(i8* %34, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %8)
store i64 %39, i64* %10
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%41 = load i64, i64* %10
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %34, i64 %41)
store i32 0, i32* %3
%43 = load i8*, i8** %9
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str.1 = [53 x i8] c"universal time is now %04d-%02d-%02d %02d:%02d:%02d\0A\00"
@.str.2 = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.4 = [43 x i8] c"universal time is now %s (%ld characters)\0A\00"
@.str.5 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.7 = [39 x i8] c"local time is now %s (%ld characters)\0A\00"
@str = [23 x i8] c"direct from struct tm:\00"
@str.8 = [21 x i8] c"from strftime (gmt):\00"
@str.9 = [24 x i8] c"from strftime (localt):\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca %struct.tm
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = bitcast %struct.tm* %4 to i8*
%9 = call %struct.tm* @gmtime(i32* %3)
%10 = bitcast %struct.tm* %9 to i8*
%11 = bitcast %struct.tm* %5 to i8*
%12 = call %struct.tm* @localtime(i32* %3)
%13 = bitcast %struct.tm* %12 to i8*
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27)
%29 = call i8* @llvm.stacksave()
%30 = alloca [128 x i8]
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %30, i64 0, i64 0
%32 = call i64 @strftime(i8* %31, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %4)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %31, i64 %32)
%35 = call i64 @strftime(i8* %31, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %5)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %31, i64 %35)
ret i32 0
}