#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ query_report(int, int, unsigned int *, int);
void hid_reply(int fd) {
  unsigned int buf[6] = {0};
  int i;
  if (query_report(fd, 0x10, buf, 6) < 0) {
    perror("query failed");
    close(fd);
    exit(1);
  }
  printf("query result: ");
  for (i = 0; i < 6; i++) {
    printf(" %02x", buf[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hid_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rdx
mov    $0x10,%esi
mov    $0x6,%ecx
call   1080 <query_report@plt>
cmp    $0x0,%rax
jge    11b9 <hid_reply+0x59>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    11fc <hid_reply+0x9c>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ce <hid_reply+0x6e>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hid_reply>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rdx
mov    $0x10,%esi
mov    $0x6,%ecx
call   1080 <query_report@plt>
test   %rax,%rax
js     1206 <hid_reply+0xa6>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
lea    0xe76(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdf3(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"query failed\00"
@.str.1 = [15 x i8] c"query result: \00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @hid_reply(i32 %0) {
%2 = alloca i32
%3 = alloca [6 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [6 x i32]* %3 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%8 = call i64 @query_report(i32 %6, i32 16, i32* %7, i32 6)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %17
17: ; preds = %26, %15
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 6
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %17
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"query failed\00"
@.str.1 = [15 x i8] c"query result: \00"
@.str.2 = [6 x i8] c" %02x\00"
define void @hid_reply(i32 %0) {
%2 = alloca [6 x i32]
%3 = bitcast [6 x i32]* %2 to i8*
%4 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%5 = call i64 @query_report(i32 %0, i32 16, i32* %4, i32 6)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @close(i32 %0)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 2
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 3
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 4
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 5
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @putchar(i32 10)
ret void
}