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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(double);
scalar_t__ strcmp(char *, char *);
void wait_wake() {
  char wake_status[5];
  FILE *wake_stat;
  if (access("/sys/power/wait_for_fb_wake", F_OK) != -1 &&
      access("/sys/power/wait_for_fb_wake", R_OK) != -1) {
    wake_stat = fopen("/sys/power/wait_for_fb_wake", "r");
    fscanf(wake_stat, "%s", wake_status);
    fclose(wake_stat);
    while (strcmp(wake_status, "awake") != 0) {
      wake_stat = fopen("/sys/power/wait_for_fb_wake", "r");
      fscanf(wake_stat, "%s", wake_status);
      fclose(wake_stat);
    }
    sleep(1.5);
  } else {
    printf("Unable to get wake status!\n");
  }
}


x86 assembly (clang, -O0):
<wait_wake>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     124d <wait_wake+0xdd>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     124d <wait_wake+0xdd>
lea    0xe4d(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x5(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x5(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     123b <wait_wake+0xcb>
lea    0xdff(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x5(%rbp),%rdx
lea    0xdfe(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e8 <wait_wake+0x78>
movsd  0xdbd(%rip),%xmm0
call   1090 <sleep@plt>
jmp    1259 <wait_wake+0xe9>
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_wake>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1280 <wait_wake+0x110>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1280 <wait_wake+0x110>
lea    0xe4a(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe52(%rip),%rsi
lea    0x3(%rsp),%r14
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1264 <wait_wake+0xf4>
lea    0xe01(%rip),%r14
lea    0xe16(%rip),%r15
lea    0xe11(%rip),%r12
lea    0x3(%rsp),%rbx
lea    0xe08(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1230 <wait_wake+0xc0>
movsd  0xd94(%rip),%xmm0
call   1090 <sleep@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda8(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"/sys/power/wait_for_fb_wake\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"awake\00"
@.str.4 = [28 x i8] c"Unable to get wake status!\0A\00"
define void @wait_wake() {
%1 = alloca [5 x i8]
%2 = alloca i32*
%3 = load i32, i32* @F_OK
%4 = call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %30
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %30
10: ; preds = %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%14 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %21, %10
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %2
%23 = load i32*, i32** %2
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%25 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
br label %17
28: ; preds = %17
%29 = call i32 @sleep(double 1.500000e+00)
br label %32
30: ; preds = %6, %0
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"/sys/power/wait_for_fb_wake\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"awake\00"
@str = [27 x i8] c"Unable to get wake status!\00"
define void @wait_wake() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %24, label %6
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = tail call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%13 = call i32 @fclose(i32* %11)
%14 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %10, %16
%17 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%19 = call i32 @fclose(i32* %17)
%20 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %16, %10
%23 = call i32 @sleep(double 1.500000e+00)
br label %26
24: ; preds = %6, %0
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
ret void
}