#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 size_t uint8_t;
typedef size_t uint32_t;

/* Variables and functions */
scalar_t__ spi_rx_is_empty(size_t *);
scalar_t__ spi_tx_is_full(size_t *);
void spi_rw(uint32_t *spi, uint8_t *data, uint8_t size) {
  uint8_t i;
  for (i = 0; i < size; ++i) {
    while (spi_tx_is_full(spi))
      ;
    spi[0x008 / 4] = data[i];
    while (spi_rx_is_empty(spi))
      ;
    data[i] = spi[0x008 / 4];
  }
}


x86 assembly (clang, -O0):
<spi_rw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b8 <spi_rw+0x98>
jmp    114f <spi_rw+0x2f>
mov    -0x8(%rbp),%rdi
call   1030 <spi_tx_is_full@plt>
cmp    $0x0,%rax
je     1167 <spi_rw+0x47>
jmp    114f <spi_rw+0x2f>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <spi_rx_is_empty@plt>
cmp    $0x0,%rax
je     1193 <spi_rw+0x73>
jmp    117b <spi_rw+0x5b>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <spi_rw+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_rw>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     117e <spi_rw+0x5e>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <spi_tx_is_full@plt>
test   %rax,%rax
jne    1140 <spi_rw+0x20>
mov    (%r15,%r12,8),%rax
mov    %rax,0x10(%rbx)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <spi_rx_is_empty@plt>
test   %rax,%rax
jne    1160 <spi_rw+0x40>
mov    0x10(%rbx),%rax
mov    %rax,(%r15,%r12,8)
add    $0x1,%r12
cmp    %r14,%r12
jne    1140 <spi_rw+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @spi_rw(i64* %0, i64* %1, i64 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64* %0, i64** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %37, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %40
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = load i64*, i64** %4
%15 = call i64 @spi_tx_is_full(i64* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i64*, i64** %5
%20 = load i64, i64* %7
%21 = getelementptr inbounds i64, i64* %19, i64 %20
%22 = load i64, i64* %21
%23 = load i64*, i64** %4
%24 = getelementptr inbounds i64, i64* %23, i64 2
store i64 %22, i64* %24
br label %25
25: ; preds = %29, %18
%26 = load i64*, i64** %4
%27 = call i64 @spi_rx_is_empty(i64* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
br label %25
30: ; preds = %25
%31 = load i64*, i64** %4
%32 = getelementptr inbounds i64, i64* %31, i64 2
%33 = load i64, i64* %32
%34 = load i64*, i64** %5
%35 = load i64, i64* %7
%36 = getelementptr inbounds i64, i64* %34, i64 %35
store i64 %33, i64* %36
br label %37
37: ; preds = %30
%38 = load i64, i64* %7
%39 = add i64 %38, 1
store i64 %39, i64* %7
br label %8
40: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @spi_rw(i64* %0, i64* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = getelementptr inbounds i64, i64* %0, i64 2
br label %7
7: ; preds = %5, %18
%8 = phi i64 [ 0, %5 ], [ %20, %18 ]
br label %9
9: ; preds = %7, %9
%10 = tail call i64 @spi_tx_is_full(i64* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %9
12: ; preds = %9
%13 = getelementptr inbounds i64, i64* %1, i64 %8
%14 = load i64, i64* %13
store i64 %14, i64* %6
br label %15
15: ; preds = %15, %12
%16 = tail call i64 @spi_rx_is_empty(i64* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %15
18: ; preds = %15
%19 = load i64, i64* %6
store i64 %19, i64* %13
%20 = add nuw i64 %8, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %22, label %7
22: ; preds = %18, %3
ret void
}