#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_slave {
  int dummy;
};

/* Variables and functions */
int spi_xfer(struct spi_slave *, unsigned char *, int, unsigned char *, int);
int spi_w8r8(struct spi_slave *slave, unsigned char byte) {
  unsigned char dout[2];
  unsigned char din[2];
  int ret;
  dout[0] = byte;
  dout[1] = 0;
  ret = spi_xfer(slave, dout, 16, din, 16);
  return ret < 0 ? ret : din[1];
}


x86 assembly (clang, -O0):
<spi_w8r8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0xb(%rbp)
movb   $0x0,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xb(%rbp),%rsi
lea    -0xd(%rbp),%rcx
mov    $0x10,%r8d
mov    %r8d,%edx
call   1030 <spi_xfer@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    115e <spi_w8r8+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <spi_w8r8+0x55>
movzbl -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_w8r8>:
push   %rax
mov    %sil,0x4(%rsp)
movb   $0x0,0x5(%rsp)
lea    0x4(%rsp),%rsi
lea    0x6(%rsp),%rcx
mov    $0x10,%edx
mov    $0x10,%r8d
call   1030 <spi_xfer@plt>
test   %eax,%eax
movzbl 0x7(%rsp),%ecx
cmovns %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.spi_slave = type { i32 }
define i32 @spi_w8r8(%struct.spi_slave* %0, i8 zeroext %1) {
%3 = alloca %struct.spi_slave*
%4 = alloca i8
%5 = alloca [2 x i8]
%6 = alloca [2 x i8]
%7 = alloca i32
store %struct.spi_slave* %0, %struct.spi_slave** %3
store i8 %1, i8* %4
%8 = load i8, i8* %4
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %8, i8* %9
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 0, i8* %10
%11 = load %struct.spi_slave*, %struct.spi_slave** %3
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = call i32 @spi_xfer(%struct.spi_slave* %11, i8* %12, i32 16, i8* %13, i32 16)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* %7
br label %23
19: ; preds = %2
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
br label %23
23: ; preds = %19, %17
%24 = phi i32 [ %18, %17 ], [ %22, %19 ]
ret i32 %24
}

LLVM IR (-O2):
%struct.spi_slave = type { i32 }
define i32 @spi_w8r8(%struct.spi_slave* %0, i8 zeroext %1) {
%3 = alloca [2 x i8]
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %1, i8* %5
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %7
%8 = call i32 @spi_xfer(%struct.spi_slave* %0, i8* %5, i32 16, i8* %6, i32 16)
%9 = icmp slt i32 %8, 0
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = select i1 %9, i32 %8, i32 %12
ret i32 %13
}