#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 *);
scalar_t__ strcmp(char *, char *);
void wait_sleep() {
  char sleep_status[8];
  FILE *sleep_stat;
  if (access("/sys/power/wait_for_fb_sleep", F_OK) != -1 &&
      access("/sys/power/wait_for_fb_sleep", R_OK) != -1) {
    sleep_stat = fopen("/sys/power/wait_for_fb_sleep", "r");
    fscanf(sleep_stat, "%s", sleep_status);
    fclose(sleep_stat);
    while (strcmp(sleep_status, "sleeping") != 0) {
      sleep_stat = fopen("/sys/power/wait_for_fb_sleep", "r");
      fscanf(sleep_stat, "%s", sleep_status);
      fclose(sleep_stat);
    }
  } else {
    printf("Unable to get sleep status!\n");
  }
}


x86 assembly (clang, -O0):
<wait_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1230 <wait_sleep+0xd0>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1230 <wait_sleep+0xd0>
lea    0xe55(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x8(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     122b <wait_sleep+0xcb>
lea    0xe07(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rdx
lea    0xe07(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d8 <wait_sleep+0x78>
jmp    123c <wait_sleep+0xdc>
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_sleep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1253 <wait_sleep+0xf3>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1253 <wait_sleep+0xf3>
lea    0xe52(%rip),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe5b(%rip),%rsi
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1244 <wait_sleep+0xe4>
lea    0xe0b(%rip),%r14
lea    0xe21(%rip),%r15
lea    0xe1c(%rip),%r12
mov    %rsp,%rbx
lea    0xe15(%rip),%r13
nopl   (%rax)
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    1210 <wait_sleep+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd1(%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 = [29 x i8] c"/sys/power/wait_for_fb_sleep\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 = [9 x i8] c"sleeping\00"
@.str.4 = [29 x i8] c"Unable to get sleep status!\0A\00"
define void @wait_sleep() {
%1 = alloca [8 x i8]
%2 = alloca i32*
%3 = load i32, i32* @F_OK
%4 = call i32 @access(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %29
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = call i32 @access(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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 [8 x i8], [8 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 [8 x i8], [8 x i8]* %1, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 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 ([29 x i8], [29 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 [8 x i8], [8 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
br label %31
29: ; preds = %6, %0
%30 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %28
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/power/wait_for_fb_sleep\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 = [9 x i8] c"sleeping\00"
@str = [28 x i8] c"Unable to get sleep status!\00"
define void @wait_sleep() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = tail call i32 @access(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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 ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %10, %16
%17 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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 ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %16
22: ; preds = %6, %0
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %16, %10, %22
ret void
}