#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;
typedef int int8_t;

/* Variables and functions */
int digitalRead(int);
int /*<<< orphan*/ digitalWrite(int, int);
uint8_t shiftIn(uint8_t dPin, uint8_t cPin, uint8_t order) {
  uint8_t value = 0;
  int8_t i;
  if (order == 1)
    for (i = 7; i >= 0; --i) {
      digitalWrite(cPin, 1);
      value |= digitalRead(dPin) << i;
      digitalWrite(cPin, 0);
    }
  else
    for (i = 0; i < 8; ++i) {
      digitalWrite(cPin, 1);
      value |= digitalRead(dPin) << i;
      digitalWrite(cPin, 0);
    }
  return value;
}


x86 assembly (clang, -O0):
<shiftIn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1190 <shiftIn+0x70>
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     118b <shiftIn+0x6b>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    -0x4(%rbp),%edi
call   1030 <digitalRead@plt>
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <shiftIn+0x29>
jmp    11de <shiftIn+0xbe>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11d9 <shiftIn+0xb9>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    -0x4(%rbp),%edi
call   1030 <digitalRead@plt>
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <shiftIn+0x77>
jmp    11de <shiftIn+0xbe>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shiftIn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%r13d
mov    %esi,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r12d
cmp    $0x1,%ebp
jne    126b <shiftIn+0x14b>
shl    $0x7,%r12d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r15d
shl    $0x6,%r15d
or     %r12d,%r15d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebx
shl    $0x5,%ebx
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r12d
shl    $0x4,%r12d
or     %ebx,%r12d
or     %r15d,%r12d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r15d
shl    $0x3,%r15d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebp
shl    $0x2,%ebp
or     %r15d,%ebp
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebx
add    %eax,%ebx
or     %ebp,%ebx
or     %r12d,%ebx
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebp
jmp    1382 <shiftIn+0x262>
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r15d
add    %eax,%r15d
or     %r12d,%r15d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r12d
shl    $0x2,%r12d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r13d,%edi
call   1030 <digitalRead@plt>
mov    %r13d,%ebx
mov    %eax,%r13d
shl    $0x3,%r13d
or     %r12d,%r13d
or     %r15d,%r13d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %ebx,%r12d
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r15d
shl    $0x4,%r15d
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebp
shl    $0x5,%ebp
or     %r15d,%ebp
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebx
shl    $0x6,%ebx
or     %ebp,%ebx
or     %r13d,%ebx
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <digitalWrite@plt>
mov    %r12d,%edi
call   1030 <digitalRead@plt>
mov    %eax,%ebp
shl    $0x7,%ebp
or     %ebx,%ebp
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <digitalWrite@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @shiftIn(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %30
11: ; preds = %3
store i32 7, i32* %8
br label %12
12: ; preds = %26, %11
%13 = load i32, i32* %8
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %5
%17 = call i32 @digitalWrite(i32 %16, i32 1)
%18 = load i32, i32* %4
%19 = call i32 @digitalRead(i32 %18)
%20 = load i32, i32* %8
%21 = shl i32 %19, %20
%22 = load i32, i32* %7
%23 = or i32 %22, %21
store i32 %23, i32* %7
%24 = load i32, i32* %5
%25 = call i32 @digitalWrite(i32 %24, i32 0)
br label %26
26: ; preds = %15
%27 = load i32, i32* %8
%28 = add nsw i32 %27, -1
store i32 %28, i32* %8
br label %12
29: ; preds = %12
br label %49
30: ; preds = %3
store i32 0, i32* %8
br label %31
31: ; preds = %45, %30
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 8
br i1 %33, label %34, label %48
34: ; preds = %31
%35 = load i32, i32* %5
%36 = call i32 @digitalWrite(i32 %35, i32 1)
%37 = load i32, i32* %4
%38 = call i32 @digitalRead(i32 %37)
%39 = load i32, i32* %8
%40 = shl i32 %38, %39
%41 = load i32, i32* %7
%42 = or i32 %41, %40
store i32 %42, i32* %7
%43 = load i32, i32* %5
%44 = call i32 @digitalWrite(i32 %43, i32 0)
br label %45
45: ; preds = %34
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %31
48: ; preds = %31
br label %49
49: ; preds = %48, %29
%50 = load i32, i32* %7
ret i32 %50
}

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