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

/* Variables and functions */
int /*<<< orphan*/ fill_random_buffer(int /*<<< orphan*/ *, int);
int send_all_loopback_buffer(int, struct spi_ioc_transfer *);
int test_loopback(int fd) {
  uint8_t tx_buf[16] = {0};
  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,
      .len = (int)(sizeof(tx_buf) / sizeof((tx_buf)[0])),
  };
  fill_random_buffer(tx_buf, (int)(sizeof(tx_buf) / sizeof((tx_buf)[0])));
  return send_all_loopback_buffer(fd, &data);
}


x86 assembly (clang, -O0):
<test_loopback>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x10,-0x98(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x10,%esi
call   1050 <fill_random_buffer@plt>
mov    -0x4(%rbp),%edi
lea    -0xa8(%rbp),%rsi
call   1040 <send_all_loopback_buffer@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_loopback>:
push   %rbx
sub    $0xa0,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x60(%rsp),%rdi
mov    %rdi,0x8(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x10,0x18(%rsp)
mov    $0x10,%esi
call   1040 <fill_random_buffer@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1030 <send_all_loopback_buffer@plt>
add    $0xa0,%rsp
pop    %rbx
ret

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

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