#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 */

/* Variables and functions */
unsigned char spi_byte(unsigned char);
void spi_frame(unsigned char *pTx, unsigned char *pRx, unsigned char count) {
  unsigned char tx = 0;
  unsigned char rx;
  while (count > 0) {
    if (pTx != NULL) {
      tx = *(pTx++);
    }
    rx = spi_byte(tx);
    if (pRx != NULL) {
      *(pRx++) = rx;
    }
    count--;
  }
}


x86 assembly (clang, -O0):
<spi_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jle    118d <spi_frame+0x7d>
cmpq   $0x0,-0x8(%rbp)
je     1155 <spi_frame+0x45>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%edi
call   1030 <spi_byte@plt>
mov    %al,-0x13(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1180 <spi_frame+0x70>
mov    -0x13(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x11(%rbp),%al
add    $0xff,%al
mov    %al,-0x11(%rbp)
jmp    1129 <spi_frame+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_frame>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1169 <spi_frame+0x59>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r12d,%r12d
jmp    113c <spi_frame+0x2c>
nopl   0x0(%rax)
mov    %al,(%r14)
add    $0x1,%r14
add    $0xff,%bl
je     1169 <spi_frame+0x59>
test   %r15,%r15
je     1150 <spi_frame+0x40>
movzbl (%r15),%r12d
add    $0x1,%r15
jmp    1153 <spi_frame+0x43>
nopl   0x0(%rax,%rax,1)
xor    %r15d,%r15d
movzbl %r12b,%edi
call   1030 <spi_byte@plt>
test   %r14,%r14
jne    1130 <spi_frame+0x20>
xor    %r14d,%r14d
add    $0xff,%bl
jne    113c <spi_frame+0x2c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @spi_frame(i8* %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
store i8 0, i8* %7
br label %9
9: ; preds = %29, %3
%10 = load i8, i8* %6
%11 = zext i8 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
%19 = load i8, i8* %17
store i8 %19, i8* %7
br label %20
20: ; preds = %16, %13
%21 = load i8, i8* %7
%22 = call zeroext i8 @spi_byte(i8 zeroext %21)
store i8 %22, i8* %8
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i8, i8* %8
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 %26, i8* %27
br label %29
29: ; preds = %25, %20
%30 = load i8, i8* %6
%31 = add i8 %30, -1
store i8 %31, i8* %6
br label %9
32: ; preds = %9
ret void
}

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