#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*/ ClearMOSI();
int /*<<< orphan*/ ClearSCK();
int /*<<< orphan*/ SetMOSI();
int /*<<< orphan*/ SetSCK();
int /*<<< orphan*/ waitmicrosec(int);
void SPI_Out(int b) {
  int i;
  for (i = 7; i >= 0; i--) {
    if (b & (1 << i))
      ClearMOSI();
    else
      SetMOSI();
    waitmicrosec(2);
    SetSCK();
    waitmicrosec(3);
    ClearSCK();
    waitmicrosec(2);
  }
}


x86 assembly (clang, -O0):
<SPI_Out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11d3 <SPI_Out+0x83>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1192 <SPI_Out+0x42>
mov    $0x0,%al
call   1070 <ClearMOSI@plt>
jmp    1199 <SPI_Out+0x49>
mov    $0x0,%al
call   1060 <SetMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
mov    $0x0,%al
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
mov    $0x0,%al
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <SPI_Out+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPI_Out>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
test   $0x80,%bl
jne    1161 <SPI_Out+0x11>
call   1060 <SetMOSI@plt>
jmp    1166 <SPI_Out+0x16>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x40,%bl
jne    11a0 <SPI_Out+0x50>
call   1060 <SetMOSI@plt>
jmp    11a5 <SPI_Out+0x55>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x20,%bl
jne    11df <SPI_Out+0x8f>
call   1060 <SetMOSI@plt>
jmp    11e4 <SPI_Out+0x94>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x10,%bl
jne    121e <SPI_Out+0xce>
call   1060 <SetMOSI@plt>
jmp    1223 <SPI_Out+0xd3>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x8,%bl
jne    125d <SPI_Out+0x10d>
call   1060 <SetMOSI@plt>
jmp    1262 <SPI_Out+0x112>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x4,%bl
jne    129c <SPI_Out+0x14c>
call   1060 <SetMOSI@plt>
jmp    12a1 <SPI_Out+0x151>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x2,%bl
jne    12db <SPI_Out+0x18b>
call   1060 <SetMOSI@plt>
jmp    12e0 <SPI_Out+0x190>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
test   $0x1,%bl
jne    131a <SPI_Out+0x1ca>
call   1060 <SetMOSI@plt>
jmp    131f <SPI_Out+0x1cf>
call   1070 <ClearMOSI@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
pop    %rbx
jmp    1040 <waitmicrosec@plt>

LLVM IR (-O0):
define void @SPI_Out(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 7, i32* %3
br label %4
4: ; preds = %23, %1
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = shl i32 1, %9
%11 = and i32 %8, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 (...) @ClearMOSI()
br label %17
15: ; preds = %7
%16 = call i32 (...) @SetMOSI()
br label %17
17: ; preds = %15, %13
%18 = call i32 @waitmicrosec(i32 2)
%19 = call i32 (...) @SetSCK()
%20 = call i32 @waitmicrosec(i32 3)
%21 = call i32 (...) @ClearSCK()
%22 = call i32 @waitmicrosec(i32 2)
br label %23
23: ; preds = %17
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %4
26: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @SPI_Out(i32 %0) {
%2 = and i32 %0, 128
%3 = icmp eq i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 (...) @ClearMOSI()
br label %8
6: ; preds = %1
%7 = tail call i32 (...) @SetMOSI()
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @waitmicrosec(i32 2)
%10 = tail call i32 (...) @SetSCK()
%11 = tail call i32 @waitmicrosec(i32 3)
%12 = tail call i32 (...) @ClearSCK()
%13 = tail call i32 @waitmicrosec(i32 2)
%14 = and i32 %0, 64
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %8
%17 = tail call i32 (...) @ClearMOSI()
br label %20
18: ; preds = %8
%19 = tail call i32 (...) @SetMOSI()
br label %20
20: ; preds = %18, %16
%21 = tail call i32 @waitmicrosec(i32 2)
%22 = tail call i32 (...) @SetSCK()
%23 = tail call i32 @waitmicrosec(i32 3)
%24 = tail call i32 (...) @ClearSCK()
%25 = tail call i32 @waitmicrosec(i32 2)
%26 = and i32 %0, 32
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = tail call i32 (...) @ClearMOSI()
br label %32
30: ; preds = %20
%31 = tail call i32 (...) @SetMOSI()
br label %32
32: ; preds = %30, %28
%33 = tail call i32 @waitmicrosec(i32 2)
%34 = tail call i32 (...) @SetSCK()
%35 = tail call i32 @waitmicrosec(i32 3)
%36 = tail call i32 (...) @ClearSCK()
%37 = tail call i32 @waitmicrosec(i32 2)
%38 = and i32 %0, 16
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %32
%41 = tail call i32 (...) @ClearMOSI()
br label %44
42: ; preds = %32
%43 = tail call i32 (...) @SetMOSI()
br label %44
44: ; preds = %42, %40
%45 = tail call i32 @waitmicrosec(i32 2)
%46 = tail call i32 (...) @SetSCK()
%47 = tail call i32 @waitmicrosec(i32 3)
%48 = tail call i32 (...) @ClearSCK()
%49 = tail call i32 @waitmicrosec(i32 2)
%50 = and i32 %0, 8
%51 = icmp eq i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %44
%53 = tail call i32 (...) @ClearMOSI()
br label %56
54: ; preds = %44
%55 = tail call i32 (...) @SetMOSI()
br label %56
56: ; preds = %54, %52
%57 = tail call i32 @waitmicrosec(i32 2)
%58 = tail call i32 (...) @SetSCK()
%59 = tail call i32 @waitmicrosec(i32 3)
%60 = tail call i32 (...) @ClearSCK()
%61 = tail call i32 @waitmicrosec(i32 2)
%62 = and i32 %0, 4
%63 = icmp eq i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %56
%65 = tail call i32 (...) @ClearMOSI()
br label %68
66: ; preds = %56
%67 = tail call i32 (...) @SetMOSI()
br label %68
68: ; preds = %66, %64
%69 = tail call i32 @waitmicrosec(i32 2)
%70 = tail call i32 (...) @SetSCK()
%71 = tail call i32 @waitmicrosec(i32 3)
%72 = tail call i32 (...) @ClearSCK()
%73 = tail call i32 @waitmicrosec(i32 2)
%74 = and i32 %0, 2
%75 = icmp eq i32 %74, 0
br i1 %75, label %78, label %76
76: ; preds = %68
%77 = tail call i32 (...) @ClearMOSI()
br label %80
78: ; preds = %68
%79 = tail call i32 (...) @SetMOSI()
br label %80
80: ; preds = %78, %76
%81 = tail call i32 @waitmicrosec(i32 2)
%82 = tail call i32 (...) @SetSCK()
%83 = tail call i32 @waitmicrosec(i32 3)
%84 = tail call i32 (...) @ClearSCK()
%85 = tail call i32 @waitmicrosec(i32 2)
%86 = and i32 %0, 1
%87 = icmp eq i32 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %80
%89 = tail call i32 (...) @ClearMOSI()
br label %92
90: ; preds = %80
%91 = tail call i32 (...) @SetMOSI()
br label %92
92: ; preds = %90, %88
%93 = tail call i32 @waitmicrosec(i32 2)
%94 = tail call i32 (...) @SetSCK()
%95 = tail call i32 @waitmicrosec(i32 3)
%96 = tail call i32 (...) @ClearSCK()
%97 = tail call i32 @waitmicrosec(i32 2)
ret void
}