#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *open_driver_file(char *, char const *, char *);
scalar_t__ read_bl_power(char const *);
int /*<<< orphan*/ set_bl_power(char const *, int);
void set_backlight(const char *driver, int value) {
  if (value > 0) {
    FILE *out = open_driver_file("brightness", driver, "w");
    if (out != NULL) {
      fprintf(out, "%d", value);
      fclose(out);
    }
    if (read_bl_power(driver) > 0)
      set_bl_power(driver, 0);
  } else {
    set_bl_power(driver, 4);
  }
}


x86 assembly (clang, -O0):
<set_backlight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11ce <set_backlight+0x7e>
mov    -0x8(%rbp),%rsi
lea    0xe8c(%rip),%rdi
lea    0xe90(%rip),%rdx
call   1040 <open_driver_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ab <set_backlight+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe70(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1030 <read_bl_power@plt>
cmp    $0x0,%rax
jle    11c9 <set_backlight+0x79>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <set_bl_power@plt>
jmp    11dc <set_backlight+0x8c>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1060 <set_bl_power@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_backlight>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
jle    11a8 <set_backlight+0x58>
mov    %esi,%ebp
lea    0xe9c(%rip),%rdi
lea    0xea0(%rip),%rdx
mov    %r14,%rsi
call   1040 <open_driver_file@plt>
test   %rax,%rax
je     1194 <set_backlight+0x44>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <read_bl_power@plt>
xor    %esi,%esi
test   %rax,%rax
jg     11ad <set_backlight+0x5d>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x4,%esi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <set_bl_power@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @set_backlight(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32* @open_driver_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32*, i32** %5
%15 = load i32, i32* %4
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %5
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %13, %8
%20 = load i8*, i8** %3
%21 = call i64 @read_bl_power(i8* %20)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %3
%25 = call i32 @set_bl_power(i8* %24, i32 0)
br label %26
26: ; preds = %23, %19
br label %30
27: ; preds = %2
%28 = load i8*, i8** %3
%29 = call i32 @set_bl_power(i8* %28, i32 4)
br label %30
30: ; preds = %27, %26
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @set_backlight(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = tail call i32* @open_driver_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%9 = tail call i32 @fclose(i32* %5)
br label %10
10: ; preds = %7, %4
%11 = tail call i64 @read_bl_power(i8* %0)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2, %10
%14 = phi i32 [ 0, %10 ], [ 4, %2 ]
%15 = tail call i32 @set_bl_power(i8* %0, i32 %14)
br label %16
16: ; preds = %13, %10
ret void
}