#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*/ DEBUG_ASSERT(int);
int GPIOBaseValid(unsigned long);
unsigned long GPIODirModeGet(unsigned long ulPort, unsigned char ucPin) {
  unsigned long ulDir, ulAFSEL;
  DEBUG_ASSERT(GPIOBaseValid(ulPort));
  DEBUG_ASSERT(ucPin < 8);
  ucPin = 1 << ucPin;
  ulDir = (*((volatile unsigned long *)(ulPort + 0x00000400)));
  ulAFSEL = (*((volatile unsigned long *)(ulPort + 0x00000420)));
  return (((ulDir & ucPin) ? 1 : 0) | ((ulAFSEL & ucPin) ? 2 : 0));
}


x86 assembly (clang, -O0):
<GPIODirModeGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <GPIOBaseValid@plt>
mov    %eax,%edi
call   1040 <DEBUG_ASSERT@plt>
movzbl -0x9(%rbp),%eax
cmp    $0x8,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <DEBUG_ASSERT@plt>
movzbl -0x9(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    0x400(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x420(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdx
movzbl -0x9(%rbp),%eax
and    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    -0x20(%rbp),%rsi
movzbl -0x9(%rbp),%ecx
and    %rcx,%rsi
xor    %ecx,%ecx
mov    $0x2,%edx
cmp    $0x0,%rsi
cmovne %edx,%ecx
or     %ecx,%eax
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GPIODirModeGet>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <GPIOBaseValid@plt>
mov    %eax,%edi
call   1040 <DEBUG_ASSERT@plt>
xor    %edi,%edi
cmp    $0x8,%bpl
setb   %dil
call   1040 <DEBUG_ASSERT@plt>
mov    $0x1,%eax
mov    %ebp,%ecx
shl    %cl,%eax
mov    0x400(%rbx),%rcx
mov    0x420(%rbx),%rdx
movzbl %al,%eax
xor    %esi,%esi
test   %eax,%ecx
setne  %sil
xor    %ecx,%ecx
test   %eax,%edx
setne  %cl
lea    (%rsi,%rcx,2),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @GPIODirModeGet(i64 %0, i8 zeroext %1) {
%3 = alloca i64
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i8 %1, i8* %4
%7 = load i64, i64* %3
%8 = call i32 @GPIOBaseValid(i64 %7)
%9 = call i32 @DEBUG_ASSERT(i32 %8)
%10 = load i8, i8* %4
%11 = zext i8 %10 to i32
%12 = icmp slt i32 %11, 8
%13 = zext i1 %12 to i32
%14 = call i32 @DEBUG_ASSERT(i32 %13)
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = shl i32 1, %16
%18 = trunc i32 %17 to i8
store i8 %18, i8* %4
%19 = load i64, i64* %3
%20 = add i64 %19, 1024
%21 = inttoptr i64 %20 to i64*
%22 = load volatile i64, i64* %21
store i64 %22, i64* %5
%23 = load i64, i64* %3
%24 = add i64 %23, 1056
%25 = inttoptr i64 %24 to i64*
%26 = load volatile i64, i64* %25
store i64 %26, i64* %6
%27 = load i64, i64* %5
%28 = load i8, i8* %4
%29 = zext i8 %28 to i64
%30 = and i64 %27, %29
%31 = icmp ne i64 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
%34 = load i64, i64* %6
%35 = load i8, i8* %4
%36 = zext i8 %35 to i64
%37 = and i64 %34, %36
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 2, i32 0
%41 = or i32 %33, %40
%42 = sext i32 %41 to i64
ret i64 %42
}

LLVM IR (-O2):
define i64 @GPIODirModeGet(i64 %0, i8 zeroext %1) {
%3 = tail call i32 @GPIOBaseValid(i64 %0)
%4 = tail call i32 @DEBUG_ASSERT(i32 %3)
%5 = zext i8 %1 to i32
%6 = icmp ult i8 %1, 8
%7 = zext i1 %6 to i32
%8 = tail call i32 @DEBUG_ASSERT(i32 %7)
%9 = shl nuw i32 1, %5
%10 = add i64 %0, 1024
%11 = inttoptr i64 %10 to i64*
%12 = load volatile i64, i64* %11
%13 = add i64 %0, 1056
%14 = inttoptr i64 %13 to i64*
%15 = load volatile i64, i64* %14
%16 = and i32 %9, 255
%17 = zext i32 %16 to i64
%18 = and i64 %12, %17
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i64
%21 = and i64 %15, %17
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i64 0, i64 2
%24 = or i64 %23, %20
ret i64 %24
}