#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 */
unsigned long ca5_readR(unsigned int);
int pinRead(int pin) {
  int bank = pin >> 5;
  int index = pin - (bank << 5);
  int val;
  unsigned int base_address = 0;
  unsigned int phys_OEN_R;
  unsigned int phys_SET_R;
  unsigned int phys_VAL_R;
  if (bank == 2)
    return -1;
  if (bank == 0)
    base_address = 0x20930000;
  else if (bank == 1)
    base_address = 0x20931000;
  else if (bank == 2)
    base_address = 0x11A08000;
  else if (bank == 3)
    base_address = 0x20932000;
  else {
    return -1;
  }
  phys_OEN_R = base_address + (0x00);
  phys_SET_R = base_address + (0x10);
  phys_VAL_R = base_address + (0x0C);
  if (ca5_readR(phys_OEN_R) & (1UL << (index)))
    val = (ca5_readR(phys_VAL_R) & (1UL << (index))) ? 1 : 0;
  else
    val = (ca5_readR(phys_SET_R) & (1UL << (index))) ? 1 : 0;
  return val;
}


x86 assembly (clang, -O0):
<pinRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    114f <pinRead+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <pinRead+0x153>
cmpl   $0x0,-0xc(%rbp)
jne    1165 <pinRead+0x55>
movl   $0x20930000,-0x18(%rbp)
jmp    11c2 <pinRead+0xb2>
cmpl   $0x1,-0xc(%rbp)
jne    117b <pinRead+0x6b>
movl   $0x20931000,-0x18(%rbp)
jmp    11bd <pinRead+0xad>
cmpl   $0x2,-0xc(%rbp)
jne    1191 <pinRead+0x81>
movl   $0x11a08000,-0x18(%rbp)
jmp    11b8 <pinRead+0xa8>
cmpl   $0x3,-0xc(%rbp)
jne    11a7 <pinRead+0x97>
movl   $0x20932000,-0x18(%rbp)
jmp    11b3 <pinRead+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <pinRead+0x153>
jmp    11b8 <pinRead+0xa8>
jmp    11bd <pinRead+0xad>
jmp    11c2 <pinRead+0xb2>
mov    -0x18(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <ca5_readR@plt>
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1231 <pinRead+0x121>
mov    -0x24(%rbp),%edi
call   1030 <ca5_readR@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
and    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    125d <pinRead+0x14d>
mov    -0x20(%rbp),%edi
call   1030 <ca5_readR@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
and    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pinRead>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ecx
sar    $0x5,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
je     116f <pinRead+0x5f>
mov    %edi,%ebx
mov    $0x20930000,%ebp
cmp    $0x20,%edi
jb     1144 <pinRead+0x34>
cmp    $0x1,%ecx
je     113f <pinRead+0x2f>
cmp    $0x3,%ecx
jne    116f <pinRead+0x5f>
mov    $0x20932000,%ebp
jmp    1144 <pinRead+0x34>
mov    $0x20931000,%ebp
and    $0x1f,%ebx
mov    %ebp,%edi
call   1030 <ca5_readR@plt>
xor    %ecx,%ecx
bt     %ebx,%eax
setae  %cl
lea    0xc(,%rcx,4),%edi
or     %ebp,%edi
call   1030 <ca5_readR@plt>
mov    %rax,%rcx
xor    %eax,%eax
bt     %ebx,%ecx
setb   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pinRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = load i32, i32* %3
%12 = ashr i32 %11, 5
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = shl i32 %14, 5
%16 = sub nsw i32 %13, %15
store i32 %16, i32* %5
store i32 0, i32* %7
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %1
store i32 -1, i32* %2
br label %76
20: ; preds = %1
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 546504704, i32* %7
br label %40
24: ; preds = %20
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 546508800, i32* %7
br label %39
28: ; preds = %24
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 295731200, i32* %7
br label %38
32: ; preds = %28
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 546512896, i32* %7
br label %37
36: ; preds = %32
store i32 -1, i32* %2
br label %76
37: ; preds = %35
br label %38
38: ; preds = %37, %31
br label %39
39: ; preds = %38, %27
br label %40
40: ; preds = %39, %23
%41 = load i32, i32* %7
%42 = add i32 %41, 0
store i32 %42, i32* %8
%43 = load i32, i32* %7
%44 = add i32 %43, 16
store i32 %44, i32* %9
%45 = load i32, i32* %7
%46 = add i32 %45, 12
store i32 %46, i32* %10
%47 = load i32, i32* %8
%48 = call i64 @ca5_readR(i32 %47)
%49 = load i32, i32* %5
%50 = zext i32 %49 to i64
%51 = shl i64 1, %50
%52 = and i64 %48, %51
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %40
%55 = load i32, i32* %10
%56 = call i64 @ca5_readR(i32 %55)
%57 = load i32, i32* %5
%58 = zext i32 %57 to i64
%59 = shl i64 1, %58
%60 = and i64 %56, %59
%61 = icmp ne i64 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 1, i32 0
store i32 %63, i32* %6
br label %74
64: ; preds = %40
%65 = load i32, i32* %9
%66 = call i64 @ca5_readR(i32 %65)
%67 = load i32, i32* %5
%68 = zext i32 %67 to i64
%69 = shl i64 1, %68
%70 = and i64 %66, %69
%71 = icmp ne i64 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i32 1, i32 0
store i32 %73, i32* %6
br label %74
74: ; preds = %64, %54
%75 = load i32, i32* %6
store i32 %75, i32* %2
br label %76
76: ; preds = %74, %36, %19
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
define i32 @pinRead(i32 %0) {
%2 = ashr i32 %0, 5
%3 = and i32 %0, 31
%4 = icmp eq i32 %2, 2
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = icmp ult i32 %0, 32
br i1 %6, label %9, label %7
7: ; preds = %5
switch i32 %2, label %22 [
i32 1, label %9
i32 3, label %8
]
8: ; preds = %7
br label %9
9: ; preds = %7, %5, %8
%10 = phi i32 [ 546512896, %8 ], [ 546504704, %5 ], [ 546508800, %7 ]
%11 = tail call i64 @ca5_readR(i32 %10)
%12 = zext i32 %3 to i64
%13 = shl nuw nsw i64 1, %12
%14 = and i64 %11, %13
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 16, i32 12
%17 = or i32 %10, %16
%18 = tail call i64 @ca5_readR(i32 %17)
%19 = and i64 %18, %13
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %7, %1, %9
%23 = phi i32 [ %21, %9 ], [ -1, %1 ], [ -1, %7 ]
ret i32 %23
}