#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*/ gpio_get_value(unsigned int, unsigned int *);
int read_byte();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_block(int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/);
int digitalRead(int pin) {
  if (pin < 81) {
    write_block(1, pin, 0, 0, 0, 0);
    usleep(10000);
    return read_byte();
  } else {
    if (pin == 157) {
      pin -= 100;
    }
    unsigned int val = 0;
    gpio_get_value((unsigned int)pin, &val);
    return val;
  }
}


x86 assembly (clang, -O0):
<digitalRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x51,-0x8(%rbp)
jge    1187 <digitalRead+0x47>
mov    -0x8(%rbp),%esi
mov    $0x1,%edi
xor    %r9d,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1040 <write_block@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11b6 <digitalRead+0x76>
cmpl   $0x9d,-0x8(%rbp)
jne    119d <digitalRead+0x5d>
mov    -0x8(%rbp),%eax
sub    $0x64,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1050 <gpio_get_value@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digitalRead>:
push   %rax
mov    %edi,%esi
cmp    $0x50,%edi
jg     116e <digitalRead+0x2e>
mov    $0x1,%edi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <write_block@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
pop    %rcx
jmp    1030 <read_byte@plt>
cmp    $0x9d,%esi
mov    $0x39,%edi
cmovne %esi,%edi
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
call   1050 <gpio_get_value@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @digitalRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 81
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 @write_block(i32 1, i32 %8, i32 0, i32 0, i32 0, i32 0)
%10 = call i32 @usleep(i32 10000)
%11 = call i32 (...) @read_byte()
store i32 %11, i32* %2
br label %22
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 157
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 100
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %12
store i32 0, i32* %4
%19 = load i32, i32* %3
%20 = call i32 @gpio_get_value(i32 %19, i32* %4)
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %18, %7
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @digitalRead(i32 %0) {
%2 = alloca i32
%3 = icmp slt i32 %0, 81
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @write_block(i32 1, i32 %0, i32 0, i32 0, i32 0, i32 0)
%6 = tail call i32 @usleep(i32 10000)
%7 = tail call i32 (...) @read_byte()
br label %14
8: ; preds = %1
%9 = icmp eq i32 %0, 157
%10 = select i1 %9, i32 57, i32 %0
%11 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%12 = call i32 @gpio_get_value(i32 %10, i32* %2)
%13 = load i32, i32* %2
br label %14
14: ; preds = %8, %4
%15 = phi i32 [ %7, %4 ], [ %13, %8 ]
ret i32 %15
}