#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*/ uint8_t;
typedef void *uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct spi_ioc_transfer {
  unsigned long tx_buf;
  unsigned long member_0;
  unsigned long rx_buf;
  unsigned long member_1;
  int /*<<< orphan*/ member_5;
  int /*<<< orphan*/ bits_per_word;
  void *member_4;
  void *speed_hz;
  int /*<<< orphan*/ member_3;
  int /*<<< orphan*/ delay_usecs;
  void *member_2;
  void *len;
};

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ errorMessage(char *, int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int spiTransfer(int fileDescriptor, unsigned int *txBuffer,
                unsigned int *rxBuffer, int transferLength, int delay,
                int speed, int bitsPerWord) {
  struct spi_ioc_transfer tr = {
      tr.tx_buf = (unsigned long)txBuffer,
      tr.rx_buf = (unsigned long)rxBuffer,
      tr.len = (uint32_t)transferLength,
      tr.delay_usecs = (uint16_t)delay,
      tr.speed_hz = (uint32_t)speed,
      tr.bits_per_word = (uint8_t)bitsPerWord,
  };
  int ret = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), &tr);
  if (ret < 0) {
    errorMessage("spi message transfer failed: %s", strerror(errno));
  }
  return ret;
}


x86 assembly (clang, -O0):
<spiTransfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    %rax,-0x70(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cltq
mov    %rax,-0x60(%rbp)
movslq -0x24(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    %eax,-0x58(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    %eax,-0x54(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
mov    -0x80(%rbp),%edi
mov    %eax,%esi
lea    -0x78(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jge    121d <spiTransfer+0xdd>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xde8(%rip),%rdi
call   1050 <errorMessage@plt>
mov    -0x7c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spiTransfer>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    0x60(%rsp),%eax
mov    %rsi,(%rsp)
mov    %rdx,0x8(%rsp)
movslq %ecx,%rcx
mov    %rcx,0x10(%rsp)
movslq %r8d,%rcx
mov    %rcx,0x18(%rsp)
mov    %r9d,0x20(%rsp)
mov    %eax,0x24(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movups %xmm0,0x38(%rsp)
movq   $0x0,0x48(%rsp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11bb <spiTransfer+0x7b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
call   1050 <errorMessage@plt>
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i64, i64, i32, i32, i8*, i8*, i32, i32, i8*, i8* }
@.str = [32 x i8] c"spi message transfer failed: %s\00"
@errno = global i32 0
define i32 @spiTransfer(i32 %0, i32* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.spi_ioc_transfer
%16 = alloca i32
store i32 %0, i32* %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%17 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 0
%18 = load i32*, i32** %9
%19 = ptrtoint i32* %18 to i64
%20 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 0
store i64 %19, i64* %20
store i64 %19, i64* %17
%21 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 1
%22 = load i32*, i32** %10
%23 = ptrtoint i32* %22 to i64
%24 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 2
store i64 %23, i64* %24
store i64 %23, i64* %21
%25 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 2
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 11
store i8* %28, i8** %29
%30 = ptrtoint i8* %28 to i64
store i64 %30, i64* %25
%31 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 3
%32 = load i32, i32* %12
%33 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 9
store i32 %32, i32* %33
%34 = sext i32 %32 to i64
store i64 %34, i64* %31
%35 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 4
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i8*
%39 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 7
store i8* %38, i8** %39
%40 = ptrtoint i8* %38 to i32
store i32 %40, i32* %35
%41 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 5
%42 = load i32, i32* %14
%43 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 5
store i32 %42, i32* %43
store i32 %42, i32* %41
%44 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 6
store i8* null, i8** %44
%45 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 7
store i8* null, i8** %45
%46 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 8
store i32 0, i32* %46
%47 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 9
store i32 0, i32* %47
%48 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 10
store i8* null, i8** %48
%49 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 11
store i8* null, i8** %49
%50 = load i32, i32* %8
%51 = call i32 @SPI_IOC_MESSAGE(i32 1)
%52 = call i32 @ioctl(i32 %50, i32 %51, %struct.spi_ioc_transfer* %15)
store i32 %52, i32* %16
%53 = load i32, i32* %16
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %7
%56 = load i32, i32* @errno
%57 = call i32 @strerror(i32 %56)
%58 = call i32 @errorMessage(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %55, %7
%60 = load i32, i32* %16
ret i32 %60
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i64, i64, i32, i32, i8*, i8*, i32, i32, i8*, i8* }
@.str = [32 x i8] c"spi message transfer failed: %s\00"
@errno = global i32 0
define i32 @spiTransfer(i32 %0, i32* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca %struct.spi_ioc_transfer
%9 = bitcast %struct.spi_ioc_transfer* %8 to i8*
%10 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 0
%11 = ptrtoint i32* %1 to i64
store i64 %11, i64* %10
%12 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 1
%13 = ptrtoint i32* %2 to i64
%14 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 2
store i64 %13, i64* %12
%15 = sext i32 %3 to i64
store i64 %15, i64* %14
%16 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 3
%17 = sext i32 %4 to i64
store i64 %17, i64* %16
%18 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 4
store i32 %5, i32* %18
%19 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 5
store i32 %6, i32* %19
%20 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %8, i64 0, i32 6
%21 = bitcast i8** %20 to i8*
%22 = tail call i32 @SPI_IOC_MESSAGE(i32 1)
%23 = call i32 @ioctl(i32 %0, i32 %22, %struct.spi_ioc_transfer* %8)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %7
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 @errorMessage(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %7
ret i32 %23
}