#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 int tx_buf;
  unsigned int rx_buf;
  size_t len;
};

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int spidev_msg(int fd, const char *txbuf, char *rxbuf, size_t len) {
  struct spi_ioc_transfer xfer = {
      .tx_buf = (unsigned int)txbuf,
      .rx_buf = (unsigned int)rxbuf,
      .len = len,
  };
  return ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
}


x86 assembly (clang, -O0):
<spidev_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spidev_msg>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    %rcx,0x8(%rsp)
mov    $0x1,%edi
call   1030 <SPI_IOC_MESSAGE@plt>
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i32, i32, i64 }
define i32 @spidev_msg(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 0
%8 = ptrtoint i8* %1 to i64
%9 = trunc i64 %8 to i32
store i32 %9, i32* %7
%10 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 1
%11 = ptrtoint i8* %2 to i64
%12 = trunc i64 %11 to i32
store i32 %12, i32* %10
%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 i32 @ioctl(i32 %0, i32 %14, %struct.spi_ioc_transfer* %5)
ret i32 %15
}