#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int on;
  int led_no;
  int fd;
  if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 ||
      sscanf(argv[2], "%d", &on) != 1 || on < 0 || on > 1 || led_no < 0 ||
      led_no > 4) {
    fprintf(stderr, "Usage: leds led_no 0|1\n");
    exit(1);
  }
  fd = open("/dev/ledsdev", 0);
  if (fd < 0) {
    perror("open leds device "
           "/dev/ledsdev");
    exit(1);
  }
  ioctl(fd, on, led_no);
  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)
cmpl   $0x3,-0x8(%rbp)
jne    11fa <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11fa <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe40(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11fa <main+0x8a>
cmpl   $0x0,-0x14(%rbp)
jl     11fa <main+0x8a>
cmpl   $0x1,-0x14(%rbp)
jg     11fa <main+0x8a>
cmpl   $0x0,-0x18(%rbp)
jl     11fa <main+0x8a>
cmpl   $0x4,-0x18(%rbp)
jle    1219 <main+0xa9>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe0c(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    124a <main+0xda>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1201 <main+0x91>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe74(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1201 <main+0x91>
mov    0x10(%rbx),%rdi
lea    0xe5a(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1201 <main+0x91>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     1201 <main+0x91>
cmp    $0x1,%eax
jg     1201 <main+0x91>
mov    0x8(%rsp),%eax
test   %eax,%eax
js     1201 <main+0x91>
cmp    $0x5,%eax
jge    1201 <main+0x91>
lea    0xe56(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     1220 <main+0xb0>
mov    %eax,%ebx
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %eax,%edi
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdf4(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Usage: leds led_no 0|1\0A\00"
@.str.2 = [13 x i8] c"/dev/ledsdev\00"
@.str.3 = [30 x i8] c"open leds device /dev/ledsdev\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %35, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%16 = icmp ne i32 %15, 1
br i1 %16, label %35, label %17
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%22 = icmp ne i32 %21, 1
br i1 %22, label %35, label %23
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 1
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 4
br i1 %34, label %35, label %39
35: ; preds = %32, %29, %26, %23, %17, %11, %2
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
%47 = load i32, i32* %8
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = call i32 @ioctl(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Usage: leds led_no 0|1\0A\00"
@.str.2 = [13 x i8] c"/dev/ledsdev\00"
@.str.3 = [30 x i8] c"open leds device /dev/ledsdev\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = icmp ne i32 %16, 1
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
%20 = select i1 %17, i1 true, i1 %19
%21 = icmp sgt i32 %18, 1
%22 = select i1 %20, i1 true, i1 %21
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 0
%25 = select i1 %22, i1 true, i1 %24
%26 = icmp sgt i32 %23, 4
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %28, label %32
28: ; preds = %13, %8, %2
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %13
%33 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 0)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = call i32 @ioctl(i32 %33, i32 %39, i32 %40)
%42 = call i32 @close(i32 %33)
ret i32 0
}