#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 spi_ioc_transfer {
  unsigned long tx_buf;
  unsigned long rx_buf;
  size_t len;
  int /*<<< orphan*/ bits_per_word;
  int /*<<< orphan*/ speed_hz;
  int /*<<< orphan*/ delay_usecs;
};

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int Transfer_spi_buffers(int fd, void *tx_buffer, void *rx_buffer,
                         size_t length) {
  struct spi_ioc_transfer transfer = {
      .tx_buf = 0,
      .rx_buf = 0,
      .len = 0,
      .delay_usecs = 0,
      .speed_hz = 0,
      .bits_per_word = 0,
  };
  transfer.rx_buf = (unsigned long)rx_buffer;
  transfer.tx_buf = (unsigned long)tx_buffer;
  transfer.len = length;
  if (ioctl(fd, SPI_IOC_MESSAGE(1), &transfer) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<Transfer_spi_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
lea    -0x48(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11a3 <Transfer_spi_buffers+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <Transfer_spi_buffers+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Transfer_spi_buffers>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rcx,0x18(%rsp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
sar    $0x3f,%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i64, i32, i32, i32 }
define i32 @Transfer_spi_buffers(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.spi_ioc_transfer
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = bitcast %struct.spi_ioc_transfer* %10 to i8*
%12 = load i8*, i8** %8
%13 = ptrtoint i8* %12 to i64
%14 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 1
store i64 %13, i64* %14
%15 = load i8*, i8** %7
%16 = ptrtoint i8* %15 to i64
%17 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 0
store i64 %16, i64* %17
%18 = load i64, i64* %9
%19 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 2
store i64 %18, i64* %19
%20 = load i32, i32* %6
%21 = call i32 @SPI_IOC_MESSAGE(i32 1)
%22 = call i64 @ioctl(i32 %20, i32 %21, %struct.spi_ioc_transfer* %10)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
br label %26
25: ; preds = %4
store i32 0, i32* %5
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i64, i32, i32, i32 }
define i32 @Transfer_spi_buffers(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca %struct.spi_ioc_transfer
%6 = bitcast %struct.spi_ioc_transfer* %5 to i8*
%7 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 3
%8 = bitcast i32* %7 to i8*
%9 = ptrtoint i8* %2 to i64
%10 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 1
store i64 %9, i64* %10
%11 = ptrtoint i8* %1 to i64
%12 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 0
store i64 %11, i64* %12
%13 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 2
store i64 %3, i64* %13
%14 = tail call i32 @SPI_IOC_MESSAGE(i32 1)
%15 = call i64 @ioctl(i32 %0, i32 %14, %struct.spi_ioc_transfer* %5)
%16 = ashr i64 %15, 63
%17 = trunc i64 %16 to i32
ret i32 %17
}