#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 void *uint8_t;
typedef void *uint16_t;
struct usbdevfs_ctrltransfer {
  int wLength;
  int timeout;
  void *data;
  void *wValue;
  void *bRequest;
  void *bRequestType;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ USBDEVFS_CONTROL;
int doioctl(int /*<<< orphan*/, struct usbdevfs_ctrltransfer *, char const *);
int /*<<< orphan*/ printf(char *, int, int);
int doctrl(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue,
           uint16_t wIndex, uint16_t wLength, void *pvBuf, const char *pszWho) {
  struct usbdevfs_ctrltransfer CtrlMsg = {0};
  CtrlMsg.bRequestType = bmRequestType;
  CtrlMsg.bRequest = bRequest;
  CtrlMsg.wValue = wValue;
  CtrlMsg.wLength = wLength;
  CtrlMsg.timeout = 1000;
  CtrlMsg.data = pvBuf;
  int rc = doioctl(USBDEVFS_CONTROL, &CtrlMsg, pszWho);
  printf("rc=%d CtrlMsg.wLength=%d\n", rc, CtrlMsg.wLength);
  if (rc >= 0)
    return rc;
  return -1;
}


x86 assembly (clang, -O0):
<doctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,-0x68(%rbp)
movl   $0x3e8,-0x64(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%rdx
lea    -0x68(%rbp),%rsi
call   1050 <doioctl@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%esi
mov    -0x68(%rbp),%edx
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x6c(%rbp)
jl     11d2 <doctrl+0xa2>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <doctrl+0xa9>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doctrl>:
push   %rbx
sub    $0x30,%rsp
mov    0x40(%rsp),%rax
movq   $0x0,0x28(%rsp)
mov    %rdi,0x20(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %r8d,(%rsp)
movl   $0x3e8,0x4(%rsp)
mov    %r9,0x8(%rsp)
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rsi
mov    %rax,%rdx
call   1040 <doioctl@plt>
mov    %eax,%ebx
mov    (%rsp),%edx
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
test   %ebx,%ebx
mov    $0xffffffff,%eax
cmovns %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.usbdevfs_ctrltransfer = type { i32, i32, i8*, i8*, i8*, i8*, i32 }
@USBDEVFS_CONTROL = global i32 0
@.str = [26 x i8] c"rc=%d CtrlMsg.wLength=%d\0A\00"
define i32 @doctrl(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca %struct.usbdevfs_ctrltransfer
%17 = alloca i32
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
%18 = bitcast %struct.usbdevfs_ctrltransfer* %16 to i8*
%19 = load i8*, i8** %9
%20 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 5
store i8* %19, i8** %20
%21 = load i8*, i8** %10
%22 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 4
store i8* %21, i8** %22
%23 = load i8*, i8** %11
%24 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 3
store i8* %23, i8** %24
%25 = load i8*, i8** %13
%26 = ptrtoint i8* %25 to i32
%27 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 1
store i32 1000, i32* %28
%29 = load i8*, i8** %14
%30 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 2
store i8* %29, i8** %30
%31 = load i32, i32* @USBDEVFS_CONTROL
%32 = load i8*, i8** %15
%33 = call i32 @doioctl(i32 %31, %struct.usbdevfs_ctrltransfer* %16, i8* %32)
store i32 %33, i32* %17
%34 = load i32, i32* %17
%35 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %16, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %36)
%38 = load i32, i32* %17
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %7
%41 = load i32, i32* %17
store i32 %41, i32* %8
br label %43
42: ; preds = %7
store i32 -1, i32* %8
br label %43
43: ; preds = %42, %40
%44 = load i32, i32* %8
ret i32 %44
}

LLVM IR (-O2):
%struct.usbdevfs_ctrltransfer = type { i32, i32, i8*, i8*, i8*, i8*, i32 }
@USBDEVFS_CONTROL = global i32 0
@.str = [26 x i8] c"rc=%d CtrlMsg.wLength=%d\0A\00"
define i32 @doctrl(i8* %0, i8* %1, i8* %2, i8* nocapture readnone %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca %struct.usbdevfs_ctrltransfer
%9 = bitcast %struct.usbdevfs_ctrltransfer* %8 to i8*
%10 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 6
%11 = bitcast i32* %10 to i64*
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 5
store i8* %0, i8** %12
%13 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 4
store i8* %1, i8** %13
%14 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 3
store i8* %2, i8** %14
%15 = ptrtoint i8* %4 to i64
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 0
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 1
store i32 1000, i32* %18
%19 = getelementptr inbounds %struct.usbdevfs_ctrltransfer, %struct.usbdevfs_ctrltransfer* %8, i64 0, i32 2
store i8* %5, i8** %19
%20 = load i32, i32* @USBDEVFS_CONTROL
%21 = call i32 @doioctl(i32 %20, %struct.usbdevfs_ctrltransfer* %8, i8* %6)
%22 = load i32, i32* %17
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = icmp sgt i32 %21, -1
%25 = select i1 %24, i32 %21, i32 -1
ret i32 %25
}