#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_driver();
int read_backlight(char *);
int read_max_backlight(char *);
int /*<<< orphan*/ set_backlight(char *, int);
int /*<<< orphan*/ stderr;
void change_blacklight(int value, int percent_ok) {
  char *driver = get_driver();
  if (driver == NULL) {
    fprintf(stderr, "Error: /sys/class/backlight is empty.");
    return;
  }
  int max_value = read_max_backlight(driver);
  int actual = read_backlight(driver);
  if (percent_ok)
    value = (float)(max_value * value) / 100.0;
  if (value < max_value && value > 0) {
    set_backlight(driver, value);
  }
  free(driver);
}


x86 assembly (clang, -O0):
<change_blacklight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <get_driver@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <change_blacklight+0x3e>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
jmp    120d <change_blacklight+0xad>
mov    -0x10(%rbp),%rdi
call   1070 <read_max_backlight@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <read_backlight@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e2 <change_blacklight+0x82>
mov    -0x14(%rbp),%eax
imul   -0x4(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe29(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1204 <change_blacklight+0xa4>
cmpl   $0x0,-0x4(%rbp)
jle    1204 <change_blacklight+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1080 <set_backlight@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_blacklight>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <get_driver@plt>
test   %rax,%rax
je     11d0 <change_blacklight+0x70>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <read_max_backlight@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1060 <read_backlight@plt>
test   %r14d,%r14d
je     11ab <change_blacklight+0x4b>
imul   %r15d,%ebp
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm0,%xmm0
divsd  0xe59(%rip),%xmm0
cvttsd2si %xmm0,%ebp
cmp    %r15d,%ebp
jge    11be <change_blacklight+0x5e>
test   %ebp,%ebp
jle    11be <change_blacklight+0x5e>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <set_backlight@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Error: /sys/class/backlight is empty.\00"
define void @change_blacklight(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i8* (...) @get_driver()
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %43
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @read_max_backlight(i8* %15)
store i32 %16, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @read_backlight(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i32, i32* %6
%23 = load i32, i32* %3
%24 = mul nsw i32 %22, %23
%25 = sitofp i32 %24 to float
%26 = fpext float %25 to double
%27 = fdiv double %26, 1.000000e+02
%28 = fptosi double %27 to i32
store i32 %28, i32* %3
br label %29
29: ; preds = %21, %14
%30 = load i32, i32* %3
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i32, i32* %3
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i8*, i8** %5
%38 = load i32, i32* %3
%39 = call i32 @set_backlight(i8* %37, i32 %38)
br label %40
40: ; preds = %36, %33, %29
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %11
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Error: /sys/class/backlight is empty.\00"
define void @change_blacklight(i32 %0, i32 %1) {
%3 = tail call i8* (...) @get_driver()
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = tail call i32 @read_max_backlight(i8* %3)
%10 = tail call i32 @read_backlight(i8* %3)
%11 = icmp eq i32 %1, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = mul nsw i32 %9, %0
%14 = sitofp i32 %13 to float
%15 = fpext float %14 to double
%16 = fdiv double %15, 1.000000e+02
%17 = fptosi double %16 to i32
br label %18
18: ; preds = %12, %8
%19 = phi i32 [ %17, %12 ], [ %0, %8 ]
%20 = icmp slt i32 %19, %9
%21 = icmp sgt i32 %19, 0
%22 = and i1 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @set_backlight(i8* %3, i32 %19)
br label %25
25: ; preds = %23, %18
%26 = tail call i32 @free(i8* %3)
br label %27
27: ; preds = %25, %5
ret void
}