#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ _IOC(int, char, int, int);
int _IOC_READ;
int _IOC_WRITE;
int ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
void send_cmd(int fd, int arg1, int arg2) {
  int res;
  char buf[3];
  memset(buf, 0x0, sizeof(buf));
  buf[0] = 0x13;
  buf[1] = arg1;
  buf[2] = arg2;
  res = ioctl(fd, _IOC(_IOC_WRITE | _IOC_READ, 'H', 0x06, 3), buf);
  if (res < 0)
    perror("HIDIOCSFEATURE");
  else if (res == 3)
    printf("Sent command %02x %02x\n", arg1, arg2);
  else
    printf("ioctl HIDIOCSFEATURE returned: %d\n", res);
}


x86 assembly (clang, -O0):
<send_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
movb   $0x13,-0x13(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x12(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
or     (%rax),%edi
mov    $0x48,%esi
mov    $0x6,%edx
mov    $0x3,%ecx
call   1030 <_IOC@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
lea    -0x13(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11d9 <send_cmd+0x89>
lea    0xe31(%rip),%rdi
call   1070 <perror@plt>
jmp    1212 <send_cmd+0xc2>
cmpl   $0x3,-0x10(%rbp)
jne    11fc <send_cmd+0xac>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120d <send_cmd+0xbd>
mov    -0x10(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1212 <send_cmd+0xc2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_cmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x5(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
movb   $0x13,0x5(%rsp)
mov    %bpl,0x6(%rsp)
mov    %r14b,0x7(%rsp)
mov    0x2e48(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
mov    $0x48,%esi
mov    $0x6,%edx
mov    $0x3,%ecx
call   1030 <_IOC@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r15,%rdx
call   1060 <ioctl@plt>
test   %eax,%eax
js     11ec <send_cmd+0x9c>
cmp    $0x3,%eax
jne    11d1 <send_cmd+0x81>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e1 <send_cmd+0x91>
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
jmp    11e1 <send_cmd+0x91>

LLVM IR (-O0):
@_IOC_WRITE = global i32 0
@_IOC_READ = global i32 0
@.str = [15 x i8] c"HIDIOCSFEATURE\00"
@.str.1 = [24 x i8] c"Sent command %02x %02x\0A\00"
@.str.2 = [35 x i8] c"ioctl HIDIOCSFEATURE returned: %d\0A\00"
define void @send_cmd(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 3)
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 19, i8* %11
%12 = load i32, i32* %5
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %13, i8* %14
%15 = load i32, i32* %6
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 %16, i8* %17
%18 = load i32, i32* %4
%19 = load i32, i32* @_IOC_WRITE
%20 = load i32, i32* @_IOC_READ
%21 = or i32 %19, %20
%22 = call i32 @_IOC(i32 %21, i8 signext 72, i32 6, i32 3)
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%24 = call i32 @ioctl(i32 %18, i32 %22, i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %3
%28 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %40
29: ; preds = %3
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
br label %39
36: ; preds = %29
%37 = load i32, i32* %7
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %32
br label %40
40: ; preds = %39, %27
ret void
}

LLVM IR (-O2):
@_IOC_WRITE = global i32 0
@_IOC_READ = global i32 0
@.str = [15 x i8] c"HIDIOCSFEATURE\00"
@.str.1 = [24 x i8] c"Sent command %02x %02x\0A\00"
@.str.2 = [35 x i8] c"ioctl HIDIOCSFEATURE returned: %d\0A\00"
define void @send_cmd(i32 %0, i32 %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 3)
store i8 19, i8* %5
%7 = trunc i32 %1 to i8
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %7, i8* %8
%9 = trunc i32 %2 to i8
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 %9, i8* %10
%11 = load i32, i32* @_IOC_WRITE
%12 = load i32, i32* @_IOC_READ
%13 = or i32 %12, %11
%14 = call i32 @_IOC(i32 %13, i8 signext 72, i32 6, i32 3)
%15 = call i32 @ioctl(i32 %0, i32 %14, i8* %5)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %25
19: ; preds = %3
%20 = icmp eq i32 %15, 3
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
br label %25
23: ; preds = %19
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %25
25: ; preds = %21, %23, %17
ret void
}