#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*/ uref;
struct hiddev_usage_ref {
  int report_id;
  int usage_index;
  int usage_code;
  unsigned char value;
  int num_fields;
  void *report_type;
  scalar_t__ field_index;
};
struct hiddev_report_info {
  int report_id;
  int usage_index;
  int usage_code;
  unsigned char value;
  int num_fields;
  void *report_type;
  scalar_t__ field_index;
};
typedef int /*<<< orphan*/ rinfo;

/* Variables and functions */
int /*<<< orphan*/ HIDIOCSREPORT;
int /*<<< orphan*/ HIDIOCSUSAGE;
void *HID_REPORT_TYPE_OUTPUT;
int ioctl(int, int /*<<< orphan*/, struct hiddev_usage_ref *);
int /*<<< orphan*/ memset(struct hiddev_usage_ref *, int /*<<< orphan*/, int);
int send_report20(int fd, const unsigned char *buf, size_t size) {
  struct hiddev_report_info rinfo;
  struct hiddev_usage_ref uref;
  int i, err;
  for (i = 0; i < size; i++) {
    memset(&uref, 0, sizeof(uref));
    uref.report_type = HID_REPORT_TYPE_OUTPUT;
    uref.report_id = 0x11;
    uref.field_index = 0;
    uref.usage_index = i;
    uref.usage_code = 0xff000001;
    uref.value = buf[i];
    err = ioctl(fd, HIDIOCSUSAGE, &uref);
    if (err < 0)
      return err;
  }
  memset(&rinfo, 0, sizeof(rinfo));
  rinfo.report_type = HID_REPORT_TYPE_OUTPUT;
  rinfo.report_id = 0x11;
  rinfo.num_fields = 1;
  err = ioctl(fd, HIDIOCSREPORT, &rinfo);
  return err;
}


