#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ isint(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strcmp(char *, char *);
int toint(char *);
int main(int argc, char *argv[]) {
  FILE *fi, *fo;
  int bright, maxbright;
  if (argc < 2) {
    fi = fopen("/sys/class/backlight/intel_backlight/brightness", "r");
    fscanf(fi, "%d", &bright);
    fclose(fi);
    printf("%d\n", bright);
    return bright;
  }
  if (argc == 2) {
    fi = fopen("/sys/class/backlight/intel_backlight/max_brightness", "r");
    fscanf(fi, "%d", &maxbright);
    fclose(fi);
    if (0 == strcmp(argv[1], "-m")) {
      printf("%d\n", maxbright);
      return maxbright;
    } else if (0 == isint(argv[1])) {
      bright = toint(argv[1]);
      if (bright > maxbright)
        return -1;
      fo = fopen("/sys/class/backlight/intel_backlight/brightness", "w");
      fprintf(fo, "%d", bright);
      fclose(fo);
      printf("%d\n", bright);
      return bright;
    } else {
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ee <main+0x6e>
lea    0xe59(%rip),%rdi
lea    0xe82(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x18b>
cmpl   $0x2,-0x8(%rbp)
jne    1304 <main+0x184>
lea    0xe3a(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1268 <main+0xe8>
mov    -0x28(%rbp),%esi
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <isint@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12f8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <toint@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    12ab <main+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    130b <main+0x18b>
lea    0xd4e(%rip),%rdi
lea    0xdb7(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd62(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xd4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x18b>
movl   $0x0,-0x4(%rbp)
jmp    130b <main+0x18b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     11d8 <main+0x58>
lea    0xe6c(%rip),%rdi
lea    0xe95(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%ebx
jmp    12aa <main+0x12a>
xor    %ebx,%ebx
cmp    $0x2,%edi
jne    12aa <main+0x12a>
mov    %rsi,%r14
lea    0xe4c(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
lea    0xe2f(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x8(%r14),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1296 <main+0x116>
mov    0x8(%r14),%rdi
call   1080 <isint@plt>
test   %rax,%rax
jne    12aa <main+0x12a>
mov    0x8(%r14),%rdi
call   1090 <toint@plt>
mov    %eax,0xc(%rsp)
mov    $0xffffffff,%ebx
cmp    0x8(%rsp),%eax
jg     12aa <main+0x12a>
mov    %eax,%ebp
lea    0xda4(%rip),%rdi
lea    0xe0d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xdc0(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xdaa(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebp,%ebx
jmp    12aa <main+0x12a>
mov    0x8(%rsp),%esi
lea    0xd94(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"/sys/class/backlight/intel_backlight/brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [52 x i8] c"/sys/class/backlight/intel_backlight/max_brightness\00"
@.str.5 = [3 x i8] c"-m\00"
@.str.6 = [2 x i8] c"w\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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* %8
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %8
store i32 %20, i32* %3
br label %66
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %65
24: ; preds = %21
%25 = call i32* @fopen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 0, %33
br i1 %34, label %35, label %39
35: ; preds = %24
%36 = load i32, i32* %9
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %9
store i32 %38, i32* %3
br label %66
39: ; preds = %24
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i64 @isint(i8* %42)
%44 = icmp eq i64 0, %43
br i1 %44, label %45, label %64
45: ; preds = %39
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @toint(i8* %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %45
store i32 -1, i32* %3
br label %66
54: ; preds = %45
%55 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %55, i32** %7
%56 = load i32*, i32** %7
%57 = load i32, i32* %8
%58 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %8
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %8
store i32 %63, i32* %3
br label %66
64: ; preds = %39
store i32 0, i32* %3
br label %66
65: ; preds = %21
store i32 0, i32* %3
br label %66
66: ; preds = %65, %64, %54, %53, %35, %12
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [48 x i8] c"/sys/class/backlight/intel_backlight/brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [52 x i8] c"/sys/class/backlight/intel_backlight/max_brightness\00"
@.str.5 = [3 x i8] c"-m\00"
@.str.6 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = call i32 @fclose(i32* %9)
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
br label %43
15: ; preds = %2
%16 = icmp eq i32 %0, 2
br i1 %16, label %17, label %43
17: ; preds = %15
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%20 = call i32 @fclose(i32* %18)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %4
br label %43
29: ; preds = %17
%30 = load i8*, i8** %21
%31 = call i64 @isint(i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load i8*, i8** %21
%35 = call i32 @toint(i8* %34)
store i32 %35, i32* %3
%36 = load i32, i32* %4
%37 = icmp sgt i32 %35, %36
br i1 %37, label %43, label %38
38: ; preds = %33
%39 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%41 = call i32 @fclose(i32* %39)
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %43
43: ; preds = %15, %29, %33, %38, %25, %8
%44 = phi i32 [ %14, %8 ], [ %28, %25 ], [ %35, %38 ], [ -1, %33 ], [ 0, %29 ], [ 0, %15 ]
ret i32 %44
}