#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ *fopen(char *, char *);
int get_brightness();
int get_power();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ set_brightness(int);
int /*<<< orphan*/ set_power(int);
scalar_t__ strcmp(char *, char *);
int usage(char **);
int main(int argc, char *argv[]) {
  if (argc != 2)
    return usage(argv);
  FILE *brightness_file;
  FILE *power_file;
  power_file = fopen("/sys/class/backlight/rpi_backlight/bl_power", "r+");
  if (power_file == NULL) {
    printf("ERROR: '%s' does not exist/insufficient permissions.\n",
           "/sys/class/backlight/rpi_backlight/bl_power");
    return EXIT_FAILURE;
  }
  brightness_file =
      fopen("/sys/class/backlight/rpi_backlight/brightness", "r+");
  if (brightness_file == NULL) {
    printf("ERROR: '%s' does not exist/insufficient permissions.\n",
           "/sys/class/backlight/rpi_backlight/brightness");
    return EXIT_FAILURE;
  }
  int brightness_value = get_brightness();
  int power_value = get_power();
  if (strcmp(argv[1], "up") == 0) {
    brightness_value += 15;
  } else if (strcmp(argv[1], "down") == 0) {
    brightness_value -= 15;
  } else if (strcmp(argv[1], "max") == 0) {
    brightness_value = 180;
  } else if (strcmp(argv[1], "min") == 0) {
    brightness_value = 30;
  } else if (strcmp(argv[1], "on") == 0) {
    power_value = 0;
  } else if (strcmp(argv[1], "off") == 0) {
    power_value = 1;
  } else {
    return usage(argv);
  }
  set_brightness(brightness_value);
  set_power(power_value);
  return EXIT_SUCCESS;
}


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)
je     11b1 <main+0x31>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1397 <main+0x217>
lea    0xe48(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f7 <main+0x77>
lea    0xe55(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   1030 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1397 <main+0x217>
lea    0xe67(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123d <main+0xbd>
lea    0xe0f(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1030 <printf@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1397 <main+0x217>
mov    $0x0,%al
call   10a0 <get_brightness@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <get_power@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe33(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    127d <main+0xfd>
mov    -0x24(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x24(%rbp)
jmp    137b <main+0x1fb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <main+0x129>
mov    -0x24(%rbp),%eax
sub    $0xf,%eax
mov    %eax,-0x24(%rbp)
jmp    1376 <main+0x1f6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12d3 <main+0x153>
movl   $0xb4,-0x24(%rbp)
jmp    1371 <main+0x1f1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12fd <main+0x17d>
movl   $0x1e,-0x24(%rbp)
jmp    136c <main+0x1ec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd97(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1327 <main+0x1a7>
movl   $0x0,-0x28(%rbp)
jmp    1367 <main+0x1e7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd70(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1351 <main+0x1d1>
movl   $0x1,-0x28(%rbp)
jmp    1362 <main+0x1e2>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1397 <main+0x217>
jmp    1367 <main+0x1e7>
jmp    136c <main+0x1ec>
jmp    1371 <main+0x1f1>
jmp    1376 <main+0x1f6>
jmp    137b <main+0x1fb>
mov    -0x24(%rbp),%edi
call   1070 <set_brightness@plt>
mov    -0x28(%rbp),%edi
call   1090 <set_power@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1265 <main+0xe5>
lea    0xe69(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1271 <main+0xf1>
lea    0xeb2(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1281 <main+0x101>
xor    %eax,%eax
call   10a0 <get_brightness@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <get_power@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
lea    0xead(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     129d <main+0x11d>
mov    0x8(%rbx),%rdi
lea    0xe97(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12a2 <main+0x122>
mov    0x8(%rbx),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12a7 <main+0x127>
mov    0x8(%rbx),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12ae <main+0x12e>
mov    0x8(%rbx),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12b5 <main+0x135>
mov    0x8(%rbx),%rdi
lea    0xe4b(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12ba <main+0x13a>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <usage@plt>
lea    0xdb7(%rip),%rdi
lea    0xd81(%rip),%rsi
jmp    128f <main+0x10f>
lea    0xda7(%rip),%rdi
lea    0xdd6(%rip),%rsi
call   1030 <printf@plt>
mov    0x2d45(%rip),%rax
jmp    12d6 <main+0x156>
add    $0xf,%ebp
jmp    12c0 <main+0x140>
add    $0xfffffff1,%ebp
jmp    12c0 <main+0x140>
mov    $0xb4,%ebp
jmp    12c0 <main+0x140>
mov    $0x1e,%ebp
jmp    12c0 <main+0x140>
xor    %r14d,%r14d
jmp    12c0 <main+0x140>
mov    $0x1,%r14d
mov    %ebp,%edi
call   1070 <set_brightness@plt>
mov    %r14d,%edi
call   1090 <set_power@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"/sys/class/backlight/rpi_backlight/bl_power\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [54 x i8] c"ERROR: '%s' does not exist/insufficient permissions.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [46 x i8] c"/sys/class/backlight/rpi_backlight/brightness\00"
@.str.4 = [3 x i8] c"up\00"
@.str.5 = [5 x i8] c"down\00"
@.str.6 = [4 x i8] c"max\00"
@.str.7 = [4 x i8] c"min\00"
@.str.8 = [3 x i8] c"on\00"
@.str.9 = [4 x i8] c"off\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
%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 ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = call i32 @usage(i8** %13)
store i32 %14, i32* %3
br label %91
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %91
22: ; preds = %15
%23 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %91
29: ; preds = %22
%30 = call i32 (...) @get_brightness()
store i32 %30, i32* %8
%31 = call i32 (...) @get_power()
store i32 %31, i32* %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 15
store i32 %39, i32* %8
br label %85
40: ; preds = %29
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 15
store i32 %48, i32* %8
br label %84
49: ; preds = %40
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %49
store i32 180, i32* %8
br label %83
56: ; preds = %49
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %56
store i32 30, i32* %8
br label %82
63: ; preds = %56
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %63
store i32 0, i32* %9
br label %81
70: ; preds = %63
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %70
store i32 1, i32* %9
br label %80
77: ; preds = %70
%78 = load i8**, i8*** %5
%79 = call i32 @usage(i8** %78)
store i32 %79, i32* %3
br label %91
80: ; preds = %76
br label %81
81: ; preds = %80, %69
br label %82
82: ; preds = %81, %62
br label %83
83: ; preds = %82, %55
br label %84
84: ; preds = %83, %46
br label %85
85: ; preds = %84, %37
%86 = load i32, i32* %8
%87 = call i32 @set_brightness(i32 %86)
%88 = load i32, i32* %9
%89 = call i32 @set_power(i32 %88)
%90 = load i32, i32* @EXIT_SUCCESS
store i32 %90, i32* %3
br label %91
91: ; preds = %85, %77, %26, %19, %12
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str = [44 x i8] c"/sys/class/backlight/rpi_backlight/bl_power\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [54 x i8] c"ERROR: '%s' does not exist/insufficient permissions.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [46 x i8] c"/sys/class/backlight/rpi_backlight/brightness\00"
@.str.4 = [3 x i8] c"up\00"
@.str.5 = [5 x i8] c"down\00"
@.str.6 = [4 x i8] c"max\00"
@.str.7 = [4 x i8] c"min\00"
@.str.8 = [3 x i8] c"on\00"
@.str.9 = [4 x i8] c"off\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @usage(i8** %1)
br label %57
6: ; preds = %2
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
br label %57
12: ; preds = %6
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
br label %57
18: ; preds = %12
%19 = tail call i32 (...) @get_brightness()
%20 = tail call i32 (...) @get_power()
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = add nsw i32 %19, 15
br label %51
27: ; preds = %18
%28 = load i8*, i8** %21
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = add nsw i32 %19, -15
br label %51
33: ; preds = %27
%34 = load i8*, i8** %21
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %51, label %37
37: ; preds = %33
%38 = load i8*, i8** %21
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %51, label %41
41: ; preds = %37
%42 = load i8*, i8** %21
%43 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %41
%46 = load i8*, i8** %21
%47 = tail call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = tail call i32 @usage(i8** %1)
br label %57
51: ; preds = %45, %41, %37, %33, %31, %25
%52 = phi i32 [ %26, %25 ], [ %32, %31 ], [ 180, %33 ], [ 30, %37 ], [ %19, %41 ], [ %19, %45 ]
%53 = phi i32 [ %20, %25 ], [ %20, %31 ], [ %20, %33 ], [ %20, %37 ], [ 0, %41 ], [ 1, %45 ]
%54 = tail call i32 @set_brightness(i32 %52)
%55 = tail call i32 @set_power(i32 %53)
%56 = load i32, i32* @EXIT_SUCCESS
br label %57
57: ; preds = %9, %15, %51, %49, %4
%58 = phi i32 [ %5, %4 ], [ %11, %9 ], [ %17, %15 ], [ %56, %51 ], [ %50, %49 ]
ret i32 %58
}