#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 reg_read(int);
int /*<<< orphan*/ reg_write(int, unsigned long);
void gpio_dir(int gpio, int dir) {
  unsigned long gdir;
  unsigned char port;
  gpio -= 96;
  if (gpio > 31) {
    gpio -= 32;
    port = 5;
    gdir = reg_read(0x20AC004);
  } else {
    port = 4;
    gdir = reg_read(0x20A8004);
  }
  if (dir) {
    if (port == 4)
      reg_write(0x20A8004, gdir | (1 << gpio));
    else
      reg_write(0x20AC004, gdir | (1 << gpio));
  } else {
    if (port == 4)
      reg_write(0x20A8004, gdir & (~(1 << gpio)));
    else
      reg_write(0x20AC004, gdir & (~(1 << gpio)));
  }
}


x86 assembly (clang, -O0):
<gpio_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x60,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x1f,-0x4(%rbp)
jle    1161 <gpio_dir+0x41>
mov    -0x4(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x4(%rbp)
movb   $0x5,-0x11(%rbp)
mov    $0x20ac004,%edi
call   1030 <reg_read@plt>
mov    %rax,-0x10(%rbp)
jmp    1173 <gpio_dir+0x53>
movb   $0x4,-0x11(%rbp)
mov    $0x20a8004,%edi
call   1030 <reg_read@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ce <gpio_dir+0xae>
movzbl -0x11(%rbp),%eax
cmp    $0x4,%eax
jne    11ac <gpio_dir+0x8c>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
or     %rax,%rsi
mov    $0x20a8004,%edi
call   1040 <reg_write@plt>
jmp    11c9 <gpio_dir+0xa9>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
or     %rax,%rsi
mov    $0x20ac004,%edi
call   1040 <reg_write@plt>
jmp    1225 <gpio_dir+0x105>
movzbl -0x11(%rbp),%eax
cmp    $0x4,%eax
jne    1200 <gpio_dir+0xe0>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
cltq
and    %rax,%rsi
mov    $0x20a8004,%edi
call   1040 <reg_write@plt>
jmp    1220 <gpio_dir+0x100>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
cltq
and    %rax,%rsi
mov    $0x20ac004,%edi
call   1040 <reg_write@plt>
jmp    1225 <gpio_dir+0x105>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_dir>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
cmp    $0x80,%edi
jl     1153 <gpio_dir+0x33>
mov    $0x20ac004,%edi
call   1030 <reg_read@plt>
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
test   %ebx,%ebx
je     1172 <gpio_dir+0x52>
movslq %edx,%rcx
or     %rcx,%rax
mov    $0x20ac004,%edi
jmp    118e <gpio_dir+0x6e>
mov    $0x20a8004,%edi
call   1030 <reg_read@plt>
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
test   %ebx,%ebx
je     1181 <gpio_dir+0x61>
movslq %edx,%rcx
or     %rcx,%rax
jmp    1189 <gpio_dir+0x69>
not    %edx
movslq %edx,%rcx
and    %rcx,%rax
mov    $0x20ac004,%edi
jmp    118e <gpio_dir+0x6e>
not    %edx
movslq %edx,%rcx
and    %rcx,%rax
mov    $0x20a8004,%edi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <reg_write@plt>

LLVM IR (-O0):
define void @gpio_dir(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = sub nsw i32 %7, 96
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 31
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 32
store i32 %13, i32* %3
store i8 5, i8* %6
%14 = call i64 @reg_read(i32 34258948)
store i64 %14, i64* %5
br label %17
15: ; preds = %2
store i8 4, i8* %6
%16 = call i64 @reg_read(i32 34242564)
store i64 %16, i64* %5
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %17
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 4
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i64, i64* %5
%26 = load i32, i32* %3
%27 = shl i32 1, %26
%28 = sext i32 %27 to i64
%29 = or i64 %25, %28
%30 = call i32 @reg_write(i32 34242564, i64 %29)
br label %38
31: ; preds = %20
%32 = load i64, i64* %5
%33 = load i32, i32* %3
%34 = shl i32 1, %33
%35 = sext i32 %34 to i64
%36 = or i64 %32, %35
%37 = call i32 @reg_write(i32 34258948, i64 %36)
br label %38
38: ; preds = %31, %24
br label %60
39: ; preds = %17
%40 = load i8, i8* %6
%41 = zext i8 %40 to i32
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i64, i64* %5
%45 = load i32, i32* %3
%46 = shl i32 1, %45
%47 = xor i32 %46, -1
%48 = sext i32 %47 to i64
%49 = and i64 %44, %48
%50 = call i32 @reg_write(i32 34242564, i64 %49)
br label %59
51: ; preds = %39
%52 = load i64, i64* %5
%53 = load i32, i32* %3
%54 = shl i32 1, %53
%55 = xor i32 %54, -1
%56 = sext i32 %55 to i64
%57 = and i64 %52, %56
%58 = call i32 @reg_write(i32 34258948, i64 %57)
br label %59
59: ; preds = %51, %43
br label %60
60: ; preds = %59, %38
ret void
}

LLVM IR (-O2):
define void @gpio_dir(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 127
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = add nsw i32 %0, -128
%6 = tail call i64 @reg_read(i32 34258948)
%7 = icmp eq i32 %1, 0
%8 = shl nuw i32 1, %5
br i1 %7, label %27, label %18
9: ; preds = %2
%10 = add nsw i32 %0, -96
%11 = tail call i64 @reg_read(i32 34242564)
%12 = icmp eq i32 %1, 0
%13 = shl nuw i32 1, %10
br i1 %12, label %22, label %14
14: ; preds = %9
%15 = sext i32 %13 to i64
%16 = or i64 %11, %15
%17 = tail call i32 @reg_write(i32 34242564, i64 %16)
br label %32
18: ; preds = %4
%19 = sext i32 %8 to i64
%20 = or i64 %6, %19
%21 = tail call i32 @reg_write(i32 34258948, i64 %20)
br label %32
22: ; preds = %9
%23 = xor i32 %13, -1
%24 = sext i32 %23 to i64
%25 = and i64 %11, %24
%26 = tail call i32 @reg_write(i32 34242564, i64 %25)
br label %32
27: ; preds = %4
%28 = xor i32 %8, -1
%29 = sext i32 %28 to i64
%30 = and i64 %6, %29
%31 = tail call i32 @reg_write(i32 34258948, i64 %30)
br label %32
32: ; preds = %22, %27, %14, %18
ret void
}