#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 */
struct input_event {
  int value;
  int /*<<< orphan*/ code;
  int /*<<< orphan*/ type;
};

/* Variables and functions */
int /*<<< orphan*/ EV_LED;
int /*<<< orphan*/ LED_MISC;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write(int, struct input_event *, int);
main(int argc, char **argv) {
  int fd;
  int retval;
  struct input_event ev;
  if (argc != 3) {
    printf("Usage: %s device 1|0\n", argv[0]);
    exit(2);
  }
  if ((fd = open(argv[1], O_WRONLY)) < 0) {
    perror("opening the file you specified");
    exit(1);
  }
  ev.type = EV_LED;
  ev.code = LED_MISC;
  ev.value = (argv[2][0] == '1') ? 1 : 0;
  write(fd, &ev, sizeof(struct input_event));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     1186 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11be <main+0x6e>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x31,%edx
cmove  %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11b3 <main+0x63>
mov    0x8(%rbx),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     11cc <main+0x7c>
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2e59(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
mov    0x10(%rbx),%rcx
xor    %edx,%edx
cmpb   $0x31,(%rcx)
sete   %dl
mov    %edx,(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32 }
@.str = [22 x i8] c"Usage: %s device 1|0\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"opening the file you specified\00"
@EV_LED = global i32 0
@LED_MISC = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.input_event
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load i32, i32* @EV_LED
%28 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @LED_MISC
%30 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 49
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 1, i32 0
%40 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %5
%42 = call i32 @write(i32 %41, %struct.input_event* %7, i32 12)
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32 }
@.str = [22 x i8] c"Usage: %s device 1|0\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"opening the file you specified\00"
@EV_LED = global i32 0
@LED_MISC = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.input_event
%4 = bitcast %struct.input_event* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i32, i32* @EV_LED
%21 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @LED_MISC
%23 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 49
%28 = zext i1 %27 to i32
%29 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
store i32 %28, i32* %29
%30 = call i32 @write(i32 %14, %struct.input_event* %3, i32 12)
ret i32 0
}