#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 convertBrightness(int);
scalar_t__ errno;
int /*<<< orphan*/ printError(char *);
int readBrightness();
int /*<<< orphan*/ setBrightness(int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strtol(char *, char **, int);
int main(int argc, char **argv) {
  errno = 0;
  char *endptr = 0;
  if (argc == 1) {
    int brightness = readBrightness();
    if (brightness == 4882) {
      setBrightness(500);
    } else {
      setBrightness(4882);
    }
  } else {
    if (strcmp(argv[1], "+") == 0) {
      int brightness = readBrightness() + 500;
      if (brightness < 4882) {
        setBrightness(brightness);
      } else {
        setBrightness(4882);
      }
    } else if (strcmp(argv[1], "-") == 0) {
      int brightness = readBrightness() - 500;
      if (brightness > 500) {
        setBrightness(brightness);
      } else {
        setBrightness(500);
      }
    } else {
      int bval = (int)strtol(argv[1], &endptr, 10);
      if (*endptr != '\0') {
        printError("Error: Invalid brightness value.\n");
        return 1;
      }
      setBrightness(convertBrightness(bval));
    }
  }
  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)
mov    0x2e63(%rip),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11cb <main+0x6b>
mov    $0x0,%al
call   1030 <readBrightness@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1312,-0x1c(%rbp)
jne    11bc <main+0x5c>
mov    $0x1f4,%edi
call   1070 <setBrightness@plt>
jmp    11c6 <main+0x66>
mov    $0x1312,%edi
call   1070 <setBrightness@plt>
jmp    12d1 <main+0x171>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1221 <main+0xc1>
mov    $0x0,%al
call   1030 <readBrightness@plt>
add    $0x1f4,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1312,-0x20(%rbp)
jge    1212 <main+0xb2>
mov    -0x20(%rbp),%edi
call   1070 <setBrightness@plt>
jmp    121c <main+0xbc>
mov    $0x1312,%edi
call   1070 <setBrightness@plt>
jmp    12cc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1277 <main+0x117>
mov    $0x0,%al
call   1030 <readBrightness@plt>
sub    $0x1f4,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1f4,-0x24(%rbp)
jle    1268 <main+0x108>
mov    -0x24(%rbp),%edi
call   1070 <setBrightness@plt>
jmp    1272 <main+0x112>
mov    $0x1f4,%edi
call   1070 <setBrightness@plt>
jmp    12c7 <main+0x167>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12b8 <main+0x158>
lea    0xd5d(%rip),%rdi
call   1080 <printError@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d8 <main+0x178>
mov    -0x28(%rbp),%edi
call   1040 <convertBrightness@plt>
mov    %eax,%edi
call   1070 <setBrightness@plt>
jmp    12cc <main+0x16c>
jmp    12d1 <main+0x171>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e74(%rip),%rax
movq   $0x0,(%rax)
movq   $0x0,0x8(%rsp)
cmp    $0x1,%edi
jne    11a4 <main+0x44>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <readBrightness@plt>
cmp    $0x1312,%eax
jne    1218 <main+0xb8>
mov    $0x1f4,%edi
call   1070 <setBrightness@plt>
jmp    1256 <main+0xf6>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe4e(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1201 <main+0xa1>
mov    0x8(%rbx),%rdi
lea    0xe3b(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1224 <main+0xc4>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1246 <main+0xe6>
lea    0xe0f(%rip),%rdi
call   1080 <printError@plt>
mov    $0x1,%ebx
jmp    1256 <main+0xf6>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <readBrightness@plt>
cmp    $0x111d,%eax
jg     1218 <main+0xb8>
add    $0x1f4,%eax
jmp    123d <main+0xdd>
mov    $0x1312,%edi
call   1070 <setBrightness@plt>
jmp    1256 <main+0xf6>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <readBrightness@plt>
cmp    $0x3e9,%eax
jl     1195 <main+0x35>
add    $0xfffffe0c,%eax
mov    %eax,%edi
call   1070 <setBrightness@plt>
jmp    1256 <main+0xf6>
mov    %eax,%edi
call   1040 <convertBrightness@plt>
mov    %eax,%edi
call   1070 <setBrightness@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [34 x i8] c"Error: Invalid brightness value.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
store i8* null, i8** %6
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = call i32 (...) @readBrightness()
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 4882
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @setBrightness(i32 500)
br label %21
19: ; preds = %13
%20 = call i32 @setBrightness(i32 4882)
br label %21
21: ; preds = %19, %17
br label %74
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %22
%29 = call i32 (...) @readBrightness()
%30 = add nsw i32 %29, 500
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 4882
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %8
%35 = call i32 @setBrightness(i32 %34)
br label %38
36: ; preds = %28
%37 = call i32 @setBrightness(i32 4882)
br label %38
38: ; preds = %36, %33
br label %73
39: ; preds = %22
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %39
%46 = call i32 (...) @readBrightness()
%47 = sub nsw i32 %46, 500
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp sgt i32 %48, 500
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32, i32* %9
%52 = call i32 @setBrightness(i32 %51)
br label %55
53: ; preds = %45
%54 = call i32 @setBrightness(i32 500)
br label %55
55: ; preds = %53, %50
br label %72
56: ; preds = %39
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strtol(i8* %59, i8** %6, i32 10)
%61 = trunc i64 %60 to i32
store i32 %61, i32* %10
%62 = load i8*, i8** %6
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = call i32 @printError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %75
68: ; preds = %56
%69 = load i32, i32* %10
%70 = call i32 @convertBrightness(i32 %69)
%71 = call i32 @setBrightness(i32 %70)
br label %72
72: ; preds = %68, %55
br label %73
73: ; preds = %72, %38
br label %74
74: ; preds = %73, %21
store i32 0, i32* %3
br label %75
75: ; preds = %74, %66
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [34 x i8] c"Error: Invalid brightness value.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
store i64 0, i64* @errno
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = tail call i32 (...) @readBrightness()
%8 = icmp eq i32 %7, 4882
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @setBrightness(i32 500)
br label %50
11: ; preds = %6
%12 = tail call i32 @setBrightness(i32 4882)
br label %50
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = tail call i32 (...) @readBrightness()
%20 = icmp slt i32 %19, 4382
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = add nsw i32 %19, 500
%23 = tail call i32 @setBrightness(i32 %22)
br label %50
24: ; preds = %18
%25 = tail call i32 @setBrightness(i32 4882)
br label %50
26: ; preds = %13
%27 = load i8*, i8** %14
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = tail call i32 (...) @readBrightness()
%32 = icmp sgt i32 %31, 1000
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = add nsw i32 %31, -500
%35 = tail call i32 @setBrightness(i32 %34)
br label %50
36: ; preds = %30
%37 = tail call i32 @setBrightness(i32 500)
br label %50
38: ; preds = %26
%39 = load i8*, i8** %14
%40 = call i64 @strtol(i8* %39, i8** %3, i32 10)
%41 = load i8*, i8** %3
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = trunc i64 %40 to i32
%46 = tail call i32 @convertBrightness(i32 %45)
%47 = tail call i32 @setBrightness(i32 %46)
br label %50
48: ; preds = %38
%49 = tail call i32 @printError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %11, %9, %24, %21, %36, %33, %44, %48
%51 = phi i32 [ 1, %48 ], [ 0, %44 ], [ 0, %33 ], [ 0, %36 ], [ 0, %21 ], [ 0, %24 ], [ 0, %9 ], [ 0, %11 ]
ret i32 %51
}