#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 O_NONBLOCK;
int O_RDWR;
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send_cmd(int, int, int);
int main(int argc, char **argv) {
  int fd;
  if (argc < 2) {
    printf(
        "Usage: tp-compact-usb-keyboard (hidraw device, e.g. /dev/hidraw1)\n");
    return 1;
  }
  fd = open(argv[1], O_RDWR | O_NONBLOCK);
  if (fd < 0) {
    perror("Unable to open device");
    return 1;
  }
  send_cmd(fd, 0x01, 0x03);
  send_cmd(fd, 0x09, 0x01);
  send_cmd(fd, 0x05, 0x01);
}


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    1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bc <main+0x7c>
lea    0xe98(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <main+0xb2>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1060 <send_cmd@plt>
mov    -0x14(%rbp),%edi
mov    $0x9,%esi
mov    $0x1,%edx
call   1060 <send_cmd@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
mov    $0x1,%edx
call   1060 <send_cmd@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jg     1159 <main+0x19>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rsi),%rdi
mov    0x2e84(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     11b1 <main+0x71>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x3,%edx
call   1060 <send_cmd@plt>
mov    %ebx,%edi
mov    $0x9,%esi
mov    $0x1,%edx
call   1060 <send_cmd@plt>
mov    %ebx,%edi
mov    $0x5,%esi
mov    $0x1,%edx
call   1060 <send_cmd@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe48(%rip),%rdi
call   1050 <perror@plt>
jmp    1152 <main+0x12>

LLVM IR (-O0):
@.str = [67 x i8] c"Usage: tp-compact-usb-keyboard (hidraw device, e.g. /dev/hidraw1)\0A\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"Unable to open device\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %30
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %14, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %30
23: ; preds = %11
%24 = load i32, i32* %6
%25 = call i32 @send_cmd(i32 %24, i32 1, i32 3)
%26 = load i32, i32* %6
%27 = call i32 @send_cmd(i32 %26, i32 9, i32 1)
%28 = load i32, i32* %6
%29 = call i32 @send_cmd(i32 %28, i32 5, i32 1)
br label %30
30: ; preds = %23, %21, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"Unable to open device\00"
@str = [66 x i8] c"Usage: tp-compact-usb-keyboard (hidraw device, e.g. /dev/hidraw1)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
br label %20
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %8, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %6
%17 = tail call i32 @send_cmd(i32 %12, i32 1, i32 3)
%18 = tail call i32 @send_cmd(i32 %12, i32 9, i32 1)
%19 = tail call i32 @send_cmd(i32 %12, i32 5, i32 1)
br label %20
20: ; preds = %16, %14, %4
%21 = phi i32 [ 1, %4 ], [ 1, %14 ], [ 0, %16 ]
ret i32 %21
}