#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 uint32_t;

/* Variables and functions */
int INREG(int);
int /*<<< orphan*/ OUTREG(int, int);
int atoi(char *);
int /*<<< orphan*/ intel_get_pci_device();
int /*<<< orphan*/ intel_mmio_use_pci_bar(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  uint32_t current, max;
  intel_mmio_use_pci_bar(intel_get_pci_device());
  current = INREG(0x48254) & (0xffff);
  max = INREG(0xc8254) >> 16;
  printf("current backlight value: %d%%\n", current * 100 / max);
  if (argc > 1) {
    uint32_t v = atoi(argv[1]) * max / 100;
    if (v > max)
      v = max;
    OUTREG(0x48254, (INREG(0x48254) & ~(0xffff)) | v);
    (void)INREG(0x48254);
    printf("set backlight to %d%%\n", v * 100 / max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <intel_get_pci_device@plt>
mov    %eax,%edi
call   1050 <intel_mmio_use_pci_bar@plt>
mov    $0x48254,%edi
call   1030 <INREG@plt>
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
mov    $0xc8254,%edi
call   1030 <INREG@plt>
sar    $0x10,%eax
mov    %eax,-0x18(%rbp)
imul   $0x64,-0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%esi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1233 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
imul   -0x18(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11f4 <main+0x94>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x48254,%edi
call   1030 <INREG@plt>
mov    %eax,%esi
and    $0xffff0000,%esi
or     -0x1c(%rbp),%esi
mov    $0x48254,%edi
call   1060 <OUTREG@plt>
mov    $0x48254,%edi
call   1030 <INREG@plt>
imul   $0x64,-0x1c(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%esi
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %eax,%eax
call   1080 <intel_get_pci_device@plt>
mov    %eax,%edi
call   1050 <intel_mmio_use_pci_bar@plt>
mov    $0x48254,%edi
call   1030 <INREG@plt>
movzwl %ax,%ebp
mov    $0xc8254,%edi
call   1030 <INREG@plt>
mov    %eax,%ebx
sar    $0x10,%ebx
imul   $0x64,%ebp,%eax
xor    %edx,%edx
idiv   %ebx
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0x2,%r15d
jl     1214 <main+0xb4>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
imul   %ebx,%eax
cltq
imul   $0x51eb851f,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x25,%rbp
add    %eax,%ebp
cmp    %ebx,%ebp
cmovg  %ebx,%ebp
mov    $0x48254,%edi
call   1030 <INREG@plt>
and    $0xffff0000,%eax
or     %ebp,%eax
mov    $0x48254,%edi
mov    %eax,%esi
call   1060 <OUTREG@plt>
mov    $0x48254,%edi
call   1030 <INREG@plt>
imul   $0x64,%ebp,%eax
cltd
idiv   %ebx
lea    0xe12(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"current backlight value: %d%%\0A\00"
@.str.1 = [23 x i8] c"set backlight to %d%%\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @intel_get_pci_device()
%10 = call i32 @intel_mmio_use_pci_bar(i32 %9)
%11 = call i32 @INREG(i32 295508)
%12 = and i32 %11, 65535
store i32 %12, i32* %6
%13 = call i32 @INREG(i32 819796)
%14 = ashr i32 %13, 16
store i32 %14, i32* %7
%15 = load i32, i32* %6
%16 = mul nsw i32 %15, 100
%17 = load i32, i32* %7
%18 = sdiv i32 %16, %17
%19 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %47
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = load i32, i32* %7
%28 = mul nsw i32 %26, %27
%29 = sdiv i32 %28, 100
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = load i32, i32* %7
store i32 %34, i32* %8
br label %35
35: ; preds = %33, %22
%36 = call i32 @INREG(i32 295508)
%37 = and i32 %36, -65536
%38 = load i32, i32* %8
%39 = or i32 %37, %38
%40 = call i32 @OUTREG(i32 295508, i32 %39)
%41 = call i32 @INREG(i32 295508)
%42 = load i32, i32* %8
%43 = mul nsw i32 %42, 100
%44 = load i32, i32* %7
%45 = sdiv i32 %43, %44
%46 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %35, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"current backlight value: %d%%\0A\00"
@.str.1 = [23 x i8] c"set backlight to %d%%\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @intel_get_pci_device()
%4 = tail call i32 @intel_mmio_use_pci_bar(i32 %3)
%5 = tail call i32 @INREG(i32 295508)
%6 = and i32 %5, 65535
%7 = tail call i32 @INREG(i32 819796)
%8 = ashr i32 %7, 16
%9 = mul nuw nsw i32 %6, 100
%10 = sdiv i32 %9, %8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = mul nsw i32 %16, %8
%18 = sdiv i32 %17, 100
%19 = icmp sgt i32 %18, %8
%20 = select i1 %19, i32 %8, i32 %18
%21 = tail call i32 @INREG(i32 295508)
%22 = and i32 %21, -65536
%23 = or i32 %20, %22
%24 = tail call i32 @OUTREG(i32 295508, i32 %23)
%25 = tail call i32 @INREG(i32 295508)
%26 = mul nsw i32 %20, 100
%27 = sdiv i32 %26, %8
%28 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %13, %2
ret i32 0
}