#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 scalar_t__ time_t;
struct utimbuf {
  void *modtime;
  int /*<<< orphan*/ actime;
};
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct stat {
  scalar_t__ st_mtime;
  int /*<<< orphan*/ st_atime;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ settimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ stat(char const *, struct stat *);
void *time(int /*<<< orphan*/ *);
int /*<<< orphan*/ utime(char const *, struct utimbuf *);
int main(int argc, char *argv[]) {
  struct stat temp;
  const char *timefile = argv[0];
  time_t current_time;
  time_t time_store;
  current_time = time(NULL);
  if (current_time == ((time_t)-1))
    return 1;
  if (stat(timefile, &temp) < 0)
    return 1;
  time_store = temp.st_mtime;
  if (time_store > current_time) {
    struct timeval sys_update;
    sys_update.tv_sec = time_store;
    sys_update.tv_usec = 0;
    printf("Setting Clock.\n");
    settimeofday(&sys_update, NULL);
  } else {
    struct utimbuf time_update;
    time_update.actime = temp.st_atime;
    time_update.modtime = time(NULL);
    printf("Saving current time.\n");
    utime(timefile, &time_update);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    1195 <main+0x45>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11b8 <main+0x68>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jle    11fc <main+0xac>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <settimeofday@plt>
jmp    1228 <main+0xd8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x58(%rbp)
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1030 <utime@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    (%rsi),%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    $0x1,%r15d
cmp    $0xffffffffffffffff,%rax
je     11e3 <main+0x93>
mov    %rax,%rbx
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     11e3 <main+0x93>
mov    0x10(%rsp),%rax
cmp    %rbx,%rax
jle    11b6 <main+0x66>
mov    %rax,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
call   1070 <settimeofday@plt>
jmp    11e3 <main+0x93>
mov    0x18(%rsp),%eax
mov    %eax,0x8(%rsp)
xor    %r15d,%r15d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,(%rsp)
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <utime@plt>
mov    %r15d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
%struct.timeval = type { i64, i64 }
%struct.utimbuf = type { i8*, i32 }
@.str = [16 x i8] c"Setting Clock.\0A\00"
@.str.1 = [22 x i8] c"Saving current time.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.timeval
%11 = alloca %struct.utimbuf
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = call i8* @time(i32* null)
%16 = ptrtoint i8* %15 to i64
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
br label %47
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = call i64 @stat(i8* %21, %struct.stat* %6)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %3
br label %47
25: ; preds = %20
%26 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%27 = load i64, i64* %26
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = load i64, i64* %8
%30 = icmp sgt i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i64, i64* %9
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i64 %32, i64* %33
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
store i64 0, i64* %34
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @settimeofday(%struct.timeval* %10, i32* null)
br label %46
37: ; preds = %25
%38 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %11, i32 0, i32 1
store i32 %39, i32* %40
%41 = call i8* @time(i32* null)
%42 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %11, i32 0, i32 0
store i8* %41, i8** %42
%43 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%44 = load i8*, i8** %7
%45 = call i32 @utime(i8* %44, %struct.utimbuf* %11)
br label %46
46: ; preds = %37, %31
store i32 0, i32* %3
br label %47
47: ; preds = %46, %24, %19
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
%struct.timeval = type { i64, i64 }
%struct.utimbuf = type { i8*, i32 }
@str = [21 x i8] c"Saving current time.\00"
@str.2 = [15 x i8] c"Setting Clock.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.timeval
%5 = alloca %struct.utimbuf
%6 = bitcast %struct.stat* %3 to i8*
%7 = load i8*, i8** %1
%8 = tail call i8* @time(i32* null)
%9 = ptrtoint i8* %8 to i64
%10 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %10, label %33, label %11
11: ; preds = %2
%12 = call i64 @stat(i8* %7, %struct.stat* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %33, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i64, i64* %15
%17 = icmp sgt i64 %16, %9
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = bitcast %struct.timeval* %4 to i8*
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 %16, i64* %20
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i64 0, i64* %21
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
%23 = call i32 @settimeofday(%struct.timeval* %4, i32* null)
br label %33
24: ; preds = %14
%25 = bitcast %struct.utimbuf* %5 to i8*
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %5, i64 0, i32 1
store i32 %27, i32* %28
%29 = call i8* @time(i32* null)
%30 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %5, i64 0, i32 0
store i8* %29, i8** %30
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%32 = call i32 @utime(i8* %7, %struct.utimbuf* %5)
br label %33
33: ; preds = %18, %24, %11, %2
%34 = phi i32 [ 1, %2 ], [ 1, %11 ], [ 0, %24 ], [ 0, %18 ]
ret i32 %34
}