#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ isdigit(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write_dig(int);
int main(int argc, char *argv[]) {
  FILE *file;
  int val;
  file = fopen(
      "/sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/brightness",
      "r");
  if (file == NULL) {
    fprintf(stderr, "Can't open dev file!\n");
    exit(EXIT_FAILURE);
  }
  fscanf(file, "%d", &val);
  int fc;
  if (argc == 1) {
    printf("Value:%d\n", val);
  } else if (argc == 2) {
    fc = (int)*argv[1];
    if (isdigit(fc)) {
      fc = fc - '0';
      if (fc >= 0 & fc <= 3) {
        write_dig(fc);
      }
    } else if (fc == '+') {
      if (val < 3)
        val++;
      write_dig(val);
    } else if (fc == '-') {
      if (val > 0)
        val--;
      write_dig(val);
    }
  }
  exit(EXIT_SUCCESS);
}


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)
lea    0xe73(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <main+0x5b>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <fscanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11fd <main+0x8d>
mov    -0x1c(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
jmp    12c4 <main+0x154>
cmpl   $0x2,-0x8(%rbp)
jne    12bf <main+0x14f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1261 <main+0xf1>
mov    -0x20(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x3,-0x20(%rbp)
setle  %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     125c <main+0xec>
mov    -0x20(%rbp),%edi
call   1040 <write_dig@plt>
jmp    12ba <main+0x14a>
cmpl   $0x2b,-0x20(%rbp)
jne    128b <main+0x11b>
cmpl   $0x3,-0x1c(%rbp)
jge    127e <main+0x10e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <write_dig@plt>
jmp    12b5 <main+0x145>
cmpl   $0x2d,-0x20(%rbp)
jne    12b0 <main+0x140>
cmpl   $0x0,-0x1c(%rbp)
jle    12a8 <main+0x138>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <write_dig@plt>
jmp    12b5 <main+0x145>
jmp    12ba <main+0x14a>
jmp    12bf <main+0x14f>
jmp    12c4 <main+0x154>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe81(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xea4(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x2,%ebp
je     11e3 <main+0x73>
cmp    $0x1,%ebp
jne    1231 <main+0xc1>
mov    0x4(%rsp),%esi
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
jmp    1231 <main+0xc1>
mov    0x8(%rbx),%rax
movsbl (%rax),%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    120e <main+0x9e>
cmp    $0x2d,%bl
je     121d <main+0xad>
cmp    $0x2b,%bl
jne    1231 <main+0xc1>
mov    0x4(%rsp),%edi
cmp    $0x2,%edi
jg     122c <main+0xbc>
add    $0x1,%edi
jmp    1228 <main+0xb8>
mov    %ebx,%eax
and    $0xfc,%al
cmp    $0x30,%al
jne    1231 <main+0xc1>
add    $0xffffffd0,%ebx
mov    %ebx,%edi
jmp    122c <main+0xbc>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    122c <main+0xbc>
add    $0xffffffff,%edi
mov    %edi,0x4(%rsp)
call   1040 <write_dig@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [70 x i8] c"/sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/brightness\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Can't open dev file!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Value:%d\0A\00"
@EXIT_SUCCESS = global i32 0
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* @fopen(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %80
25: ; preds = %17
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %79
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = call i64 @isdigit(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %28
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 48
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp sge i32 %40, 0
%42 = zext i1 %41 to i32
%43 = load i32, i32* %8
%44 = icmp sle i32 %43, 3
%45 = zext i1 %44 to i32
%46 = and i32 %42, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %37
%49 = load i32, i32* %8
%50 = call i32 @write_dig(i32 %49)
br label %51
51: ; preds = %48, %37
br label %78
52: ; preds = %28
%53 = load i32, i32* %8
%54 = icmp eq i32 %53, 43
br i1 %54, label %55, label %64
55: ; preds = %52
%56 = load i32, i32* %7
%57 = icmp slt i32 %56, 3
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %7
%63 = call i32 @write_dig(i32 %62)
br label %77
64: ; preds = %52
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, 45
br i1 %66, label %67, label %76
67: ; preds = %64
%68 = load i32, i32* %7
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32, i32* %7
%72 = add nsw i32 %71, -1
store i32 %72, i32* %7
br label %73
73: ; preds = %70, %67
%74 = load i32, i32* %7
%75 = call i32 @write_dig(i32 %74)
br label %76
76: ; preds = %73, %64
br label %77
77: ; preds = %76, %61
br label %78
78: ; preds = %77, %51
br label %79
79: ; preds = %78, %25
br label %80
80: ; preds = %79, %22
%81 = load i32, i32* @EXIT_SUCCESS
%82 = call i32 @exit(i32 %81)
unreachable
}

LLVM IR (-O2):
@.str = [70 x i8] c"/sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/brightness\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Can't open dev file!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Value:%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
switch i32 %0, label %47 [
i32 1, label %14
i32 2, label %17
]
14: ; preds = %12
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %47
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i64 @isdigit(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = and i8 %20, -4
%26 = icmp eq i8 %25, 48
br i1 %26, label %27, label %47
27: ; preds = %24
%28 = add nsw i32 %21, -48
%29 = call i32 @write_dig(i32 %28)
br label %47
30: ; preds = %17
switch i8 %20, label %47 [
i8 43, label %31
i8 45, label %39
]
31: ; preds = %30
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = add nsw i32 %32, 1
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %31
%37 = phi i32 [ %35, %34 ], [ %32, %31 ]
%38 = call i32 @write_dig(i32 %37)
br label %47
39: ; preds = %30
%40 = load i32, i32* %3
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = add nsw i32 %40, -1
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %39
%45 = phi i32 [ %43, %42 ], [ %40, %39 ]
%46 = call i32 @write_dig(i32 %45)
br label %47
47: ; preds = %30, %12, %36, %44, %24, %27, %14
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}