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

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int transfer(int fd, uint16_t word) {
  struct spi_ioc_transfer transfer = {
      .tx_buf = (unsigned long)&word,
      .rx_buf = (unsigned long)NULL,
      .len = 2,
      .speed_hz = 0,
      .bits_per_word = 9,
  };
  return ioctl(fd, SPI_IOC_MESSAGE(1), &transfer);
}


x86 assembly (clang, -O0):
<transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x9,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movabs $0x900000002,%rax
mov    %rax,0x20(%rsp)
movl   $0x0,0x28(%rsp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i32, i32, i32 }
define i32 @transfer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.spi_ioc_transfer
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i32 0, i32 0
%7 = ptrtoint i32* %4 to i64
store i64 %7, i64* %6
%8 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i32 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i32 0, i32 2
store i32 2, i32* %9
%10 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i32 0, i32 3
store i32 9, i32* %10
%11 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i32 0, i32 4
store i32 0, i32* %11
%12 = load i32, i32* %3
%13 = call i32 @SPI_IOC_MESSAGE(i32 1)
%14 = call i32 @ioctl(i32 %12, i32 %13, %struct.spi_ioc_transfer* %5)
ret i32 %14
}

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