#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 */
struct tm {
  int tm_hour;
  int tm_min;
};

/* Variables and functions */
int /*<<< orphan*/ dump_time_struct_bytes(struct tm *, int);
int /*<<< orphan*/ localtime_r(long *, struct tm *);
int /*<<< orphan*/ printf(char *, void *, ...);
long time(int /*<<< orphan*/);
int main() {
  long int seconds_since_epoch;
  struct tm current_time, *time_ptr;
  int hour, minute, second, i, *int_ptr;
  seconds_since_epoch = time(0);
  printf("time() - seconds since epoch: %ld\n", seconds_since_epoch);
  time_ptr = &current_time;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
  localtime_r(&seconds_since_epoch, time_ptr);
#pragma GCC diagnostic pop
  hour = current_time.tm_hour;
  minute = time_ptr->tm_min;
  second = *((int *)time_ptr);
  printf("Current time is: %02d:%02d:%02d\n", hour, minute, second);
  dump_time_struct_bytes(time_ptr, sizeof(struct tm));
  minute = hour = 0;
  int_ptr = (int *)time_ptr;
  for (i = 0; i < 3; i++) {
    printf("int_ptr @ %p : %d\n", (void *)int_ptr, *int_ptr);
    int_ptr++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1030 <localtime_r@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movslq -0x24(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1040 <dump_time_struct_bytes@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    1219 <main+0xd9>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11dd <main+0x9d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,0x8(%rsp)
lea    0xea4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
call   1030 <localtime_r@plt>
lea    0x4(%rsp),%r14
mov    (%rsp),%eax
mov    0x4(%rsp),%edx
movslq %eax,%rcx
lea    0xe97(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    $0x8,%esi
call   1040 <dump_time_struct_bytes@plt>
mov    (%rsp),%edx
lea    0xe97(%rip),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
@.str = [35 x i8] c"time() - seconds since epoch: %ld\0A\00"
@.str.1 = [33 x i8] c"Current time is: %02d:%02d:%02d\0A\00"
@.str.2 = [19 x i8] c"int_ptr @ %p : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.tm
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %1
%10 = call i64 @time(i32 0)
store i64 %10, i64* %2
%11 = load i64, i64* %2
%12 = inttoptr i64 %11 to i8*
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
store %struct.tm* %3, %struct.tm** %4
%14 = load %struct.tm*, %struct.tm** %4
%15 = call i32 @localtime_r(i64* %2, %struct.tm* %14)
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %5
%18 = load %struct.tm*, %struct.tm** %4
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
%20 = load i32, i32* %19
store i32 %20, i32* %6
%21 = load %struct.tm*, %struct.tm** %4
%22 = bitcast %struct.tm* %21 to i32*
%23 = load i32, i32* %22
store i32 %23, i32* %7
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27, i32 %28)
%30 = load %struct.tm*, %struct.tm** %4
%31 = call i32 @dump_time_struct_bytes(%struct.tm* %30, i32 8)
store i32 0, i32* %5
store i32 0, i32* %6
%32 = load %struct.tm*, %struct.tm** %4
%33 = bitcast %struct.tm* %32 to i32*
store i32* %33, i32** %9
store i32 0, i32* %8
br label %34
34: ; preds = %45, %0
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 3
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load i32*, i32** %9
%39 = bitcast i32* %38 to i8*
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %39, i32 %41)
%43 = load i32*, i32** %9
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %9
br label %45
45: ; preds = %37
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %34
48: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
@.str = [35 x i8] c"time() - seconds since epoch: %ld\0A\00"
@.str.1 = [33 x i8] c"Current time is: %02d:%02d:%02d\0A\00"
@.str.2 = [19 x i8] c"int_ptr @ %p : %d\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca %struct.tm
%3 = bitcast i64* %1 to i8*
%4 = bitcast %struct.tm* %2 to i8*
%5 = tail call i64 @time(i32 0)
store i64 %5, i64* %1
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 @localtime_r(i64* %1, %struct.tm* %2)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sext i32 %10 to i64
%14 = inttoptr i64 %13 to i8*
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %12, i32 %10)
%16 = call i32 @dump_time_struct_bytes(%struct.tm* %2, i32 8)
%17 = bitcast %struct.tm* %2 to i8*
%18 = load i32, i32* %9
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %18)
%20 = getelementptr inbounds i32, i32* %9, i64 1
%21 = bitcast i32* %20 to i8*
%22 = load i32, i32* %20
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %22)
%24 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 1, i32 0
%25 = bitcast i32* %24 to i8*
%26 = load i32, i32* %24
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %26)
ret i32 0
}