#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;

/* Variables and functions */
int /*<<< orphan*/ delayMicroseconds(int);
int /*<<< orphan*/ gpio_set_value(int, int);
void shiftOut(uint8_t bitOrder, uint8_t val) {
  uint8_t i;
  for (i = 0; i < 8; i++) {
    if (bitOrder == 0) {
      gpio_set_value(38, !!(val & (1 << i)));
    } else {
      gpio_set_value(38, !!(val & (1 << ((8 - 1 - i)))));
      gpio_set_value(40, 1);
      delayMicroseconds(80);
      gpio_set_value(40, 0);
    }
  }
}


x86 assembly (clang, -O0):
<shiftOut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11df <shiftOut+0xbf>
cmpl   $0x0,-0x4(%rbp)
jne    1178 <shiftOut+0x58>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
mov    $0x26,%edi
call   1040 <gpio_set_value@plt>
jmp    11cc <shiftOut+0xac>
mov    -0x8(%rbp),%eax
mov    $0x7,%ecx
sub    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
mov    $0x26,%edi
call   1040 <gpio_set_value@plt>
mov    $0x28,%edi
mov    $0x1,%esi
call   1040 <gpio_set_value@plt>
mov    $0x50,%edi
call   1030 <delayMicroseconds@plt>
mov    $0x28,%edi
xor    %esi,%esi
call   1040 <gpio_set_value@plt>
jmp    11d1 <shiftOut+0xb1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <shiftOut+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shiftOut>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
xor    %ebx,%ebx
mov    $0x7,%ebp
jmp    1181 <shiftOut+0x61>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    $0x26,%edi
call   1040 <gpio_set_value@plt>
mov    $0x28,%edi
mov    $0x1,%esi
call   1040 <gpio_set_value@plt>
mov    $0x50,%edi
call   1030 <delayMicroseconds@plt>
mov    $0x28,%edi
xor    %esi,%esi
call   1040 <gpio_set_value@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    $0x8,%ebx
je     1197 <shiftOut+0x77>
mov    %r14d,%esi
test   %r15d,%r15d
jne    1140 <shiftOut+0x20>
mov    %ebx,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    $0x26,%edi
jmp    1171 <shiftOut+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shiftOut(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %37, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = shl i32 1, %14
%16 = and i32 %13, %15
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = xor i1 %18, true
%20 = zext i1 %19 to i32
%21 = call i32 @gpio_set_value(i32 38, i32 %20)
br label %36
22: ; preds = %9
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = sub nsw i32 7, %24
%26 = shl i32 1, %25
%27 = and i32 %23, %26
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
%32 = call i32 @gpio_set_value(i32 38, i32 %31)
%33 = call i32 @gpio_set_value(i32 40, i32 1)
%34 = call i32 @delayMicroseconds(i32 80)
%35 = call i32 @gpio_set_value(i32 40, i32 0)
br label %36
36: ; preds = %22, %12
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %6
40: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @shiftOut(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br label %4
4: ; preds = %2, %18
%5 = phi i32 [ 0, %2 ], [ %19, %18 ]
br i1 %3, label %6, label %10
6: ; preds = %4
%7 = lshr i32 %1, %5
%8 = and i32 %7, 1
%9 = tail call i32 @gpio_set_value(i32 38, i32 %8)
br label %18
10: ; preds = %4
%11 = sub nuw nsw i32 7, %5
%12 = lshr i32 %1, %11
%13 = and i32 %12, 1
%14 = tail call i32 @gpio_set_value(i32 38, i32 %13)
%15 = tail call i32 @gpio_set_value(i32 40, i32 1)
%16 = tail call i32 @delayMicroseconds(i32 80)
%17 = tail call i32 @gpio_set_value(i32 40, i32 0)
br label %18
18: ; preds = %6, %10
%19 = add nuw nsw i32 %5, 1
%20 = icmp eq i32 %19, 8
br i1 %20, label %21, label %4
21: ; preds = %18
ret void
}