#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ delay();
int gpio_in(int);
int /*<<< orphan*/ gpio_out(int, int);
uint8_t bbspi_transfer(uint8_t cspin, uint8_t val) {
  uint8_t i;
  gpio_out(11, cspin);
  delay();
  for (i = 0; i < 8; i++) {
    gpio_out(10, 0);
    if (val & 0x80) {
      gpio_out(12, 1);
    } else {
      gpio_out(12, 0);
    }
    delay();
    gpio_out(10, 1);
    val <<= 1;
    val |= gpio_in(13);
    delay();
  }
  gpio_out(10, 0);
  return val;
}


x86 assembly (clang, -O0):
<bbspi_transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    $0xb,%edi
call   1050 <gpio_out@plt>
mov    $0x0,%al
call   1040 <delay@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11e4 <bbspi_transfer+0xb4>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    -0x8(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1194 <bbspi_transfer+0x64>
mov    $0xc,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
jmp    11a0 <bbspi_transfer+0x70>
mov    $0xc,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    $0x0,%al
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0xd,%edi
call   1030 <gpio_in@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <delay@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <bbspi_transfer+0x29>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbspi_transfer>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%esi
mov    $0xb,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebx,%ebx
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebp,%ebp
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebx,%ebx
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebp,%ebp
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebx,%ebx
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebp,%ebp
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebx,%ebx
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    $0xc,%edi
call   1050 <gpio_out@plt>
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
mov    $0x1,%esi
call   1050 <gpio_out@plt>
add    %ebp,%ebp
mov    $0xd,%edi
call   1030 <gpio_in@plt>
mov    %eax,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <gpio_out@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bbspi_transfer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @gpio_out(i32 11, i32 %6)
%8 = call i32 (...) @delay()
store i32 0, i32* %5
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 8
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = call i32 @gpio_out(i32 10, i32 0)
%14 = load i32, i32* %4
%15 = and i32 %14, 128
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @gpio_out(i32 12, i32 1)
br label %21
19: ; preds = %12
%20 = call i32 @gpio_out(i32 12, i32 0)
br label %21
21: ; preds = %19, %17
%22 = call i32 (...) @delay()
%23 = call i32 @gpio_out(i32 10, i32 1)
%24 = load i32, i32* %4
%25 = shl i32 %24, 1
store i32 %25, i32* %4
%26 = call i32 @gpio_in(i32 13)
%27 = load i32, i32* %4
%28 = or i32 %27, %26
store i32 %28, i32* %4
%29 = call i32 (...) @delay()
br label %30
30: ; preds = %21
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %9
33: ; preds = %9
%34 = call i32 @gpio_out(i32 10, i32 0)
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @bbspi_transfer(i32 %0, i32 %1) {
%3 = tail call i32 @gpio_out(i32 11, i32 %0)
%4 = tail call i32 (...) @delay()
%5 = tail call i32 @gpio_out(i32 10, i32 0)
%6 = lshr i32 %1, 7
%7 = and i32 %6, 1
%8 = tail call i32 @gpio_out(i32 12, i32 %7)
%9 = tail call i32 (...) @delay()
%10 = tail call i32 @gpio_out(i32 10, i32 1)
%11 = shl i32 %1, 1
%12 = tail call i32 @gpio_in(i32 13)
%13 = or i32 %12, %11
%14 = tail call i32 (...) @delay()
%15 = tail call i32 @gpio_out(i32 10, i32 0)
%16 = lshr i32 %13, 7
%17 = and i32 %16, 1
%18 = tail call i32 @gpio_out(i32 12, i32 %17)
%19 = tail call i32 (...) @delay()
%20 = tail call i32 @gpio_out(i32 10, i32 1)
%21 = shl i32 %13, 1
%22 = tail call i32 @gpio_in(i32 13)
%23 = or i32 %22, %21
%24 = tail call i32 (...) @delay()
%25 = tail call i32 @gpio_out(i32 10, i32 0)
%26 = lshr i32 %23, 7
%27 = and i32 %26, 1
%28 = tail call i32 @gpio_out(i32 12, i32 %27)
%29 = tail call i32 (...) @delay()
%30 = tail call i32 @gpio_out(i32 10, i32 1)
%31 = shl i32 %23, 1
%32 = tail call i32 @gpio_in(i32 13)
%33 = or i32 %32, %31
%34 = tail call i32 (...) @delay()
%35 = tail call i32 @gpio_out(i32 10, i32 0)
%36 = lshr i32 %33, 7
%37 = and i32 %36, 1
%38 = tail call i32 @gpio_out(i32 12, i32 %37)
%39 = tail call i32 (...) @delay()
%40 = tail call i32 @gpio_out(i32 10, i32 1)
%41 = shl i32 %33, 1
%42 = tail call i32 @gpio_in(i32 13)
%43 = or i32 %42, %41
%44 = tail call i32 (...) @delay()
%45 = tail call i32 @gpio_out(i32 10, i32 0)
%46 = lshr i32 %43, 7
%47 = and i32 %46, 1
%48 = tail call i32 @gpio_out(i32 12, i32 %47)
%49 = tail call i32 (...) @delay()
%50 = tail call i32 @gpio_out(i32 10, i32 1)
%51 = shl i32 %43, 1
%52 = tail call i32 @gpio_in(i32 13)
%53 = or i32 %52, %51
%54 = tail call i32 (...) @delay()
%55 = tail call i32 @gpio_out(i32 10, i32 0)
%56 = lshr i32 %53, 7
%57 = and i32 %56, 1
%58 = tail call i32 @gpio_out(i32 12, i32 %57)
%59 = tail call i32 (...) @delay()
%60 = tail call i32 @gpio_out(i32 10, i32 1)
%61 = shl i32 %53, 1
%62 = tail call i32 @gpio_in(i32 13)
%63 = or i32 %62, %61
%64 = tail call i32 (...) @delay()
%65 = tail call i32 @gpio_out(i32 10, i32 0)
%66 = lshr i32 %63, 7
%67 = and i32 %66, 1
%68 = tail call i32 @gpio_out(i32 12, i32 %67)
%69 = tail call i32 (...) @delay()
%70 = tail call i32 @gpio_out(i32 10, i32 1)
%71 = shl i32 %63, 1
%72 = tail call i32 @gpio_in(i32 13)
%73 = or i32 %72, %71
%74 = tail call i32 (...) @delay()
%75 = tail call i32 @gpio_out(i32 10, i32 0)
%76 = lshr i32 %73, 7
%77 = and i32 %76, 1
%78 = tail call i32 @gpio_out(i32 12, i32 %77)
%79 = tail call i32 (...) @delay()
%80 = tail call i32 @gpio_out(i32 10, i32 1)
%81 = shl i32 %73, 1
%82 = tail call i32 @gpio_in(i32 13)
%83 = or i32 %82, %81
%84 = tail call i32 (...) @delay()
%85 = tail call i32 @gpio_out(i32 10, i32 0)
ret i32 %83
}