#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;
struct spi_ioc_transfer {
  unsigned long tx_buf;
  int /*<<< orphan*/ 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_write(int fd, uint8_t *tx_buffer, uint8_t tx_len) {
  struct spi_ioc_transfer spi_message[1];
  memset(spi_message, 0, sizeof(spi_message));
  spi_message[0].tx_buf = (unsigned long)tx_buffer;
  spi_message[0].len = tx_len;
  return ioctl(fd, SPI_IOC_MESSAGE(1), spi_message);
}


x86 assembly (clang, -O0):
<spi_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %rbx,(%rsp)
mov    %ebp,0x8(%rsp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %r15,%rdx
call   1050 <ioctl@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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