#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void set_backlight(char *driver, int value) {
  if (value > 0) {
    char path[1024];
    sprintf(path, "/sys/class/backlight/%s/brightness", driver);
    FILE *out = fopen(path, "w");
    if (out != NULL) {
      fprintf(out, "%d", value);
      fclose(out);
    } else {
      perror("Couldn't open /sys/class/backlight/driver/brightness");
    }
  }
}


x86 assembly (clang, -O0):
<set_backlight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11e3 <set_backlight+0x93>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11d2 <set_backlight+0x82>
mov    -0x418(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11de <set_backlight+0x8e>
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
jmp    11e3 <set_backlight+0x93>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_backlight>:
test   %esi,%esi
jle    11ad <set_backlight+0x5d>
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %rdi,%rdx
lea    0xe97(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ae <set_backlight+0x5e>
mov    %rax,%rbx
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
jmp    11a4 <set_backlight+0x54>

LLVM IR (-O0):
@.str = [35 x i8] c"/sys/class/backlight/%s/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [53 x i8] c"Couldn't open /sys/class/backlight/driver/brightness\00"
define void @set_backlight(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32*, i32** %6
%19 = load i32, i32* %4
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
br label %25
23: ; preds = %9
%24 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
br label %26
26: ; preds = %25, %2
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"/sys/class/backlight/%s/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [53 x i8] c"Couldn't open /sys/class/backlight/driver/brightness\00"
define void @set_backlight(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%12 = tail call i32 @fclose(i32* %8)
br label %15
13: ; preds = %5
%14 = tail call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
br label %16
16: ; preds = %15, %2
ret void
}