#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*/ abort();
int setbrightness(char const *, long);
int strlen(char const *);
int adjbrightness(const char *device, double pcur, long int cur, long int max,
                  double adj, int inc, const char *suf) {
  switch (strlen(suf)) {
  case 2:
    pcur = adj * pcur / 100 + pcur * inc;
    cur = (long int)(pcur * (double)max + (double)0.5f);
    break;
  case 1:
    pcur = adj / 100 + pcur * inc;
    cur = (long int)(pcur * (double)max + (double)0.5f);
    break;
  case 0:
    cur = (long int)adj + cur * inc;
    break;
  default:
    abort();
  }
  cur = cur < 0 ? 0 : cur < max ? cur : max;
  return setbrightness(device, cur);
}


x86 assembly (clang, -O0):
<adjbrightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
test   %eax,%eax
je     1239 <adjbrightness+0x109>
jmp    1170 <adjbrightness+0x40>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     11e8 <adjbrightness+0xb8>
jmp    1181 <adjbrightness+0x51>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
jne    1257 <adjbrightness+0x127>
jmp    1192 <adjbrightness+0x62>
movsd  -0x28(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe64(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
jmp    125e <adjbrightness+0x12e>
movsd  -0x28(%rbp),%xmm1
movsd  0xe13(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
jmp    125e <adjbrightness+0x12e>
cvttsd2si -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    125e <adjbrightness+0x12e>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x18(%rbp)
jge    1274 <adjbrightness+0x144>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    129f <adjbrightness+0x16f>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    128f <adjbrightness+0x15f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1297 <adjbrightness+0x167>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <setbrightness@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjbrightness>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
movsd  %xmm1,0x8(%rsp)
mov    %rdx,%rbx
mov    %rsi,%r15
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%r14
mov    %r8,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11ad <adjbrightness+0x7d>
cmp    $0x1,%eax
je     11c0 <adjbrightness+0x90>
cmp    $0x2,%eax
jne    121e <adjbrightness+0xee>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm1
divsd  0xe7d(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe62(%rip),%xmm1
cvttsd2si %xmm1,%rax
jmp    11fc <adjbrightness+0xcc>
cvttsd2si 0x8(%rsp),%rcx
movslq %ebp,%rax
imul   %r15,%rax
add    %rcx,%rax
jmp    11fc <adjbrightness+0xcc>
movsd  0x8(%rsp),%xmm1
divsd  0xe32(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mulsd  %xmm2,%xmm0
addsd  0xe11(%rip),%xmm0
cvttsd2si %xmm0,%rax
cmp    %rbx,%rax
cmovl  %rax,%rbx
xor    %esi,%esi
test   %rax,%rax
cmovns %rbx,%rsi
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <setbrightness@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @adjbrightness(i8* %0, double %1, i64 %2, i64 %3, double %4, i32 %5, i8* %6) {
%8 = alloca i8*
%9 = alloca double
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %8
store double %1, double* %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store double %4, double* %12
store i32 %5, i32* %13
store i8* %6, i8** %14
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
switch i32 %16, label %51 [
i32 2, label %17
i32 1, label %31
i32 0, label %43
]
17: ; preds = %7
%18 = load double, double* %12
%19 = load double, double* %9
%20 = fmul double %18, %19
%21 = fdiv double %20, 1.000000e+02
%22 = load double, double* %9
%23 = load i32, i32* %13
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double %22, double %24, double %21)
store double %25, double* %9
%26 = load double, double* %9
%27 = load i64, i64* %11
%28 = sitofp i64 %27 to double
%29 = call double @llvm.fmuladd.f64(double %26, double %28, double 5.000000e-01)
%30 = fptosi double %29 to i64
store i64 %30, i64* %10
br label %53
31: ; preds = %7
%32 = load double, double* %12
%33 = fdiv double %32, 1.000000e+02
%34 = load double, double* %9
%35 = load i32, i32* %13
%36 = sitofp i32 %35 to double
%37 = call double @llvm.fmuladd.f64(double %34, double %36, double %33)
store double %37, double* %9
%38 = load double, double* %9
%39 = load i64, i64* %11
%40 = sitofp i64 %39 to double
%41 = call double @llvm.fmuladd.f64(double %38, double %40, double 5.000000e-01)
%42 = fptosi double %41 to i64
store i64 %42, i64* %10
br label %53
43: ; preds = %7
%44 = load double, double* %12
%45 = fptosi double %44 to i64
%46 = load i64, i64* %10
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = mul nsw i64 %46, %48
%50 = add nsw i64 %45, %49
store i64 %50, i64* %10
br label %53
51: ; preds = %7
%52 = call i32 (...) @abort()
unreachable
53: ; preds = %43, %31, %17
%54 = load i64, i64* %10
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
br label %67
57: ; preds = %53
%58 = load i64, i64* %10
%59 = load i64, i64* %11
%60 = icmp slt i64 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = load i64, i64* %10
br label %65
63: ; preds = %57
%64 = load i64, i64* %11
br label %65
65: ; preds = %63, %61
%66 = phi i64 [ %62, %61 ], [ %64, %63 ]
br label %67
67: ; preds = %65, %56
%68 = phi i64 [ 0, %56 ], [ %66, %65 ]
store i64 %68, i64* %10
%69 = load i8*, i8** %8
%70 = load i64, i64* %10
%71 = call i32 @setbrightness(i8* %69, i64 %70)
ret i32 %71
}

LLVM IR (-O2):
define i32 @adjbrightness(i8* %0, double %1, i64 %2, i64 %3, double %4, i32 %5, i8* %6) {
%8 = tail call i32 @strlen(i8* %6)
switch i32 %8, label %29 [
i32 2, label %9
i32 1, label %17
i32 0, label %24
]
9: ; preds = %7
%10 = fmul double %1, %4
%11 = fdiv double %10, 1.000000e+02
%12 = sitofp i32 %5 to double
%13 = tail call double @llvm.fmuladd.f64(double %1, double %12, double %11)
%14 = sitofp i64 %3 to double
%15 = tail call double @llvm.fmuladd.f64(double %13, double %14, double 5.000000e-01)
%16 = fptosi double %15 to i64
br label %31
17: ; preds = %7
%18 = fdiv double %4, 1.000000e+02
%19 = sitofp i32 %5 to double
%20 = tail call double @llvm.fmuladd.f64(double %1, double %19, double %18)
%21 = sitofp i64 %3 to double
%22 = tail call double @llvm.fmuladd.f64(double %20, double %21, double 5.000000e-01)
%23 = fptosi double %22 to i64
br label %31
24: ; preds = %7
%25 = fptosi double %4 to i64
%26 = sext i32 %5 to i64
%27 = mul nsw i64 %26, %2
%28 = add nsw i64 %27, %25
br label %31
29: ; preds = %7
%30 = tail call i32 (...) @abort()
unreachable
31: ; preds = %24, %17, %9
%32 = phi i64 [ %28, %24 ], [ %23, %17 ], [ %16, %9 ]
%33 = icmp slt i64 %32, 0
%34 = icmp slt i64 %32, %3
%35 = select i1 %34, i64 %32, i64 %3
%36 = select i1 %33, i64 0, i64 %35
%37 = tail call i32 @setbrightness(i8* %0, i64 %36)
ret i32 %37
}