#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*/ ClearSCK();
scalar_t__ GetMISO();
int /*<<< orphan*/ SetSCK();
int /*<<< orphan*/ waitmicrosec(int);
int SPI_In() {
  int i, b = 0;
  for (i = 7; i >= 0; i--) {
    SetSCK();
    waitmicrosec(2);
    if (GetMISO())
      b |= 1 << i;
    waitmicrosec(3);
    ClearSCK();
    waitmicrosec(2);
  }
  return b;
}


x86 assembly (clang, -O0):
<SPI_In>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x7,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     11bb <SPI_In+0x7b>
mov    $0x0,%al
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
mov    $0x0,%al
call   1060 <GetMISO@plt>
cmp    $0x0,%rax
je     1192 <SPI_In+0x52>
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
mov    $0x0,%al
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1156 <SPI_In+0x16>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPI_In>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
shl    $0x7,%ebp
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
shl    $0x6,%ebx
or     %ebp,%ebx
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
shl    $0x5,%ebp
or     %ebx,%ebp
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
shl    $0x4,%ebx
or     %ebp,%ebx
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,8),%ebx
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,4),%ebx
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rbx,%rcx,2),%ebp
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1030 <SetSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1060 <GetMISO@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
or     %ebp,%ebx
mov    $0x3,%edi
call   1040 <waitmicrosec@plt>
xor    %eax,%eax
call   1050 <ClearSCK@plt>
mov    $0x2,%edi
call   1040 <waitmicrosec@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @SPI_In() {
%1 = tail call i32 (...) @SetSCK()
%2 = tail call i32 @waitmicrosec(i32 2)
%3 = tail call i64 (...) @GetMISO()
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i32 0, i32 128
%6 = tail call i32 @waitmicrosec(i32 3)
%7 = tail call i32 (...) @ClearSCK()
%8 = tail call i32 @waitmicrosec(i32 2)
%9 = tail call i32 (...) @SetSCK()
%10 = tail call i32 @waitmicrosec(i32 2)
%11 = tail call i64 (...) @GetMISO()
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32 0, i32 64
%14 = or i32 %13, %5
%15 = tail call i32 @waitmicrosec(i32 3)
%16 = tail call i32 (...) @ClearSCK()
%17 = tail call i32 @waitmicrosec(i32 2)
%18 = tail call i32 (...) @SetSCK()
%19 = tail call i32 @waitmicrosec(i32 2)
%20 = tail call i64 (...) @GetMISO()
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 0, i32 32
%23 = or i32 %22, %14
%24 = tail call i32 @waitmicrosec(i32 3)
%25 = tail call i32 (...) @ClearSCK()
%26 = tail call i32 @waitmicrosec(i32 2)
%27 = tail call i32 (...) @SetSCK()
%28 = tail call i32 @waitmicrosec(i32 2)
%29 = tail call i64 (...) @GetMISO()
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i32 0, i32 16
%32 = or i32 %31, %23
%33 = tail call i32 @waitmicrosec(i32 3)
%34 = tail call i32 (...) @ClearSCK()
%35 = tail call i32 @waitmicrosec(i32 2)
%36 = tail call i32 (...) @SetSCK()
%37 = tail call i32 @waitmicrosec(i32 2)
%38 = tail call i64 (...) @GetMISO()
%39 = icmp eq i64 %38, 0
%40 = select i1 %39, i32 0, i32 8
%41 = or i32 %40, %32
%42 = tail call i32 @waitmicrosec(i32 3)
%43 = tail call i32 (...) @ClearSCK()
%44 = tail call i32 @waitmicrosec(i32 2)
%45 = tail call i32 (...) @SetSCK()
%46 = tail call i32 @waitmicrosec(i32 2)
%47 = tail call i64 (...) @GetMISO()
%48 = icmp eq i64 %47, 0
%49 = select i1 %48, i32 0, i32 4
%50 = or i32 %49, %41
%51 = tail call i32 @waitmicrosec(i32 3)
%52 = tail call i32 (...) @ClearSCK()
%53 = tail call i32 @waitmicrosec(i32 2)
%54 = tail call i32 (...) @SetSCK()
%55 = tail call i32 @waitmicrosec(i32 2)
%56 = tail call i64 (...) @GetMISO()
%57 = icmp eq i64 %56, 0
%58 = select i1 %57, i32 0, i32 2
%59 = or i32 %58, %50
%60 = tail call i32 @waitmicrosec(i32 3)
%61 = tail call i32 (...) @ClearSCK()
%62 = tail call i32 @waitmicrosec(i32 2)
%63 = tail call i32 (...) @SetSCK()
%64 = tail call i32 @waitmicrosec(i32 2)
%65 = tail call i64 (...) @GetMISO()
%66 = icmp ne i64 %65, 0
%67 = zext i1 %66 to i32
%68 = or i32 %59, %67
%69 = tail call i32 @waitmicrosec(i32 3)
%70 = tail call i32 (...) @ClearSCK()
%71 = tail call i32 @waitmicrosec(i32 2)
ret i32 %68
}