#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 EXIT_FAILURE;
int O_TRUNC;
int O_WRONLY;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char const *);
int getopt(int, char **, char *);
int open(char const *, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ch;
  int eflg, dflg, lflg;
  int level = -1;
  char level_str[4] = "";
  int fd;
  const char *kbd_file = "/sys/class/leds/kbd_backlight/brightness";
  eflg = dflg = lflg = 0;
  while ((ch = getopt(argc, argv, "edhl:")) != -1) {
    switch (ch) {
    case 'e':
      eflg = 1;
      if (dflg || lflg) {
        print_help();
        return EXIT_FAILURE;
      }
      level = 100;
      break;
    case 'd':
      dflg = 1;
      if (eflg || lflg) {
        print_help();
        return EXIT_FAILURE;
      }
      level = 0;
      break;
    case 'l':
      lflg = 1;
      if (dflg || eflg) {
        print_help();
        return EXIT_FAILURE;
      }
      level = atoi(optarg);
      if (level < 0 || level > 100) {
        print_help();
        return EXIT_FAILURE;
      }
      break;
    case '?':
    case 'h':
    default:
      print_help();
      return EXIT_FAILURE;
    }
  }
  if (level == -1) {
    print_help();
    return EXIT_FAILURE;
  } else {
    snprintf(level_str, sizeof level_str, "%d", level);
  }
  fd = open(kbd_file, O_TRUNC | O_WRONLY);
  if (fd == -1) {
    err(1, "%s", kbd_file);
  }
  write(fd, level_str, strlen(level_str));
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0xee4(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xee6(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     134a <main+0x1aa>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x2d,%eax
ja     132d <main+0x18d>
mov    -0x40(%rbp),%rax
lea    0xdd4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1250 <main+0xb0>
cmpl   $0x0,-0x20(%rbp)
je     1268 <main+0xc8>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
movl   $0x64,-0x24(%rbp)
jmp    1345 <main+0x1a5>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    128f <main+0xef>
cmpl   $0x0,-0x20(%rbp)
je     12a7 <main+0x107>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
movl   $0x0,-0x24(%rbp)
jmp    1345 <main+0x1a5>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12ce <main+0x12e>
cmpl   $0x0,-0x18(%rbp)
je     12e6 <main+0x146>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     130b <main+0x16b>
cmpl   $0x64,-0x24(%rbp)
jle    1323 <main+0x183>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
jmp    1345 <main+0x1a5>
jmp    132d <main+0x18d>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
jmp    11ed <main+0x4d>
cmpl   $0xffffffff,-0x24(%rbp)
jne    136c <main+0x1cc>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13ee <main+0x24e>
lea    -0x28(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0x4,%esi
lea    0xd68(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
mov    0x2c28(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13c1 <main+0x221>
mov    -0x38(%rbp),%rdx
mov    $0x1,%edi
lea    0xd2e(%rip),%rsi
call   1080 <err@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r13d
movl   $0x0,0x4(%rsp)
mov    $0xffffffff,%ebx
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r15,%rsi
lea    0xe5c(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0x64,%eax
jle    1210 <main+0x80>
cmp    $0x6c,%eax
je     1230 <main+0xa0>
cmp    $0x65,%eax
jne    12eb <main+0x15b>
mov    $0x1,%r14d
mov    $0x64,%ebx
or     %ebp,%r12d
mov    $0x0,%ebp
mov    $0x0,%r12d
je     11c0 <main+0x30>
jmp    12eb <main+0x15b>
cs nopw 0x0(%rax,%rax,1)
nop
jne    1268 <main+0xd8>
xor    %ebx,%ebx
mov    $0x1,%ebp
or     %r12d,%r14d
mov    $0x0,%r12d
mov    $0x0,%r14d
je     11c0 <main+0x30>
jmp    12eb <main+0x15b>
nop
or     %ebp,%r14d
jne    12eb <main+0x15b>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    $0x1,%r12d
mov    $0x0,%ebp
mov    $0x0,%r14d
cmp    $0x65,%eax
jb     11c0 <main+0x30>
jmp    12eb <main+0x15b>
cmp    $0xffffffff,%eax
jne    12eb <main+0x15b>
cmp    $0xffffffff,%ebx
je     12eb <main+0x15b>
lea    0xdb6(%rip),%rdx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    %ebx,%ecx
call   1050 <snprintf@plt>
mov    0x2d5f(%rip),%rax
mov    0x2d28(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xd5d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    12c7 <main+0x137>
lea    0xd7c(%rip),%rsi
lea    0xd43(%rip),%rdx
mov    $0x1,%edi
call   1070 <err@plt>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    12fb <main+0x16b>
xor    %eax,%eax
call   10b0 <print_help@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/leds/kbd_backlight/brightness\00"
@.str.1 = [6 x i8] c"edhl:\00"
@EXIT_FAILURE = global i32 0
@optarg = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str.3 = [3 x i8] c"%s\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
%10 = alloca i32
%11 = alloca [4 x i8]
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %10
%14 = bitcast [4 x i8]* %11 to i8*
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8** %13
store i32 0, i32* %9
store i32 0, i32* %8
store i32 0, i32* %7
br label %15
15: ; preds = %67, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %6
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %68
20: ; preds = %15
%21 = load i32, i32* %6
switch i32 %21, label %64 [
i32 101, label %22
i32 100, label %32
i32 108, label %42
i32 63, label %63
i32 104, label %63
]
22: ; preds = %20
store i32 1, i32* %7
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25, %22
%29 = call i32 (...) @print_help()
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %97
31: ; preds = %25
store i32 100, i32* %10
br label %67
32: ; preds = %20
store i32 1, i32* %8
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35, %32
%39 = call i32 (...) @print_help()
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %97
41: ; preds = %35
store i32 0, i32* %10
br label %67
42: ; preds = %20
store i32 1, i32* %9
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45, %42
%49 = call i32 (...) @print_help()
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %3
br label %97
51: ; preds = %45
%52 = load i32, i32* @optarg
%53 = call i32 @atoi(i32 %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp slt i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %51
%57 = load i32, i32* %10
%58 = icmp sgt i32 %57, 100
br i1 %58, label %59, label %62
59: ; preds = %56, %51
%60 = call i32 (...) @print_help()
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %97
62: ; preds = %56
br label %67
63: ; preds = %20, %20
br label %64
64: ; preds = %20, %63
%65 = call i32 (...) @print_help()
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %3
br label %97
67: ; preds = %62, %41, %31
br label %15
68: ; preds = %15
%69 = load i32, i32* %10
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = call i32 (...) @print_help()
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %3
br label %97
74: ; preds = %68
%75 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%76 = load i32, i32* %10
%77 = call i32 @snprintf(i8* %75, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %74
%79 = load i8*, i8** %13
%80 = load i32, i32* @O_TRUNC
%81 = load i32, i32* @O_WRONLY
%82 = or i32 %80, %81
%83 = call i32 @open(i8* %79, i32 %82)
store i32 %83, i32* %12
%84 = load i32, i32* %12
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %89
86: ; preds = %78
%87 = load i8*, i8** %13
%88 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %86, %78
%90 = load i32, i32* %12
%91 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%92 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
%94 = call i32 @write(i32 %90, i8* %91, i32 %93)
%95 = load i32, i32* %12
%96 = call i32 @close(i32 %95)
br label %97
97: ; preds = %89, %71, %64, %59, %48, %38, %28
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/leds/kbd_backlight/brightness\00"
@.str.1 = [6 x i8] c"edhl:\00"
@EXIT_FAILURE = global i32 0
@optarg = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %20, %2
%6 = phi i32 [ 0, %2 ], [ %21, %20 ]
%7 = phi i32 [ 0, %2 ], [ %22, %20 ]
%8 = phi i32 [ -1, %2 ], [ %23, %20 ]
%9 = phi i32 [ 0, %2 ], [ %24, %20 ]
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
switch i32 %10, label %41 [
i32 -1, label %44
i32 101, label %11
i32 100, label %17
i32 108, label %28
]
11: ; preds = %5
%12 = or i32 %7, %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = tail call i32 (...) @print_help()
%16 = load i32, i32* @EXIT_FAILURE
br label %62
17: ; preds = %5
%18 = or i32 %9, %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17, %11, %34
%21 = phi i32 [ 0, %34 ], [ 0, %11 ], [ 1, %17 ]
%22 = phi i32 [ 1, %34 ], [ 0, %11 ], [ 0, %17 ]
%23 = phi i32 [ %36, %34 ], [ 100, %11 ], [ 0, %17 ]
%24 = phi i32 [ 0, %34 ], [ 1, %11 ], [ 0, %17 ]
br label %5
25: ; preds = %17
%26 = tail call i32 (...) @print_help()
%27 = load i32, i32* @EXIT_FAILURE
br label %62
28: ; preds = %5
%29 = or i32 %9, %6
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 (...) @print_help()
%33 = load i32, i32* @EXIT_FAILURE
br label %62
34: ; preds = %28
%35 = load i32, i32* @optarg
%36 = tail call i32 @atoi(i32 %35)
%37 = icmp ugt i32 %36, 100
br i1 %37, label %38, label %20
38: ; preds = %34
%39 = tail call i32 (...) @print_help()
%40 = load i32, i32* @EXIT_FAILURE
br label %62
41: ; preds = %5
%42 = tail call i32 (...) @print_help()
%43 = load i32, i32* @EXIT_FAILURE
br label %62
44: ; preds = %5
%45 = icmp eq i32 %8, -1
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = tail call i32 (...) @print_help()
%48 = load i32, i32* @EXIT_FAILURE
br label %62
49: ; preds = %44
%50 = call i32 @snprintf(i8* %4, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%51 = load i32, i32* @O_TRUNC
%52 = load i32, i32* @O_WRONLY
%53 = or i32 %52, %51
%54 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %49
%57 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %58
58: ; preds = %56, %49
%59 = call i32 @strlen(i8* %4)
%60 = call i32 @write(i32 %54, i8* %4, i32 %59)
%61 = call i32 @close(i32 %54)
br label %62
62: ; preds = %58, %46, %41, %38, %31, %25, %14
%63 = phi i32 [ %43, %41 ], [ %33, %31 ], [ %40, %38 ], [ %27, %25 ], [ %16, %14 ], [ %48, %46 ], [ 0, %58 ]
ret i32 %63
}