#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 EINVAL;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int cmd = 0;
  if (!(strcmp(argv[1], "ON")))
    cmd = 1;
  else if (!(strcmp(argv[1], "OFF")))
    cmd = 0;
  else {
    printf("cmd error!\n");
    return -EINVAL;
  }
  int fd;
  fd = open("/dev/leddev0", O_RDWR);
  switch (cmd) {
  case 1:
    ioctl(fd, _IO('L', 0));
    break;
  case 0:
    ioctl(fd, _IO('L', 1));
    break;
  default:
    printf("cmd error!\n");
    break;
  }
  close(fd);
  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)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11a6 <main+0x46>
movl   $0x1,-0x14(%rbp)
jmp    11f3 <main+0x93>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11cf <main+0x6f>
movl   $0x0,-0x14(%rbp)
jmp    11ee <main+0x8e>
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    0x2df4(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <main+0x12f>
jmp    11f3 <main+0x93>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe10(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1250 <main+0xf0>
jmp    121e <main+0xbe>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
jne    1274 <main+0x114>
jmp    122f <main+0xcf>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x4c,%edi
xor    %esi,%esi
call   1040 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
jmp    1280 <main+0x120>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x4c,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
jmp    1280 <main+0x120>
lea    0xd8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rbx
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
xor    %r14d,%r14d
mov    $0x0,%ebp
test   %eax,%eax
je     11b6 <main+0x56>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11b1 <main+0x51>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e2f(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
jmp    11e9 <main+0x89>
mov    $0x1,%ebp
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
mov    $0x4c,%edi
mov    %ebp,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ON\00"
@.str.1 = [4 x i8] c"OFF\00"
@.str.2 = [12 x i8] c"cmd error!\0A\00"
@EINVAL = global i32 0
@.str.3 = [13 x i8] c"/dev/leddev0\00"
@O_RDWR = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 1, i32* %6
br label %26
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 0, i32* %6
br label %25
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
store i32 %24, i32* %3
br label %43
25: ; preds = %20
br label %26
26: ; preds = %25, %13
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %6
switch i32 %29, label %38 [
i32 1, label %30
i32 0, label %34
]
30: ; preds = %26
%31 = load i32, i32* %7
%32 = call i32 @_IO(i8 signext 76, i32 0)
%33 = call i32 @ioctl(i32 %31, i32 %32)
br label %40
34: ; preds = %26
%35 = load i32, i32* %7
%36 = call i32 @_IO(i8 signext 76, i32 1)
%37 = call i32 @ioctl(i32 %35, i32 %36)
br label %40
38: ; preds = %26
%39 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %34, %30
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %21
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"ON\00"
@.str.1 = [4 x i8] c"OFF\00"
@EINVAL = global i32 0
@.str.3 = [13 x i8] c"/dev/leddev0\00"
@O_RDWR = global i32 0
@str.4 = [11 x i8] c"cmd error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
br label %21
14: ; preds = %7, %2
%15 = phi i32 [ 0, %2 ], [ 1, %7 ]
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = tail call i32 @_IO(i8 signext 76, i32 %15)
%19 = tail call i32 @ioctl(i32 %17, i32 %18)
%20 = tail call i32 @close(i32 %17)
br label %21
21: ; preds = %14, %10
%22 = phi i32 [ %13, %10 ], [ 0, %14 ]
ret i32 %22
}