#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 /*<<< orphan*/ digitalWrite(int, int);
void shiftOut(uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) {
  int8_t i;
  if (order == 1)
    for (i = 7; i >= 0; --i) {
      digitalWrite(dPin, val & (1 << i));
      digitalWrite(cPin, 1);
      digitalWrite(cPin, 0);
    }
  else
    for (i = 0; i < 8; ++i) {
      digitalWrite(dPin, val & (1 << i));
      digitalWrite(cPin, 1);
      digitalWrite(cPin, 0);
    }
}


x86 assembly (clang, -O0):
<shiftOut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1180 <shiftOut+0x70>
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     117b <shiftOut+0x6b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%esi
call   1030 <digitalWrite@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <shiftOut+0x25>
jmp    11d2 <shiftOut+0xc2>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11cd <shiftOut+0xbd>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%esi
call   1030 <digitalWrite@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <shiftOut+0x77>
jmp    11d2 <shiftOut+0xc2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shiftOut>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%r13d
xor    %r10d,%r10d
xor    %eax,%eax
cmp    $0x1,%edx
setne  %r10b
mov    $0x80,%edi
mov    $0x1,%esi
cmove  %edi,%esi
mov    $0x80,%edi
sete   %al
mov    $0x40,%ebp
mov    $0x2,%r8d
mov    $0x2,%r12d
cmove  %ebp,%r12d
mov    $0x40,%ebp
mov    $0x20,%r14d
mov    $0x4,%r9d
mov    $0x4,%r15d
cmove  %r14d,%r15d
lea    0x8(,%rax,8),%eax
mov    %eax,0x8(%rsp)
cmove  %r9d,%r14d
cmove  %r8d,%ebp
mov    %ebp,0x10(%rsp)
lea    0x8(,%r10,8),%eax
mov    %eax,0xc(%rsp)
cmove  %edx,%edi
mov    %edi,0x14(%rsp)
mov    %ecx,%ebp
and    %ecx,%esi
mov    %r13d,%edi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
and    %ebp,%r12d
mov    %r13d,%edi
mov    %r12d,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
and    %ebp,%r15d
mov    %r13d,%edi
mov    %r15d,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    0x8(%rsp),%esi
and    %ebp,%esi
mov    %r13d,%edi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    0xc(%rsp),%esi
and    %ebp,%esi
mov    %r13d,%edi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
and    %ebp,%r14d
mov    %r13d,%edi
mov    %r14d,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    0x10(%rsp),%esi
and    %ebp,%esi
mov    %r13d,%edi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <digitalWrite@plt>
mov    0x14(%rsp),%esi
and    %ebp,%esi
mov    %r13d,%edi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <digitalWrite@plt>
mov    %ebx,%edi
xor    %esi,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <digitalWrite@plt>

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

LLVM IR (-O2):
define void @shiftOut(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 1
%6 = select i1 %5, i32 128, i32 1
%7 = select i1 %5, i32 64, i32 2
%8 = select i1 %5, i32 32, i32 4
%9 = select i1 %5, i32 16, i32 8
%10 = select i1 %5, i32 8, i32 16
%11 = select i1 %5, i32 4, i32 32
%12 = select i1 %5, i32 2, i32 64
%13 = select i1 %5, i32 1, i32 128
%14 = and i32 %6, %3
%15 = tail call i32 @digitalWrite(i32 %0, i32 %14)
%16 = tail call i32 @digitalWrite(i32 %1, i32 1)
%17 = tail call i32 @digitalWrite(i32 %1, i32 0)
%18 = and i32 %7, %3
%19 = tail call i32 @digitalWrite(i32 %0, i32 %18)
%20 = tail call i32 @digitalWrite(i32 %1, i32 1)
%21 = tail call i32 @digitalWrite(i32 %1, i32 0)
%22 = and i32 %8, %3
%23 = tail call i32 @digitalWrite(i32 %0, i32 %22)
%24 = tail call i32 @digitalWrite(i32 %1, i32 1)
%25 = tail call i32 @digitalWrite(i32 %1, i32 0)
%26 = and i32 %9, %3
%27 = tail call i32 @digitalWrite(i32 %0, i32 %26)
%28 = tail call i32 @digitalWrite(i32 %1, i32 1)
%29 = tail call i32 @digitalWrite(i32 %1, i32 0)
%30 = and i32 %10, %3
%31 = tail call i32 @digitalWrite(i32 %0, i32 %30)
%32 = tail call i32 @digitalWrite(i32 %1, i32 1)
%33 = tail call i32 @digitalWrite(i32 %1, i32 0)
%34 = and i32 %11, %3
%35 = tail call i32 @digitalWrite(i32 %0, i32 %34)
%36 = tail call i32 @digitalWrite(i32 %1, i32 1)
%37 = tail call i32 @digitalWrite(i32 %1, i32 0)
%38 = and i32 %12, %3
%39 = tail call i32 @digitalWrite(i32 %0, i32 %38)
%40 = tail call i32 @digitalWrite(i32 %1, i32 1)
%41 = tail call i32 @digitalWrite(i32 %1, i32 0)
%42 = and i32 %13, %3
%43 = tail call i32 @digitalWrite(i32 %0, i32 %42)
%44 = tail call i32 @digitalWrite(i32 %1, i32 1)
%45 = tail call i32 @digitalWrite(i32 %1, i32 0)
ret void
}