#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 stat {
  scalar_t__ st_mtime;
};

/* Variables and functions */
int PATH_MAX;
char *ctime(scalar_t__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
time_t getPlanetTime(const char *tile_dir) {
  static time_t last_check;
  static time_t planet_timestamp;
  time_t now = time(NULL);
  struct stat buf;
  char filename[PATH_MAX];
  snprintf(filename, PATH_MAX - 1, "%s/%s", tile_dir,
           "/planet-import-complete");
  if (now < last_check + 300)
    return planet_timestamp;
  last_check = now;
  if (stat(filename, &buf)) {
    fprintf(stderr, "Planet timestamp file (%s) is missing\n", filename);
    planet_timestamp = now - 3 * 24 * 60 * 60;
  } else {
    if (buf.st_mtime != planet_timestamp) {
      printf("Planet file updated at %s", ctime(&buf.st_mtime));
      planet_timestamp = buf.st_mtime;
    }
  }
  return planet_timestamp;
}


x86 assembly (clang, -O0):
<getPlanetTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rcx
lea    0xe44(%rip),%rdx
lea    0xe43(%rip),%r8
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    0x2e85(%rip),%rcx
add    $0x12c,%rcx
cmp    %rcx,%rax
jge    11fa <getPlanetTime+0x9a>
mov    0x2e76(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1296 <getPlanetTime+0x136>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %rax,0x2e4f(%rip)
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     124b <getPlanetTime+0xeb>
mov    -0x40(%rbp),%rdx
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rax
sub    $0x3f480,%rax
mov    %rax,0x2e1a(%rip)
jmp    1284 <getPlanetTime+0x124>
mov    -0x20(%rbp),%rax
cmp    0x2e0a(%rip),%rax
je     127f <getPlanetTime+0x11f>
lea    -0x20(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,0x2de1(%rip)
jmp    1284 <getPlanetTime+0x124>
mov    0x2dd5(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPlanetTime>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
xor    %edi,%edi
call   1080 <time@plt>
mov    %rax,%r14
mov    %rsp,%r12
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
add    $0xffffffff,%esi
lea    0xe5b(%rip),%rdx
lea    0xe5a(%rip),%r8
mov    %rbx,%rdi
mov    %r15,%rcx
call   1050 <snprintf@plt>
mov    $0x12c,%eax
add    0x2e95(%rip),%rax
cmp    %rax,%r14
jge    11d1 <getPlanetTime+0x71>
mov    0x2e91(%rip),%r14
jmp    123a <getPlanetTime+0xda>
mov    %r14,0x2e80(%rip)
lea    -0x28(%rbp),%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
test   %rax,%rax
je     120a <getPlanetTime+0xaa>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
add    $0xfffffffffffc0b80,%r14
jmp    1233 <getPlanetTime+0xd3>
mov    -0x28(%rbp),%r14
cmp    0x2e4b(%rip),%r14
je     123a <getPlanetTime+0xda>
lea    -0x28(%rbp),%rdi
call   1030 <ctime@plt>
lea    0xe1e(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    -0x28(%rbp),%r14
mov    %r14,0x2e26(%rip)
mov    %r12,%rsp
mov    %r14,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@getPlanetTime.last_check = internal global i64 0
@getPlanetTime.planet_timestamp = internal global i64 0
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [24 x i8] c"/planet-import-complete\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Planet timestamp file (%s) is missing\0A\00"
@.str.3 = [26 x i8] c"Planet file updated at %s\00"
define i64 @getPlanetTime(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = call i64 @time(i32* null)
store i64 %9, i64* %4
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* @PATH_MAX
%15 = sub nsw i32 %14, 1
%16 = load i8*, i8** %3
%17 = call i32 @snprintf(i8* %13, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%18 = load i64, i64* %4
%19 = load i64, i64* @getPlanetTime.last_check
%20 = add nsw i64 %19, 300
%21 = icmp slt i64 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = load i64, i64* @getPlanetTime.planet_timestamp
store i64 %23, i64* %2
store i32 1, i32* %8
br label %47
24: ; preds = %1
%25 = load i64, i64* %4
store i64 %25, i64* @getPlanetTime.last_check
%26 = call i64 @stat(i8* %13, %struct.stat* %5)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%31 = load i64, i64* %4
%32 = sub nsw i64 %31, 259200
store i64 %32, i64* @getPlanetTime.planet_timestamp
br label %45
33: ; preds = %24
%34 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* @getPlanetTime.planet_timestamp
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%40 = call i8* @ctime(i64* %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%43 = load i64, i64* %42
store i64 %43, i64* @getPlanetTime.planet_timestamp
br label %44
44: ; preds = %38, %33
br label %45
45: ; preds = %44, %28
%46 = load i64, i64* @getPlanetTime.planet_timestamp
store i64 %46, i64* %2
store i32 1, i32* %8
br label %47
47: ; preds = %45, %22
%48 = load i8*, i8** %6
%49 = load i64, i64* %2
ret i64 %49
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@getPlanetTime.last_check = internal unnamed_addr global i64 0
@getPlanetTime.planet_timestamp = internal unnamed_addr global i64 0
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [24 x i8] c"/planet-import-complete\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"Planet timestamp file (%s) is missing\0A\00"
@.str.3 = [26 x i8] c"Planet file updated at %s\00"
define i64 @getPlanetTime(i8* %0) {
%2 = alloca %struct.stat
%3 = tail call i64 @time(i32* null)
%4 = bitcast %struct.stat* %2 to i8*
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @PATH_MAX
%10 = add nsw i32 %9, -1
%11 = call i32 @snprintf(i8* %8, i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = load i64, i64* @getPlanetTime.last_check
%13 = add nsw i64 %12, 300
%14 = icmp slt i64 %3, %13
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i64, i64* @getPlanetTime.planet_timestamp
br label %33
17: ; preds = %1
store i64 %3, i64* @getPlanetTime.last_check
%18 = call i64 @stat(i8* %8, %struct.stat* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%23 = add nsw i64 %3, -259200
store i64 %23, i64* @getPlanetTime.planet_timestamp
br label %33
24: ; preds = %17
%25 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @getPlanetTime.planet_timestamp
%28 = icmp eq i64 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = call i8* @ctime(i64* %25)
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i64, i64* %25
store i64 %32, i64* @getPlanetTime.planet_timestamp
br label %33
33: ; preds = %15, %20, %29, %24
%34 = phi i64 [ %16, %15 ], [ %23, %20 ], [ %32, %29 ], [ %26, %24 ]
ret i64 %34
}