#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 */
struct usbdevfs_bulktransfer {
  int ep;
  int len;
  char *data;
  int timeout;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ USBDEVFS_BULK;
int ioctl(int, int /*<<< orphan*/, struct usbdevfs_bulktransfer *);
int bulk_talk(int fd, int endpoint, char *buffer, int length) {
  const int kTimeoutMs = 20;
  struct usbdevfs_bulktransfer ctrl = {0};
  ctrl.ep = endpoint;
  ctrl.len = length;
  ctrl.data = buffer;
  ctrl.timeout = kTimeoutMs;
  int ret = ioctl(fd, USBDEVFS_BULK, &ctrl);
  return ret;
}


x86 assembly (clang, -O0):
<bulk_talk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x14,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x14,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bulk_talk>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
mov    %esi,(%rsp)
mov    %ecx,0x4(%rsp)
mov    %rdx,0x8(%rsp)
movl   $0x14,0x10(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.usbdevfs_bulktransfer = type { i32, i32, i8*, i32, i32 }
@USBDEVFS_BULK = global i32 0
define i32 @bulk_talk(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.usbdevfs_bulktransfer
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 20, i32* %9
%12 = bitcast %struct.usbdevfs_bulktransfer* %10 to i8*
%13 = load i32, i32* %6
%14 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %10, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* %8
%16 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %10, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i8*, i8** %7
%18 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %10, i32 0, i32 2
store i8* %17, i8** %18
%19 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %10, i32 0, i32 3
store i32 20, i32* %19
%20 = load i32, i32* %5
%21 = load i32, i32* @USBDEVFS_BULK
%22 = call i32 @ioctl(i32 %20, i32 %21, %struct.usbdevfs_bulktransfer* %10)
store i32 %22, i32* %11
%23 = load i32, i32* %11
ret i32 %23
}

LLVM IR (-O2):
%struct.usbdevfs_bulktransfer = type { i32, i32, i8*, i32, i32 }
@USBDEVFS_BULK = global i32 0
define i32 @bulk_talk(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.usbdevfs_bulktransfer
%6 = bitcast %struct.usbdevfs_bulktransfer* %5 to i8*
%7 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %5, i64 0, i32 3
%8 = bitcast i32* %7 to i64*
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %5, i64 0, i32 0
store i32 %1, i32* %9
%10 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %5, i64 0, i32 1
store i32 %3, i32* %10
%11 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %5, i64 0, i32 2
store i8* %2, i8** %11
%12 = getelementptr inbounds %struct.usbdevfs_bulktransfer, %struct.usbdevfs_bulktransfer* %5, i64 0, i32 3
store i32 20, i32* %12
%13 = load i32, i32* @USBDEVFS_BULK
%14 = call i32 @ioctl(i32 %0, i32 %13, %struct.usbdevfs_bulktransfer* %5)
ret i32 %14
}