#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int read_wakeup_count() {
  int fd;
  int n;
  char buf[20];
  fd = open("/sys/power/wakeup_count", O_RDONLY);
  if (fd < 0)
    return -1;
  n = read(fd, buf, sizeof(buf) - 1);
  close(fd);
  if (n < 0)
    return -1;
  buf[n] = 0;
  return atoi(buf);
}


x86 assembly (clang, -O0):
<read_wakeup_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1176 <read_wakeup_count+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <read_wakeup_count+0x7d>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x13,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11a8 <read_wakeup_count+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <read_wakeup_count+0x7d>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_wakeup_count>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1196 <read_wakeup_count+0x56>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x13,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
test   %ebx,%ebx
js     1196 <read_wakeup_count+0x56>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/sys/power/wakeup_count\00"
@O_RDONLY = global i32 0
define i32 @read_wakeup_count() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %25
10: ; preds = %0
%11 = load i32, i32* %2
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 19)
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
store i32 -1, i32* %1
br label %25
19: ; preds = %10
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %1
br label %25
25: ; preds = %19, %18, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [24 x i8] c"/sys/power/wakeup_count\00"
@O_RDONLY = global i32 0
define i32 @read_wakeup_count() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 19)
%8 = tail call i32 @close(i32 %4)
%9 = icmp slt i32 %7, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @atoi(i8* %2)
br label %14
14: ; preds = %6, %0, %10
%15 = phi i32 [ %13, %10 ], [ -1, %0 ], [ -1, %6 ]
ret i32 %15
}