#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 char *time_t;
struct tm {
  int dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
char *asctime(struct tm *);
char *ctime(char **);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(char **);
struct tm *localtime(char **);
char *mktime(struct tm *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_tm(struct tm *);
int /*<<< orphan*/ printf(char *, ...);
char *time(char **);
int main(int argc, char *argv[]) {
  int ret = 0;
  time_t t1, t2;
  t1 = time(&t2);
  printf("t1 = %ld, t2 = %ld\n", t1, t2);
  struct timeval tv;
  ret = gettimeofday(&tv, NULL);
  if (ret == -1)
    perror("gettimeofday");
  printf("ret %d, tv.sec = %ld, tv.usec = %ld\n", ret, tv.tv_sec, tv.tv_usec);
  struct tm *tm1 = gmtime(&t1);
  struct tm *tm2 = localtime(&t2);
  print_tm(tm1);
  print_tm(tm2);
  time_t t3 = mktime(tm2);
  printf("t3 = %ld\n", t3);
  printf("from asctime: %s", asctime(tm2));
  printf("from ctime: %s", ctime(&t3));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
call   1090 <time@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1206 <main+0x66>
lea    0xe13(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
call   10c0 <gmtime@plt>
mov    %rax,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <print_tm@plt>
mov    -0x40(%rbp),%rdi
call   1080 <print_tm@plt>
mov    -0x40(%rbp),%rdi
call   10a0 <mktime@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <asctime@plt>
mov    %rax,%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x48(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x10(%rsp),%rdi
call   1090 <time@plt>
mov    %rax,0x20(%rsp)
mov    0x10(%rsp),%rdx
lea    0xe3e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1281 <main+0xe1>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%edx
lea    0xe2f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%rdi
call   10c0 <gmtime@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <print_tm@plt>
mov    %rbx,%rdi
call   1080 <print_tm@plt>
mov    %rbx,%rdi
call   10a0 <mktime@plt>
mov    %rax,0x18(%rsp)
lea    0xe0d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <asctime@plt>
lea    0xdfe(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x18(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xdf4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd8c(%rip),%rdi
call   10b0 <perror@plt>
jmp    11e3 <main+0x43>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [20 x i8] c"t1 = %ld, t2 = %ld\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.2 = [37 x i8] c"ret %d, tv.sec = %ld, tv.usec = %ld\0A\00"
@.str.3 = [10 x i8] c"t3 = %ld\0A\00"
@.str.4 = [17 x i8] c"from asctime: %s\00"
@.str.5 = [15 x i8] c"from ctime: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.timeval
%10 = alloca %struct.tm*
%11 = alloca %struct.tm*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = call i8* @time(i8** %8)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32, i32* %6
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %25, i32 %27)
%29 = call %struct.tm* @gmtime(i8** %7)
store %struct.tm* %29, %struct.tm** %10
%30 = call %struct.tm* @localtime(i8** %8)
store %struct.tm* %30, %struct.tm** %11
%31 = load %struct.tm*, %struct.tm** %10
%32 = call i32 @print_tm(%struct.tm* %31)
%33 = load %struct.tm*, %struct.tm** %11
%34 = call i32 @print_tm(%struct.tm* %33)
%35 = load %struct.tm*, %struct.tm** %11
%36 = call i8* @mktime(%struct.tm* %35)
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load %struct.tm*, %struct.tm** %11
%40 = call i8* @asctime(%struct.tm* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = call i8* @ctime(i8** %12)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %42)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [20 x i8] c"t1 = %ld, t2 = %ld\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.2 = [37 x i8] c"ret %d, tv.sec = %ld, tv.usec = %ld\0A\00"
@.str.3 = [10 x i8] c"t3 = %ld\0A\00"
@.str.4 = [17 x i8] c"from asctime: %s\00"
@.str.5 = [15 x i8] c"from ctime: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca i8*
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = call i8* @time(i8** %4)
store i8* %9, i8** %3
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = bitcast %struct.timeval* %5 to i8*
%13 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %19, i32 %21)
%23 = call %struct.tm* @gmtime(i8** %3)
%24 = call %struct.tm* @localtime(i8** %4)
%25 = call i32 @print_tm(%struct.tm* %23)
%26 = call i32 @print_tm(%struct.tm* %24)
%27 = bitcast i8** %6 to i8*
%28 = call i8* @mktime(%struct.tm* %24)
store i8* %28, i8** %6
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = call i8* @asctime(%struct.tm* %24)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = call i8* @ctime(i8** %6)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %32)
ret i32 0
}