#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;
struct spi_ioc_transfer {
  unsigned long tx_buf;
  unsigned long rx_buf;
  void *len;
};
typedef int /*<<< orphan*/ spi_message;

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int /*<<< orphan*/ memset(struct spi_ioc_transfer *, int /*<<< orphan*/, int);
int spi_xfer(int fd, uint8_t *tx_buffer, uint8_t tx_len, uint8_t *rx_buffer,
             uint8_t rx_len) {
  struct spi_ioc_transfer spi_message[2];
  memset(spi_message, 0, sizeof(spi_message));
  spi_message[0].tx_buf = (unsigned long)tx_buffer;
  spi_message[0].len = tx_len;
  spi_message[1].rx_buf = (unsigned long)rx_buffer;
  spi_message[1].len = rx_len;
  return ioctl(fd, SPI_IOC_MESSAGE(2), spi_message);
}


x86 assembly (clang, -O0):
<spi_xfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    $0x2,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    -0x64(%rbp),%edi
mov    %eax,%esi
lea    -0x60(%rbp),%rdx
call   1050 <ioctl@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_xfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    %rbx,(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    $0x2,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r13,%rdx
call   1050 <ioctl@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i8* }
define i32 @spi_xfer(i32 %0, i8** %1, i8* %2, i8** %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca [2 x %struct.spi_ioc_transfer]
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
store i8* %4, i8** %10
%12 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 0
%13 = call i32 @memset(%struct.spi_ioc_transfer* %12, i32 0, i32 48)
%14 = load i8**, i8*** %7
%15 = ptrtoint i8** %14 to i64
%16 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 0
%17 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %16, i32 0, i32 0
store i64 %15, i64* %17
%18 = load i8*, i8** %8
%19 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 0
%20 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %19, i32 0, i32 2
store i8* %18, i8** %20
%21 = load i8**, i8*** %9
%22 = ptrtoint i8** %21 to i64
%23 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 1
%24 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %23, i32 0, i32 1
store i64 %22, i64* %24
%25 = load i8*, i8** %10
%26 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 1
%27 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %26, i32 0, i32 2
store i8* %25, i8** %27
%28 = load i32, i32* %6
%29 = call i32 @SPI_IOC_MESSAGE(i32 2)
%30 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %11, i64 0, i64 0
%31 = call i32 @ioctl(i32 %28, i32 %29, %struct.spi_ioc_transfer* %30)
ret i32 %31
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i8* }
define i32 @spi_xfer(i32 %0, i8** %1, i8* %2, i8** %3, i8* %4) {
%6 = alloca [2 x %struct.spi_ioc_transfer]
%7 = bitcast [2 x %struct.spi_ioc_transfer]* %6 to i8*
%8 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0
%9 = call i32 @memset(%struct.spi_ioc_transfer* %8, i32 0, i32 48)
%10 = ptrtoint i8** %1 to i64
%11 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0, i32 0
store i64 %10, i64* %11
%12 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0, i32 2
store i8* %2, i8** %12
%13 = ptrtoint i8** %3 to i64
%14 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 1, i32 1
store i64 %13, i64* %14
%15 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 1, i32 2
store i8* %4, i8** %15
%16 = call i32 @SPI_IOC_MESSAGE(i32 2)
%17 = call i32 @ioctl(i32 %0, i32 %16, %struct.spi_ioc_transfer* %8)
ret i32 %17
}