#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*/ max;
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*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void set_brightness(int brightness, int blen) {
  char max[(blen)];
  sprintf(max, "%d", brightness);
  FILE *brightness_set;
  if (access("/sys/class/backlight/panel/brightness", F_OK) != -1 &&
      access("/sys/class/backlight/panel/brightness", R_OK) != -1) {
    brightness_set = fopen("/sys/class/backlight/panel/brightness", "w+");
    fwrite(max, sizeof(max[0]), sizeof(max) / sizeof(max[0]), brightness_set);
    fclose(brightness_set);
  } else if (access("/sys/class/leds/lcd-backlight/brightness", F_OK) != -1 &&
             access("/sys/class/leds/lcd-backlight/brightness", R_OK) != -1) {
    brightness_set = fopen("/sys/class/leds/lcd-backlight/brightness", "w+");
    fwrite(max, sizeof(max[0]), sizeof(max) / sizeof(max[0]), brightness_set);
    fclose(brightness_set);
  } else {
    printf("Unable to set display brightness!\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edx
lea    0xe4e(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     1237 <set_brightness+0xc7>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     1237 <set_brightness+0xc7>
lea    0xe09(%rip),%rdi
lea    0xe28(%rip),%rsi
call   1060 <fopen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,-0x20(%rbp)
shr    $0x0,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12d2 <set_brightness+0x162>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    0xde5(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     12b7 <set_brightness+0x147>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    0xdc7(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     12b7 <set_brightness+0x147>
lea    0xdb2(%rip),%rdi
lea    0xda8(%rip),%rsi
call   1060 <fopen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,-0x20(%rbp)
shr    $0x0,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12cd <set_brightness+0x15d>
lea    0xd97(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12d2 <set_brightness+0x162>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_brightness>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%edx
mov    %esi,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe66(%rip),%rsi
mov    %r15,%rdi
call   1070 <sprintf@plt>
mov    0x2e27(%rip),%r12
mov    (%r12),%esi
lea    0xe4f(%rip),%rbx
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11d7 <set_brightness+0x67>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    1205 <set_brightness+0x95>
mov    (%r12),%esi
lea    0xe4a(%rip),%rbx
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     123e <set_brightness+0xce>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     123e <set_brightness+0xce>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [38 x i8] c"/sys/class/backlight/panel/brightness\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [41 x i8] c"/sys/class/leds/lcd-backlight/brightness\00"
@.str.4 = [35 x i8] c"Unable to set display brightness!\0A\00"
define void @set_brightness(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* %3
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @F_OK
%15 = call i32 @access(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %29
17: ; preds = %2
%18 = load i32, i32* @R_OK
%19 = call i32 @access(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = udiv i64 %9, 1
%24 = trunc i64 %23 to i32
%25 = load i32*, i32** %7
%26 = call i32 @fwrite(i8* %11, i32 1, i32 %24, i32* %25)
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
br label %49
29: ; preds = %17, %2
%30 = load i32, i32* @F_OK
%31 = call i32 @access(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32, i32* @R_OK
%35 = call i32 @access(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %7
%39 = udiv i64 %9, 1
%40 = trunc i64 %39 to i32
%41 = load i32*, i32** %7
%42 = call i32 @fwrite(i8* %11, i32 1, i32 %40, i32* %41)
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
br label %48
45: ; preds = %33, %29
%46 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %37
br label %49
49: ; preds = %48, %21
%50 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [38 x i8] c"/sys/class/backlight/panel/brightness\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [41 x i8] c"/sys/class/leds/lcd-backlight/brightness\00"
@str = [34 x i8] c"Unable to set display brightness!\00"
define void @set_brightness(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @F_OK
%7 = tail call i32 @access(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @R_OK
%11 = tail call i32 @access(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %24
13: ; preds = %9, %2
%14 = load i32, i32* @F_OK
%15 = tail call i32 @access(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* @R_OK
%19 = tail call i32 @access(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17, %13
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17, %9
%25 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), %17 ]
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @fwrite(i8* %4, i32 1, i32 %1, i32* %26)
%28 = tail call i32 @fclose(i32* %26)
ret void
}