#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int ipod_generation();
int /*<<< orphan*/ ipod_set_backlight(int);
int /*<<< orphan*/ ipod_set_brightness(int);
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    print_help();
    exit(1);
  }
  if (strcmp(argv[1], "on") == 0) {
    ipod_set_backlight(1);
    printf("Backlight turned on.\n");
    exit(0);
  } else if (strcmp(argv[1], "off") == 0) {
    ipod_set_backlight(0);
    printf("Backlight turned off.\n");
    exit(0);
  } else if (argc == 3 && strcmp(argv[1], "brightness") == 0) {
    int hw_ver = ipod_generation() >> 16;
    if (hw_ver == 0xC || hw_ver == 0xB) {
      int brightness = atoi(argv[2]);
      if (!brightness || brightness < 1 || brightness > 32) {
        printf("Please specify a valid brightness level between 1 and 32.\n");
        print_help();
        exit(1);
      } else {
        ipod_set_backlight(1);
        printf("Backlight turned on.\n");
        ipod_set_brightness(brightness);
        printf("Backlight brightness level set to %i.\n", brightness);
        exit(0);
      }
    } else {
      printf("Sorry, backlight brightness levels can only be changed for iPod "
             "nanos and videos.\n");
      exit(1);
    }
  } else {
    print_help();
    exit(1);
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11b1 <main+0x31>
mov    $0x0,%al
call   1090 <print_help@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe40(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ee <main+0x6e>
mov    $0x1,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1228 <main+0xa8>
xor    %edi,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    130e <main+0x18e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    130e <main+0x18e>
mov    $0x0,%al
call   1070 <ipod_generation@plt>
sar    $0x10,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xc,-0x14(%rbp)
je     1271 <main+0xf1>
cmpl   $0xb,-0x14(%rbp)
jne    12f6 <main+0x176>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     129f <main+0x11f>
cmpl   $0x1,-0x18(%rbp)
jl     129f <main+0x11f>
cmpl   $0x20,-0x18(%rbp)
jle    12be <main+0x13e>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <print_help@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x1,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <ipod_set_brightness@plt>
mov    -0x18(%rbp),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <print_help@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11a9 <main+0x19>
xor    %eax,%eax
call   10a0 <print_help@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11d6 <main+0x46>
mov    $0x1,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xf07(%rip),%rdi
jmp    11f9 <main+0x69>
mov    0x8(%rbx),%rdi
lea    0xe22(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1205 <main+0x75>
xor    %edi,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
cmp    $0x3,%ebp
jne    1198 <main+0x8>
mov    0x8(%rbx),%rdi
lea    0xdf2(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1198 <main+0x8>
xor    %eax,%eax
call   1080 <ipod_generation@plt>
sar    $0x10,%eax
add    $0xfffffff5,%eax
cmp    $0x1,%eax
ja     1259 <main+0xc9>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    -0x21(%rbx),%eax
cmp    $0xffffffdf,%eax
ja     126f <main+0xdf>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
jmp    1198 <main+0x8>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x1,%edi
call   1030 <ipod_set_backlight@plt>
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1060 <ipod_set_brightness@plt>
lea    0xd7f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"on\00"
@.str.1 = [22 x i8] c"Backlight turned on.\0A\00"
@.str.2 = [4 x i8] c"off\00"
@.str.3 = [23 x i8] c"Backlight turned off.\0A\00"
@.str.4 = [11 x i8] c"brightness\00"
@.str.5 = [59 x i8] c"Please specify a valid brightness level between 1 and 32.\0A\00"
@.str.6 = [39 x i8] c"Backlight brightness level set to %i.\0A\00"
@.str.7 = [83 x i8] c"Sorry, backlight brightness levels can only be changed for iPod nanos and videos.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (...) @print_help()
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 @ipod_set_backlight(i32 1)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 @ipod_set_backlight(i32 0)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %23
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %78
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %78
42: ; preds = %36
%43 = call i32 (...) @ipod_generation()
%44 = ashr i32 %43, 16
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 12
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 11
br i1 %49, label %50, label %75
50: ; preds = %47, %42
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %50
%58 = load i32, i32* %7
%59 = icmp slt i32 %58, 1
br i1 %59, label %63, label %60
60: ; preds = %57
%61 = load i32, i32* %7
%62 = icmp sgt i32 %61, 32
br i1 %62, label %63, label %67
63: ; preds = %60, %57, %50
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 (...) @print_help()
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %60
%68 = call i32 @ipod_set_backlight(i32 1)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%70 = load i32, i32* %7
%71 = call i32 @ipod_set_brightness(i32 %70)
%72 = load i32, i32* %7
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = call i32 @exit(i32 0)
unreachable
75: ; preds = %47
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.7, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %36, %33
%79 = call i32 (...) @print_help()
%80 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
@.str.4 = [11 x i8] c"brightness\00"
@.str.6 = [39 x i8] c"Backlight brightness level set to %i.\0A\00"
@str = [82 x i8] c"Sorry, backlight brightness levels can only be changed for iPod nanos and videos.\00"
@str.9 = [58 x i8] c"Please specify a valid brightness level between 1 and 32.\00"
@str.10 = [22 x i8] c"Backlight turned off.\00"
@str.11 = [21 x i8] c"Backlight turned on.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 (...) @print_help()
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = tail call i32 @ipod_set_backlight(i32 1)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %7
%17 = load i8*, i8** %8
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = tail call i32 @ipod_set_backlight(i32 0)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = icmp eq i32 %0, 3
br i1 %25, label %26, label %54
26: ; preds = %24
%27 = load i8*, i8** %8
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %54
30: ; preds = %26
%31 = tail call i32 (...) @ipod_generation()
%32 = ashr i32 %31, 16
%33 = add nsw i32 %32, -11
%34 = icmp ult i32 %33, 2
br i1 %34, label %35, label %51
35: ; preds = %30
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = load i8*, i8** %36
%38 = tail call i32 @atoi(i8* %37)
%39 = add i32 %38, -33
%40 = icmp ult i32 %39, -32
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.9, i64 0, i64 0))
%43 = tail call i32 (...) @print_help()
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = tail call i32 @ipod_set_backlight(i32 1)
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%48 = tail call i32 @ipod_set_brightness(i32 %38)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%50 = tail call i32 @exit(i32 0)
unreachable
51: ; preds = %30
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @str, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %26, %24
%55 = tail call i32 (...) @print_help()
%56 = tail call i32 @exit(i32 1)
unreachable
}