#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int fd;
  int steps;
  int current;
  int new;
  fd = open("/dev/sharp_fl", O_RDWR);
  steps = ioctl(fd, 102, 0);
  if (steps < 1) {
    perror("SHARP_FL_IOCTL_GET_STEP: ");
    close(fd);
    exit(1);
  }
  current = ioctl(fd, 101, 0);
  if (argc < 2) {
    printf("Current backlight setting = %d / %d\n", current, steps - 1);
  } else if (strcmp(argv[1], "on") == 0) {
    ioctl(fd, 1, 0);
  } else if (strcmp(argv[1], "off") == 0) {
    ioctl(fd, 2, 0);
  } else if (sscanf(argv[1], "%d", &new) == 1) {
    printf("Setting backlight to %d\n", new);
    ioctl(fd, 100, new);
  } else {
    printf("Usage:\n%s [on|off|<num>]\n", argv[0]);
    exit(1);
  }
  close(fd);
  return 0;
}


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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x66,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11e8 <main+0x68>
lea    0xe3d(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x65,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1220 <main+0xa0>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f9 <main+0x179>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1252 <main+0xd2>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
jmp    12f4 <main+0x174>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1284 <main+0x104>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
jmp    12ef <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc1(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    12cb <main+0x14b>
mov    -0x20(%rbp),%esi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    $0x64,%esi
call   1040 <ioctl@plt>
jmp    12ea <main+0x16a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12ef <main+0x16f>
jmp    12f4 <main+0x174>
jmp    12f9 <main+0x179>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    $0x66,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
test   %eax,%eax
jle    1279 <main+0xf9>
mov    %eax,%ebx
mov    %r15d,%edi
mov    $0x65,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0x1,%ebp
jg     11e7 <main+0x67>
add    $0xffffffff,%ebx
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1264 <main+0xe4>
mov    0x8(%r14),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     124b <main+0xcb>
mov    0x8(%r14),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1255 <main+0xd5>
mov    0x8(%r14),%rdi
lea    0xe38(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1297 <main+0x117>
mov    0x4(%rsp),%esi
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    %r15d,%edi
mov    $0x64,%esi
jmp    125f <main+0xdf>
mov    %r15d,%edi
mov    $0x1,%esi
jmp    125d <main+0xdd>
mov    %r15d,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8e(%rip),%rdi
call   1090 <perror@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    (%r14),%rsi
lea    0xdcf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/sharp_fl\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"SHARP_FL_IOCTL_GET_STEP: \00"
@.str.2 = [37 x i8] c"Current backlight setting = %d / %d\0A\00"
@.str.3 = [3 x i8] c"on\00"
@.str.4 = [4 x i8] c"off\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [25 x i8] c"Setting backlight to %d\0A\00"
@.str.7 = [26 x i8] c"Usage:\0A%s [on|off|<num>]\0A\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* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @ioctl(i32 %12, i32 102, i32 0)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %6
%23 = call i32 @ioctl(i32 %22, i32 101, i32 0)
store i32 %23, i32* %8
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %29)
br label %70
31: ; preds = %21
%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.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* %6
%39 = call i32 @ioctl(i32 %38, i32 1, i32 0)
br label %69
40: ; preds = %31
%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 ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %6
%48 = call i32 @ioctl(i32 %47, i32 2, i32 0)
br label %68
49: ; preds = %40
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %9)
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %61
55: ; preds = %49
%56 = load i32, i32* %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %6
%59 = load i32, i32* %9
%60 = call i32 @ioctl(i32 %58, i32 100, i32 %59)
br label %67
61: ; preds = %49
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %55
br label %68
68: ; preds = %67, %46
br label %69
69: ; preds = %68, %37
br label %70
70: ; preds = %69, %26
%71 = load i32, i32* %6
%72 = call i32 @close(i32 %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/sharp_fl\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"SHARP_FL_IOCTL_GET_STEP: \00"
@.str.2 = [37 x i8] c"Current backlight setting = %d / %d\0A\00"
@.str.3 = [3 x i8] c"on\00"
@.str.4 = [4 x i8] c"off\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [25 x i8] c"Setting backlight to %d\0A\00"
@.str.7 = [26 x i8] c"Usage:\0A%s [on|off|<num>]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @ioctl(i32 %6, i32 102, i32 0)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @close(i32 %6)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32 @ioctl(i32 %6, i32 101, i32 0)
%15 = icmp slt i32 %0, 2
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = add nsw i32 %7, -1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %17)
br label %45
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @ioctl(i32 %6, i32 1, i32 0)
br label %45
26: ; preds = %19
%27 = load i8*, i8** %20
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @ioctl(i32 %6, i32 2, i32 0)
br label %45
32: ; preds = %26
%33 = load i8*, i8** %20
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %3
%40 = call i32 @ioctl(i32 %6, i32 100, i32 %39)
br label %45
41: ; preds = %32
%42 = load i8*, i8** %1
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %24, %36, %30, %16
%46 = call i32 @close(i32 %6)
ret i32 0
}