#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*/ free(char *);
char *get_driver();
int read_max_backlight(char *);
int /*<<< orphan*/ set_backlight(char *, int);
void change_blacklight(int value, int percent_ok) {
  char *driver = get_driver();
  if (driver == NULL) {
    return;
  }
  int max_value = read_max_backlight(driver);
  if (percent_ok) {
    value = (float)(max_value * value) / 100.0;
    if (value == 0) {
      value = 1;
    }
  }
  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    1169 <change_blacklight+0x29>
jmp    11e2 <change_blacklight+0xa2>
mov    -0x10(%rbp),%rdi
call   1050 <read_max_backlight@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b7 <change_blacklight+0x77>
mov    -0x14(%rbp),%eax
imul   -0x4(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b2 <change_blacklight+0x72>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <change_blacklight+0x77>
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11d9 <change_blacklight+0x99>
cmpl   $0x0,-0x4(%rbp)
jle    11d9 <change_blacklight+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <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   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <get_driver@plt>
test   %rax,%rax
je     11a4 <change_blacklight+0x64>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <read_max_backlight@plt>
test   %r14d,%r14d
je     1186 <change_blacklight+0x46>
imul   %eax,%ebp
cvtsi2ss %ebp,%xmm0
cvtss2sd %xmm0,%xmm0
divsd  0xe88(%rip),%xmm0
cvttsd2si %xmm0,%ecx
test   %ecx,%ecx
mov    $0x1,%ebp
cmovne %ecx,%ebp
cmp    %eax,%ebp
jg     1198 <change_blacklight+0x58>
test   %ebp,%ebp
jle    1198 <change_blacklight+0x58>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <set_backlight@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @change_blacklight(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = call i8* (...) @get_driver()
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %42
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @read_max_backlight(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %6
%18 = load i32, i32* %3
%19 = mul nsw i32 %17, %18
%20 = sitofp i32 %19 to float
%21 = fpext float %20 to double
%22 = fdiv double %21, 1.000000e+02
%23 = fptosi double %22 to i32
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %16
store i32 1, i32* %3
br label %27
27: ; preds = %26, %16
br label %28
28: ; preds = %27, %11
%29 = load i32, i32* %3
%30 = load i32, i32* %6
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* %3
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i32, i32* %3
%38 = call i32 @set_backlight(i8* %36, i32 %37)
br label %39
39: ; preds = %35, %32, %28
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %39, %10
ret void
}

LLVM IR (-O2):
define void @change_blacklight(i32 %0, i32 %1) {
%3 = tail call i8* (...) @get_driver()
%4 = icmp eq i8* %3, null
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = tail call i32 @read_max_backlight(i8* %3)
%7 = icmp eq i32 %1, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = mul nsw i32 %6, %0
%10 = sitofp i32 %9 to float
%11 = fpext float %10 to double
%12 = fdiv double %11, 1.000000e+02
%13 = fptosi double %12 to i32
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 1, i32 %13
br label %16
16: ; preds = %8, %5
%17 = phi i32 [ %15, %8 ], [ %0, %5 ]
%18 = icmp sle i32 %17, %6
%19 = icmp sgt i32 %17, 0
%20 = and i1 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @set_backlight(i8* %3, i32 %17)
br label %23
23: ; preds = %21, %16
%24 = tail call i32 @free(i8* %3)
br label %25
25: ; preds = %2, %23
ret void
}