x86 assembly (clang, -O0):
<send_report20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x6c(%rbp)
movslq -0x6c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d0 <send_report20+0xb0>
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
movl   $0x11,-0x68(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x64(%rbp)
movl   $0xff000001,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x5c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jge    11bd <send_report20+0x9d>
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121a <send_report20+0xfa>
jmp    11c2 <send_report20+0xa2>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    113a <send_report20+0x1a>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x11,-0x40(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_report20>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edi,%r14d
test   %rdx,%rdx
je     11b0 <send_report20+0x90>
mov    %rdx,%r12
mov    %rsi,%r15
xor    %ebx,%ebx
lea    0x8(%rsp),%rbp
mov    0x2e8e(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
movl   $0x11,0x8(%rsp)
movq   $0x0,0x28(%rsp)
mov    %ebx,0xc(%rsp)
movl   $0xff000001,0x10(%rsp)
ff
movzbl (%r15,%rbx,1),%eax
mov    %al,0x14(%rsp)
mov    0x0(%r13),%esi
mov    %r14d,%edi
mov    %rbp,%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
js     11f7 <send_report20+0xd7>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <send_report20+0x30>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x48(%rsp)
movl   $0x11,0x30(%rsp)
movl   $0x1,0x40(%rsp)
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hiddev_report_info = type { i32, i32, i32, i8, i32, i8*, i64 }
%struct.hiddev_usage_ref = type { i32, i32, i32, i8, i32, i8*, i64 }
@HID_REPORT_TYPE_OUTPUT = global i8* null
@HIDIOCSUSAGE = global i32 0
@HIDIOCSREPORT = global i32 0
define i32 @send_report20(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.hiddev_report_info
%9 = alloca %struct.hiddev_usage_ref
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %10
br label %12
12: ; preds = %40, %3
%13 = load i32, i32* %10
%14 = sext i32 %13 to i64
%15 = load i64, i64* %7
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %43
17: ; preds = %12
%18 = call i32 @memset(%struct.hiddev_usage_ref* %9, i32 0, i32 40)
%19 = load i8*, i8** @HID_REPORT_TYPE_OUTPUT
%20 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 5
store i8* %19, i8** %20
%21 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 0
store i32 17, i32* %21
%22 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 6
store i64 0, i64* %22
%23 = load i32, i32* %10
%24 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 2
store i32 -16777215, i32* %25
%26 = load i8*, i8** %6
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %9, i32 0, i32 3
store i8 %30, i8* %31
%32 = load i32, i32* %5
%33 = load i32, i32* @HIDIOCSUSAGE
%34 = call i32 @ioctl(i32 %32, i32 %33, %struct.hiddev_usage_ref* %9)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %17
%38 = load i32, i32* %11
store i32 %38, i32* %4
br label %55
39: ; preds = %17
br label %40
40: ; preds = %39
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %12
43: ; preds = %12
%44 = bitcast %struct.hiddev_report_info* %8 to %struct.hiddev_usage_ref*
%45 = call i32 @memset(%struct.hiddev_usage_ref* %44, i32 0, i32 40)
%46 = load i8*, i8** @HID_REPORT_TYPE_OUTPUT
%47 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %8, i32 0, i32 5
store i8* %46, i8** %47
%48 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %8, i32 0, i32 0
store i32 17, i32* %48
%49 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %8, i32 0, i32 4
store i32 1, i32* %49
%50 = load i32, i32* %5
%51 = load i32, i32* @HIDIOCSREPORT
%52 = bitcast %struct.hiddev_report_info* %8 to %struct.hiddev_usage_ref*
%53 = call i32 @ioctl(i32 %50, i32 %51, %struct.hiddev_usage_ref* %52)
store i32 %53, i32* %11
%54 = load i32, i32* %11
store i32 %54, i32* %4
br label %55
55: ; preds = %43, %37
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
%struct.hiddev_report_info = type { i32, i32, i32, i8, i32, i8*, i64 }
%struct.hiddev_usage_ref = type { i32, i32, i32, i8, i32, i8*, i64 }
@HID_REPORT_TYPE_OUTPUT = global i8* null
@HIDIOCSUSAGE = global i32 0
@HIDIOCSREPORT = global i32 0
define i32 @send_report20(i32 %0, i8* nocapture %1, i64 %2) {
%4 = alloca %struct.hiddev_report_info
%5 = alloca %struct.hiddev_usage_ref
%6 = bitcast %struct.hiddev_report_info* %4 to i8*
%7 = bitcast %struct.hiddev_usage_ref* %5 to i8*
%8 = icmp eq i64 %2, 0
br i1 %8, label %29, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 5
%11 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 0
%12 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 6
%13 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 1
%14 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 2
%15 = getelementptr inbounds %struct.hiddev_usage_ref, %struct.hiddev_usage_ref* %5, i64 0, i32 3
br label %18
16: ; preds = %18
%17 = icmp eq i64 %28, %2
br i1 %17, label %29, label %18
18: ; preds = %9, %16
%19 = phi i64 [ 0, %9 ], [ %28, %16 ]
%20 = call i32 @memset(%struct.hiddev_usage_ref* %5, i32 0, i32 40)
%21 = load i8*, i8** @HID_REPORT_TYPE_OUTPUT
store i8* %21, i8** %10
store i32 17, i32* %11
store i64 0, i64* %12
%22 = trunc i64 %19 to i32
store i32 %22, i32* %13
store i32 -16777215, i32* %14
%23 = getelementptr inbounds i8, i8* %1, i64 %19
%24 = load i8, i8* %23
store i8 %24, i8* %15
%25 = load i32, i32* @HIDIOCSUSAGE
%26 = call i32 @ioctl(i32 %0, i32 %25, %struct.hiddev_usage_ref* %5)
%27 = icmp slt i32 %26, 0
%28 = add nuw i64 %19, 1
br i1 %27, label %38, label %16
29: ; preds = %16, %3
%30 = bitcast %struct.hiddev_report_info* %4 to %struct.hiddev_usage_ref*
%31 = call i32 @memset(%struct.hiddev_usage_ref* %30, i32 0, i32 40)
%32 = load i8*, i8** @HID_REPORT_TYPE_OUTPUT
%33 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %4, i64 0, i32 5
store i8* %32, i8** %33
%34 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %4, i64 0, i32 0
store i32 17, i32* %34
%35 = getelementptr inbounds %struct.hiddev_report_info, %struct.hiddev_report_info* %4, i64 0, i32 4
store i32 1, i32* %35
%36 = load i32, i32* @HIDIOCSREPORT
%37 = call i32 @ioctl(i32 %0, i32 %36, %struct.hiddev_usage_ref* %30)
br label %38
38: ; preds = %18, %29
%39 = phi i32 [ %37, %29 ], [ %26, %18 ]
ret i32 %39
}