#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*/ ca5_writeR(unsigned long, unsigned int);
int /*<<< orphan*/ printf(char *);
int ca5_digitalWrite(int pin, int value) {
  unsigned int bank = pin >> 5;
  unsigned int index = pin - (bank << 5);
  unsigned int phyaddr = 0;
  unsigned int base_address = 0;
  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 {
    printf("Bad pin number!\n");
    return 0;
  }
  if (value)
    phyaddr = base_address + (0x10);
  else
    phyaddr = base_address + (0x14);
  ca5_writeR((1UL << (index)), phyaddr);
  return 0;
}


x86 assembly (clang, -O0):
<ca5_digitalWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1169 <ca5_digitalWrite+0x49>
movl   $0x20930000,-0x1c(%rbp)
jmp    11d2 <ca5_digitalWrite+0xb2>
cmpl   $0x1,-0x10(%rbp)
jne    117f <ca5_digitalWrite+0x5f>
movl   $0x20931000,-0x1c(%rbp)
jmp    11cd <ca5_digitalWrite+0xad>
cmpl   $0x2,-0x10(%rbp)
jne    1195 <ca5_digitalWrite+0x75>
movl   $0x11a08000,-0x1c(%rbp)
jmp    11c8 <ca5_digitalWrite+0xa8>
cmpl   $0x3,-0x10(%rbp)
jne    11ab <ca5_digitalWrite+0x8b>
movl   $0x20932000,-0x1c(%rbp)
jmp    11c3 <ca5_digitalWrite+0xa3>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120f <ca5_digitalWrite+0xef>
jmp    11c8 <ca5_digitalWrite+0xa8>
jmp    11cd <ca5_digitalWrite+0xad>
jmp    11d2 <ca5_digitalWrite+0xb2>
cmpl   $0x0,-0xc(%rbp)
je     11ea <ca5_digitalWrite+0xca>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    11f3 <ca5_digitalWrite+0xd3>
mov    -0x1c(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%edi
shl    %cl,%rdi
mov    -0x18(%rbp),%esi
call   1040 <ca5_writeR@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ca5_digitalWrite>:
push   %rax
mov    $0x20930000,%ecx
cmp    $0x20,%edi
jb     1144 <ca5_digitalWrite+0x24>
mov    %edi,%eax
sar    $0x5,%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
jae    116c <ca5_digitalWrite+0x4c>
cltq
lea    0xecf(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
and    $0x1f,%edi
xor    %eax,%eax
test   %esi,%esi
sete   %al
shl    $0x2,%eax
or     %ecx,%eax
or     $0x10,%eax
mov    $0x1,%edx
mov    %edi,%ecx
shl    %cl,%rdx
mov    %rdx,%rdi
mov    %eax,%esi
call   1040 <ca5_writeR@plt>
jmp    1178 <ca5_digitalWrite+0x58>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Bad pin number!\0A\00"
define i32 @ca5_digitalWrite(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* %4
%11 = ashr i32 %10, 5
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = load i32, i32* %6
%14 = shl i32 %13, 5
%15 = sub i32 %12, %14
store i32 %15, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 546504704, i32* %9
br label %36
19: ; preds = %2
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 546508800, i32* %9
br label %35
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 295731200, i32* %9
br label %34
27: ; preds = %23
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 546512896, i32* %9
br label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %51
33: ; preds = %30
br label %34
34: ; preds = %33, %26
br label %35
35: ; preds = %34, %22
br label %36
36: ; preds = %35, %18
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %9
%41 = add i32 %40, 16
store i32 %41, i32* %8
br label %45
42: ; preds = %36
%43 = load i32, i32* %9
%44 = add i32 %43, 20
store i32 %44, i32* %8
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %7
%47 = zext i32 %46 to i64
%48 = shl i64 1, %47
%49 = load i32, i32* %8
%50 = call i32 @ca5_writeR(i64 %48, i32 %49)
store i32 0, i32* %3
br label %51
51: ; preds = %45, %31
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@str = [16 x i8] c"Bad pin number!\00"
@switch.table.ca5_digitalWrite = [3 x i32] [i32 546508800, i32 295731200, i32 546512896]
define i32 @ca5_digitalWrite(i32 %0, i32 %1) {
%3 = and i32 %0, 31
%4 = icmp ult i32 %0, 32
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = ashr i32 %0, 5
%7 = add nsw i32 %6, -1
%8 = icmp ult i32 %7, 3
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %23
11: ; preds = %5
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.ca5_digitalWrite, i64 0, i64 %12
%14 = load i32, i32* %13
br label %15
15: ; preds = %11, %2
%16 = phi i32 [ 546504704, %2 ], [ %14, %11 ]
%17 = icmp eq i32 %1, 0
%18 = select i1 %17, i32 20, i32 16
%19 = or i32 %16, %18
%20 = zext i32 %3 to i64
%21 = shl nuw nsw i64 1, %20
%22 = tail call i32 @ca5_writeR(i64 %21, i32 %19)
br label %23
23: ; preds = %15, %9
ret i32 0
}