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

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int /*<<< orphan*/ printf(char *);
int transfer(int fd, char *tbuf, char *rbuf, int bytes) {
  int ret;
  struct spi_ioc_transfer tr = {
      .tx_buf = (unsigned long)tbuf,
      .rx_buf = (unsigned long)rbuf,
      .len = bytes,
  };
  ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
  if (ret == 1)
    printf("can't send spi message");
  return ret;
}


x86 assembly (clang, -O0):
<transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
lea    -0x38(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1193 <transfer+0x63>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsi,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %ecx,0x18(%rsp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
jne    1170 <transfer+0x40>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i32 }
@.str = [23 x i8] c"can't send spi message\00"
define i32 @transfer(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.spi_ioc_transfer
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 0
%12 = load i8*, i8** %6
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %11
%14 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 1
%15 = load i8*, i8** %7
%16 = ptrtoint i8* %15 to i64
store i64 %16, i64* %14
%17 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %10, i32 0, i32 2
%18 = load i32, i32* %8
store i32 %18, i32* %17
%19 = load i32, i32* %5
%20 = call i32 @SPI_IOC_MESSAGE(i32 1)
%21 = call i32 @ioctl(i32 %19, i32 %20, %struct.spi_ioc_transfer* %10)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %4
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %4
%27 = load i32, i32* %9
ret i32 %27
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i32 }
@.str = [23 x i8] c"can't send spi message\00"
define i32 @transfer(i32 %0, i8* %1, i8* %2, i32 %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
store i64 %8, i64* %7
%9 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 1
%10 = ptrtoint i8* %2 to i64
store i64 %10, i64* %9
%11 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %5, i64 0, i32 2
store i32 %3, i32* %11
%12 = tail call i32 @SPI_IOC_MESSAGE(i32 1)
%13 = call i32 @ioctl(i32 %0, i32 %12, %struct.spi_ioc_transfer* %5)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
ret i32 %13
}