#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 digitalRead(int);
int /*<<< orphan*/ sensorLowHighWait(int);
uint8_t retrieveByte(int GPIO) {
  uint8_t result = 0x00;
  for (int bit = 0; bit < 8; ++bit) {
    if (!sensorLowHighWait(GPIO)) {
      return 0;
    }
    delayMicroseconds(30);
    result <<= 1;
    if (digitalRead(GPIO) == 1) {
      result |= 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<retrieveByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11b0 <retrieveByte+0x80>
mov    -0x8(%rbp),%edi
call   1040 <sensorLowHighWait@plt>
cmp    $0x0,%eax
jne    1170 <retrieveByte+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <retrieveByte+0x86>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <digitalRead@plt>
cmp    $0x1,%eax
jne    119d <retrieveByte+0x6d>
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <retrieveByte+0x72>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <retrieveByte+0x19>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retrieveByte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
call   1040 <sensorLowHighWait@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,%r13d
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
mov    %ebx,%edi
call   1030 <digitalRead@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1040 <sensorLowHighWait@plt>
test   %eax,%eax
je     12be <retrieveByte+0x18e>
xor    %eax,%eax
cmp    $0x1,%r14d
sete   %al
xor    %ecx,%ecx
cmp    $0x1,%r15d
sete   %cl
lea    (%rcx,%rax,2),%eax
xor    %ecx,%ecx
cmp    $0x1,%r12d
sete   %cl
add    %ecx,%ecx
lea    (%rcx,%rax,4),%eax
xor    %ecx,%ecx
cmp    $0x1,%r13d
sete   %cl
or     %eax,%ecx
xor    %eax,%eax
cmpl   $0x1,0x14(%rsp)
sete   %al
add    %eax,%eax
lea    (%rax,%rcx,4),%eax
xor    %r14d,%r14d
cmpl   $0x1,0x10(%rsp)
sete   %r14b
or     %eax,%r14d
xor    %ebp,%ebp
cmpl   $0x1,0xc(%rsp)
sete   %bpl
mov    $0x1e,%edi
call   1050 <delayMicroseconds@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%r14,4),%r14d
mov    %ebx,%edi
call   1030 <digitalRead@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
or     %r14d,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @retrieveByte(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @sensorLowHighWait(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 0, i32* %2
br label %30
14: ; preds = %9
%15 = call i32 @delayMicroseconds(i32 30)
%16 = load i32, i32* %4
%17 = shl i32 %16, 1
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = call i32 @digitalRead(i32 %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %4
%23 = or i32 %22, 1
store i32 %23, i32* %4
br label %24
24: ; preds = %21, %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %6
28: ; preds = %6
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %13
%31 = load i32, i32* %2
ret i32 %31
}

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