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

/* Variables and functions */
int SPI_CS_HIGH;
int send_buffer(int, struct spi_ioc_transfer *, int);
int test_aardvark(int fd, uint8_t mode) {
  uint8_t tx_buf[66] = {
      0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x1A, 0x1C, 0x1C, 0x1D, 0x1E,
      0x1F, 0x1A, 0x1C, 0x1C, 0x1D, 0x1E, 0x1F, 0x1A, 0x1B, 0x1C, 0x1D,
      0x1E, 0x1F, 0x1A, 0x1F, 0x1C, 0x1D, 0x1E, 0x1F, 0x1A, 0x2A, 0x1C,
      0x1D, 0x1E, 0x1F, 0x1A, 0x1B, 0x3B, 0x1D, 0x1E, 0x1F, 0x2F, 0x5A,
      0x8B, 0x1F, 0x1A, 0x1B, 0x3B, 0x1D, 0x1E, 0x1F, 0x2F, 0x5A, 0x8B,
      0x1F, 0x1A, 0x1B, 0x3B, 0x1D, 0x1E, 0x1F, 0x2F, 0x5A, 0x8B, 0x1F,
  };
  uint8_t rx_buf[(int)(sizeof(tx_buf) / sizeof((tx_buf)[0]))] = {0};
  struct spi_ioc_transfer data = {
      .tx_buf = (unsigned long)tx_buf,
      .rx_buf = (unsigned long)rx_buf,
      .bits_per_word = 8,
      .cs_change = 0,
      .len = (int)(sizeof(tx_buf) / sizeof((tx_buf)[0])),
  };
  return send_buffer(fd, &data, mode & ~SPI_CS_HIGH);
}


x86 assembly (clang, -O0):
<test_aardvark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xeb1(%rip),%rsi
mov    $0x108,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x108,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x238(%rbp)
movl   $0x8,-0x230(%rbp)
movl   $0x42,-0x22c(%rbp)
movl   $0x0,-0x228(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
lea    -0x240(%rbp),%rsi
call   1030 <send_buffer@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_aardvark>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x238,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
lea    0xeb6(%rip),%rsi
lea    0x130(%rsp),%rbx
mov    $0x108,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
lea    0x20(%rsp),%rbp
mov    $0x108,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,(%rsp)
mov    %rbp,0x8(%rsp)
movabs $0x4200000008,%rax
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
not    %edx
and    %r15d,%edx
mov    %rsp,%rsi
mov    %r14d,%edi
call   1030 <send_buffer@plt>
add    $0x238,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i32, i32, i32 }
@__const.test_aardvark.tx_buf = [66 x i32] [i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 26, i32 28, i32 28, i32 29, i32 30, i32 31, i32 26, i32 28, i32 28, i32 29, i32 30, i32 31, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 26, i32 31, i32 28, i32 29, i32 30, i32 31, i32 26, i32 42, i32 28, i32 29, i32 30, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31]
@SPI_CS_HIGH = global i32 0
define i32 @test_aardvark(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [66 x i32]
%6 = alloca [66 x i32]
%7 = alloca %struct.spi_ioc_transfer
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [66 x i32]* %5 to i8*
%9 = bitcast [66 x i32]* %6 to i8*
%10 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %7, i32 0, i32 0
%11 = getelementptr inbounds [66 x i32], [66 x i32]* %5, i64 0, i64 0
%12 = ptrtoint i32* %11 to i64
store i64 %12, i64* %10
%13 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %7, i32 0, i32 1
%14 = getelementptr inbounds [66 x i32], [66 x i32]* %6, i64 0, i64 0
%15 = ptrtoint i32* %14 to i64
store i64 %15, i64* %13
%16 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %7, i32 0, i32 2
store i32 8, i32* %16
%17 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %7, i32 0, i32 3
store i32 66, i32* %17
%18 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %7, i32 0, i32 4
store i32 0, i32* %18
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = load i32, i32* @SPI_CS_HIGH
%22 = xor i32 %21, -1
%23 = and i32 %20, %22
%24 = call i32 @send_buffer(i32 %19, %struct.spi_ioc_transfer* %7, i32 %23)
ret i32 %24
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i32, i32, i32 }
@__const.test_aardvark.tx_buf = [66 x i32] [i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 26, i32 28, i32 28, i32 29, i32 30, i32 31, i32 26, i32 28, i32 28, i32 29, i32 30, i32 31, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 26, i32 31, i32 28, i32 29, i32 30, i32 31, i32 26, i32 42, i32 28, i32 29, i32 30, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31, i32 26, i32 27, i32 59, i32 29, i32 30, i32 31, i32 47, i32 90, i32 139, i32 31]
@SPI_CS_HIGH = global i32 0
define i32 @test_aardvark(i32 %0, i32 %1) {
%3 = alloca [66 x i32]
%4 = alloca [66 x i32]
%5 = alloca %struct.spi_ioc_transfer
%6 = bitcast [66 x i32]* %3 to i8*
%7 = bitcast [66 x i32]* %4 to i8*
%8 = bitcast %struct.spi_ioc_transfer* %5 to i8*
%9 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 0
%10 = ptrtoint [66 x i32]* %3 to i64
store i64 %10, i64* %9
%11 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 1
%12 = ptrtoint [66 x i32]* %4 to i64
store i64 %12, i64* %11
%13 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 2
store i32 8, i32* %13
%14 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 3
store i32 66, i32* %14
%15 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 4
store i32 0, i32* %15
%16 = load i32, i32* @SPI_CS_HIGH
%17 = xor i32 %16, -1
%18 = and i32 %17, %1
%19 = call i32 @send_buffer(i32 %0, %struct.spi_ioc_transfer* %5, i32 %18)
ret i32 %19
}