#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 */
int /*<<< orphan*/ cts_bit(int);
int /*<<< orphan*/ delay1u5();
unsigned char rx_bit();
int /*<<< orphan*/ tx_bit(unsigned char);
unsigned char spi_slow_wr(register unsigned char data) {
  register int cnt;
  for (cnt = 0; cnt < 8; cnt++) {
    tx_bit(data & 0x80);
    delay1u5();
    cts_bit(1);
    data = (data << 1) | rx_bit();
    delay1u5();
    cts_bit(0);
  }
  return (data);
}


x86 assembly (clang, -O0):
<spi_slow_wr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    11bb <spi_slow_wr+0x7b>
movzbl -0x1(%rbp),%eax
and    $0x80,%eax
movzbl %al,%edi
call   1040 <tx_bit@plt>
mov    $0x0,%al
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <rx_bit@plt>
mov    %al,%cl
mov    -0xc(%rbp),%eax
movzbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <spi_slow_wr+0x15>
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_slow_wr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
and    $0xffffff80,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
lea    (%rbx,%rbx,1),%ebp
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebx
or     %bpl,%bl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebx,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bl,%bl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebp,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bpl,%bpl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebx
or     %bpl,%bl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebx,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bl,%bl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebp,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bpl,%bpl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebx
or     %bpl,%bl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebx,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bl,%bl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebp,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bpl,%bpl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebx
or     %bpl,%bl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebx,%eax
and    $0x80,%al
movzbl %al,%edi
call   1040 <tx_bit@plt>
xor    %eax,%eax
call   1050 <delay1u5@plt>
mov    $0x1,%edi
call   1030 <cts_bit@plt>
add    %bl,%bl
xor    %eax,%eax
call   1060 <rx_bit@plt>
mov    %eax,%ebp
or     %bl,%bpl
xor    %eax,%eax
call   1050 <delay1u5@plt>
xor    %edi,%edi
call   1030 <cts_bit@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @spi_slow_wr(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %3
br label %4
4: ; preds = %24, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %27
7: ; preds = %4
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = and i32 %9, 128
%11 = trunc i32 %10 to i8
%12 = call i32 @tx_bit(i8 zeroext %11)
%13 = call i32 (...) @delay1u5()
%14 = call i32 @cts_bit(i32 1)
%15 = load i8, i8* %2
%16 = zext i8 %15 to i32
%17 = shl i32 %16, 1
%18 = call zeroext i8 (...) @rx_bit()
%19 = zext i8 %18 to i32
%20 = or i32 %17, %19
%21 = trunc i32 %20 to i8
store i8 %21, i8* %2
%22 = call i32 (...) @delay1u5()
%23 = call i32 @cts_bit(i32 0)
br label %24
24: ; preds = %7
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %4
27: ; preds = %4
%28 = load i8, i8* %2
ret i8 %28
}

LLVM IR (-O2):
define zeroext i8 @spi_slow_wr(i8 zeroext %0) {
%2 = and i8 %0, -128
%3 = tail call i32 @tx_bit(i8 zeroext %2)
%4 = tail call i32 (...) @delay1u5()
%5 = tail call i32 @cts_bit(i32 1)
%6 = shl i8 %0, 1
%7 = tail call zeroext i8 (...) @rx_bit()
%8 = or i8 %7, %6
%9 = tail call i32 (...) @delay1u5()
%10 = tail call i32 @cts_bit(i32 0)
%11 = and i8 %8, -128
%12 = tail call i32 @tx_bit(i8 zeroext %11)
%13 = tail call i32 (...) @delay1u5()
%14 = tail call i32 @cts_bit(i32 1)
%15 = shl i8 %8, 1
%16 = tail call zeroext i8 (...) @rx_bit()
%17 = or i8 %16, %15
%18 = tail call i32 (...) @delay1u5()
%19 = tail call i32 @cts_bit(i32 0)
%20 = and i8 %17, -128
%21 = tail call i32 @tx_bit(i8 zeroext %20)
%22 = tail call i32 (...) @delay1u5()
%23 = tail call i32 @cts_bit(i32 1)
%24 = shl i8 %17, 1
%25 = tail call zeroext i8 (...) @rx_bit()
%26 = or i8 %25, %24
%27 = tail call i32 (...) @delay1u5()
%28 = tail call i32 @cts_bit(i32 0)
%29 = and i8 %26, -128
%30 = tail call i32 @tx_bit(i8 zeroext %29)
%31 = tail call i32 (...) @delay1u5()
%32 = tail call i32 @cts_bit(i32 1)
%33 = shl i8 %26, 1
%34 = tail call zeroext i8 (...) @rx_bit()
%35 = or i8 %34, %33
%36 = tail call i32 (...) @delay1u5()
%37 = tail call i32 @cts_bit(i32 0)
%38 = and i8 %35, -128
%39 = tail call i32 @tx_bit(i8 zeroext %38)
%40 = tail call i32 (...) @delay1u5()
%41 = tail call i32 @cts_bit(i32 1)
%42 = shl i8 %35, 1
%43 = tail call zeroext i8 (...) @rx_bit()
%44 = or i8 %43, %42
%45 = tail call i32 (...) @delay1u5()
%46 = tail call i32 @cts_bit(i32 0)
%47 = and i8 %44, -128
%48 = tail call i32 @tx_bit(i8 zeroext %47)
%49 = tail call i32 (...) @delay1u5()
%50 = tail call i32 @cts_bit(i32 1)
%51 = shl i8 %44, 1
%52 = tail call zeroext i8 (...) @rx_bit()
%53 = or i8 %52, %51
%54 = tail call i32 (...) @delay1u5()
%55 = tail call i32 @cts_bit(i32 0)
%56 = and i8 %53, -128
%57 = tail call i32 @tx_bit(i8 zeroext %56)
%58 = tail call i32 (...) @delay1u5()
%59 = tail call i32 @cts_bit(i32 1)
%60 = shl i8 %53, 1
%61 = tail call zeroext i8 (...) @rx_bit()
%62 = or i8 %61, %60
%63 = tail call i32 (...) @delay1u5()
%64 = tail call i32 @cts_bit(i32 0)
%65 = and i8 %62, -128
%66 = tail call i32 @tx_bit(i8 zeroext %65)
%67 = tail call i32 (...) @delay1u5()
%68 = tail call i32 @cts_bit(i32 1)
%69 = shl i8 %62, 1
%70 = tail call zeroext i8 (...) @rx_bit()
%71 = or i8 %70, %69
%72 = tail call i32 (...) @delay1u5()
%73 = tail call i32 @cts_bit(i32 0)
ret i8 %71
}