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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void power_display(void) {
  FILE *power_set;
  if (access("/sys/power/state", F_OK) != -1 &&
      access("/sys/power/state", R_OK) != -1) {
    power_set = fopen("/sys/power/state", "w+");
    char on[2] = "on";
    fwrite(on, sizeof(on[0]), sizeof(on) / sizeof(on[0]), power_set);
    fclose(power_set);
  } else {
    fprintf(stderr, "Unable to set display power state!\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<power_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11eb <power_display+0x8b>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11eb <power_display+0x8b>
lea    0xe55(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0xe76(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    -0xa(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
jmp    120a <power_display+0xaa>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_display>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11da <power_display+0x7a>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11da <power_display+0x7a>
lea    0xe60(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movw   $0x6e6f,0xe(%rsp)
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <fclose@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/sys/power/state\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.1 = [3 x i8] c"w+\00"
@__const.power_display.on = [2 x i8] c"on"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to set display power state!\0A\00"
define void @power_display() {
%1 = alloca i32*
%2 = alloca [2 x i8]
%3 = load i32, i32* @F_OK
%4 = call i32 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp ne i32 %4, -1
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = load i32, i32* @R_OK
%8 = call i32 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %1
%12 = bitcast [2 x i8]* %2 to i8*
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%14 = load i32*, i32** %1
%15 = call i32 @fwrite(i8* %13, i32 1, i32 2, i32* %14)
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
br label %22
18: ; preds = %6, %0
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/sys/power/state\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to set display power state!\0A\00"
define void @power_display() {
%1 = alloca i16
%2 = load i32, i32* @F_OK
%3 = tail call i32 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %14, label %5
5: ; preds = %0
%6 = load i32, i32* @R_OK
%7 = tail call i32 @access(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = bitcast i16* %1 to i8*
store i16 28271, i16* %1
%12 = call i32 @fwrite(i8* %11, i32 1, i32 2, i32* %10)
%13 = tail call i32 @fclose(i32* %10)
ret void
14: ; preds = %5, %0
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
}