#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
void power_status(void) {
  char power_status[3];
  FILE *pwr_stat;
  if (access("/sys/power/wait_for_fb_status", F_OK) != -1 &&
      access("/sys/power/wait_for_fb_status", R_OK) != -1) {
    pwr_stat = fopen("/sys/power/wait_for_fb_status", "r");
    fscanf(pwr_stat, "%s", power_status);
    fclose(pwr_stat);
  } else {
    printf("Unable to get display power status!\n");
    fclose(pwr_stat);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<power_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11dd <power_status+0x7d>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11dd <power_status+0x7d>
lea    0xe55(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x3(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f9 <power_status+0x99>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_status>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11d1 <power_status+0x71>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11d1 <power_status+0x71>
lea    0xe60(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe6a(%rip),%rsi
lea    0xd(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/power/wait_for_fb_status\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 = [37 x i8] c"Unable to get display power status!\0A\00"
define void @power_status() {
%1 = alloca [3 x i8]
%2 = alloca i32*
%3 = load i32, i32* @F_OK
%4 = call i32 @access(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = call i32 @access(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 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 [3 x i8], [3 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 %22
17: ; preds = %6, %0
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/power/wait_for_fb_status\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 = [36 x i8] c"Unable to get display power status!\00"
define void @power_status() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = tail call i32 @access(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 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)
ret void
14: ; preds = %6, %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @fclose(i32* undef)
%17 = tail call i32 @exit(i32 0)
unreachable
}