#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ LONG_MAX;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, scalar_t__ *);
time_t read_e2_timers(time_t curTime) {
  char line[12];
  time_t recordTime = LONG_MAX;
  FILE *fd = fopen("/proc/stb/fp/wakeup_time", "r");
  printf("Getting enigma2 wakeup time");
  if (fd > 0) {
    fgets(line, 11, fd);
    sscanf(line, "%ld", &recordTime);
    if (recordTime <= curTime) {
      recordTime = LONG_MAX;
      printf(" - Got timer but in the past (ignoring)\n");
    } else
      printf(" - Done\n");
  } else
    printf(" - Error reading %s\n", "/proc/stb/fp/wakeup_time");
  return recordTime;
}


x86 assembly (clang, -O0):
<read_e2_timers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9f(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
jbe    11f2 <read_e2_timers+0xb2>
lea    -0x14(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xb,%esi
call   1040 <fgets@plt>
lea    -0x14(%rbp),%rdi
lea    0xe90(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     11df <read_e2_timers+0x9f>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <read_e2_timers+0xad>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1207 <read_e2_timers+0xc7>
lea    0xe74(%rip),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_e2_timers>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    0x2e7b(%rip),%r12
mov    (%r12),%rax
mov    %rax,(%rsp)
lea    0xe8c(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
je     11cc <read_e2_timers+0x7c>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
mov    $0xb,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
lea    0xe85(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rdi
call   1060 <sscanf@plt>
cmp    %r14,(%rsp)
jle    11e3 <read_e2_timers+0x93>
lea    0xe86(%rip),%rdi
jmp    11f2 <read_e2_timers+0xa2>
lea    0xe68(%rip),%rdi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f7 <read_e2_timers+0xa7>
mov    (%r12),%rax
mov    %rax,(%rsp)
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@.str = [25 x i8] c"/proc/stb/fp/wakeup_time\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Getting enigma2 wakeup time\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [41 x i8] c" - Got timer but in the past (ignoring)\0A\00"
@.str.5 = [9 x i8] c" - Done\0A\00"
@.str.6 = [21 x i8] c" - Error reading %s\0A\00"
define i64 @read_e2_timers(i64 %0) {
%2 = alloca i64
%3 = alloca [12 x i8]
%4 = alloca i64
%5 = alloca i32*
store i64 %0, i64* %2
%6 = load i64, i64* @LONG_MAX
store i64 %6, i64* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32*, i32** %5
%10 = icmp ugt i32* %9, null
br i1 %10, label %11, label %26
11: ; preds = %1
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i32 @fgets(i8* %12, i32 11, i32* %13)
%15 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%17 = load i64, i64* %4
%18 = load i64, i64* %2
%19 = icmp sle i64 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i64, i64* @LONG_MAX
store i64 %21, i64* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %25
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
br label %28
26: ; preds = %1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
%29 = load i64, i64* %4
ret i64 %29
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@.str = [25 x i8] c"/proc/stb/fp/wakeup_time\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Getting enigma2 wakeup time\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.6 = [21 x i8] c" - Error reading %s\0A\00"
@str = [8 x i8] c" - Done\00"
@str.7 = [40 x i8] c" - Got timer but in the past (ignoring)\00"
define i64 @read_e2_timers(i64 %0) {
%2 = alloca [12 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = bitcast i64* %3 to i8*
%6 = load i64, i64* @LONG_MAX
store i64 %6, i64* %3
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %7, null
br i1 %9, label %20, label %10
10: ; preds = %1
%11 = call i32 @fgets(i8* %4, i32 11, i32* %7)
%12 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, %0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i64, i64* @LONG_MAX
store i64 %16, i64* %3
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.7, i64 0, i64 0))
br label %22
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %22
20: ; preds = %1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %15, %18, %20
%23 = load i64, i64* %3
ret i64 %23
}