#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 unsigned long time_t;
struct tm {
  int dummy;
};
struct timeval {
  unsigned long tv_sec;
};
struct timespec {
  unsigned long tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(unsigned long *);
struct tm *localtime(unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
unsigned long time(unsigned long *);
int /*<<< orphan*/ time_show(struct tm *, char *);
int main(int argc, char *argv[]) {
  time_t t = time(NULL);
  printf("time %ld by time\n", (unsigned long)t);
  time_t v;
  time(&v);
  printf("time %ld by time\n", (unsigned long)v);
  struct timespec ts;
  if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
    printf("clock_gettime error.\n");
  }
  printf("time %ld by clock_gettime\n", ts.tv_sec);
  struct timeval tv;
  gettimeofday(&tv, NULL);
  printf("time %ld by gettimeofday\n", tv.tv_sec);
  struct tm *tmptr = gmtime(&t);
  time_show(tmptr, "time gmtime");
  tmptr = localtime(&v);
  time_show(tmptr, "time localtime");
  tmptr = localtime(&ts.tv_sec);
  time_show(tmptr, "clock_gettime localtime");
  tmptr = gmtime(&tv.tv_sec);
  time_show(tmptr, "gettimeofday gmtime");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <time@plt>
mov    -0x20(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    11e9 <main+0x79>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x30(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1090 <gmtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1050 <time_show@plt>
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <time_show@plt>
lea    -0x28(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1050 <time_show@plt>
lea    -0x30(%rbp),%rdi
call   1090 <gmtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1050 <time_show@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x18(%rsp)
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x8(%rsp),%rdi
call   1090 <time@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x60>
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rsi
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    0x10(%rsp),%rsi
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x18(%rsp),%rdi
call   10a0 <gmtime@plt>
lea    0xe22(%rip),%rsi
mov    %rax,%rdi
call   1060 <time_show@plt>
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe1e(%rip),%rsi
mov    %rax,%rdi
call   1060 <time_show@plt>
mov    %rsp,%rdi
call   1030 <localtime@plt>
lea    0xdfe(%rip),%rsi
mov    %rax,%rdi
call   1060 <time_show@plt>
mov    %rbx,%rdi
call   10a0 <gmtime@plt>
lea    0xdff(%rip),%rsi
mov    %rax,%rdi
call   1060 <time_show@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64 }
%struct.timeval = type { i64 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"time %ld by time\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [27 x i8] c"time %ld by clock_gettime\0A\00"
@.str.3 = [26 x i8] c"time %ld by gettimeofday\0A\00"
@.str.4 = [12 x i8] c"time gmtime\00"
@.str.5 = [15 x i8] c"time localtime\00"
@.str.6 = [24 x i8] c"clock_gettime localtime\00"
@.str.7 = [20 x i8] c"gettimeofday gmtime\00"
@str = [21 x i8] c"clock_gettime error.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.timespec
%6 = alloca %struct.timeval
%7 = bitcast i64* %3 to i8*
%8 = tail call i64 @time(i64* null)
store i64 %8, i64* %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = bitcast i64* %4 to i8*
%11 = call i64 @time(i64* %4)
%12 = load i64, i64* %4
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = bitcast %struct.timespec* %5 to i8*
%15 = load i32, i32* @CLOCK_REALTIME
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%22 = load i64, i64* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %22)
%24 = bitcast %struct.timeval* %6 to i8*
%25 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%27 = load i64, i64* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %27)
%29 = call %struct.tm* @gmtime(i64* %3)
%30 = call i32 @time_show(%struct.tm* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%31 = call %struct.tm* @localtime(i64* %4)
%32 = call i32 @time_show(%struct.tm* %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%33 = call %struct.tm* @localtime(i64* %21)
%34 = call i32 @time_show(%struct.tm* %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%35 = call %struct.tm* @gmtime(i64* %26)
%36 = call i32 @time_show(%struct.tm* %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}