#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 time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
struct tm *localtime(int *);
int /*<<< orphan*/ memset(char *, int, int);
int mktime(struct tm *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int time(int /*<<< orphan*/ *);
int main(void) {
  struct tm *pt;
  char buf[26 + 1] = {};
  time_t t = time(NULL);
  if (-1 == t)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day04/time.c",
              22, "time", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  pt = localtime(&t);
  while (1) {
    memset(buf, 0x00, sizeof(buf));
    fflush(stdout);
    t = time(NULL);
    printf("t=%d\n", t);
    pt = localtime(&t);
    printf("return=%d\n", mktime(pt));
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x34(%rbp)
mov    $0xffffffff,%eax
cmp    -0x34(%rbp),%eax
jne    122b <main+0x8b>
jmp    11de <main+0x3e>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%r9
lea    0xdfb(%rip),%rsi
lea    0xe04(%rip),%rdx
mov    $0x16,%ecx
lea    0xe8b(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <mktime@plt>
mov    %eax,%esi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
jmp    1238 <main+0x98>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x1b(%rsp)
movaps %xmm0,0x10(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1253 <main+0xb3>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <localtime@plt>
lea    0x10(%rsp),%r15
mov    0x2de1(%rip),%r13
lea    0xeba(%rip),%r12
lea    0xeb9(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1b,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%edi
call   1080 <fflush@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1090 <mktime@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
jmp    1200 <main+0x60>
mov    0x2d86(%rip),%rax
mov    (%rax),%ebx
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd8f(%rip),%rsi
lea    0xd98(%rip),%rdx
lea    0xe24(%rip),%r8
mov    %ebx,%edi
mov    $0x16,%ecx
mov    %rax,%r9
call   1060 <fprintf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day04/time.c\00"
@.str.2 = [5 x i8] c"time\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.3 = [6 x i8] c"t=%d\0A\00"
@.str.4 = [11 x i8] c"return=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca [27 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [27 x i8]* %3 to i8*
%6 = call i32 @time(i32* null)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 -1, %7
br i1 %8, label %9, label %18
9: ; preds = %0
br label %10
10: ; preds = %9
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %0
%19 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %19, %struct.tm** %2
br label %20
20: ; preds = %18, %20
%21 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 27)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = call i32 @time(i32* null)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %28, %struct.tm** %2
%29 = load %struct.tm*, %struct.tm** %2
%30 = call i32 @mktime(%struct.tm* %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = call i32 @sleep(i32 1)
br label %20
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day04/time.c\00"
@.str.2 = [5 x i8] c"time\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.3 = [6 x i8] c"t=%d\0A\00"
@.str.4 = [11 x i8] c"return=%d\0A\00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call %struct.tm* @localtime(i32* %2)
br label %16
16: ; preds = %16, %14
%17 = call i32 @memset(i8* %3, i32 0, i32 27)
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = call i32 @time(i32* null)
store i32 %20, i32* %2
%21 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = call %struct.tm* @localtime(i32* %2)
%23 = call i32 @mktime(%struct.tm* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = call i32 @sleep(i32 1)
br label %16
}