#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
int readl(int);
int gpio_function(int gpio) {
  uint32_t regval = 0;
  int bank = gpio >> 5;
  int index = gpio - (bank << 5);
  int offset = ((index - ((index >> 3) << 3)) << 2);
  uint32_t phyaddr = (0x01C20800) + (bank * 36) + ((index >> 3) << 2);
  regval = readl(phyaddr);
  if (0)
    printf("read reg val: 0x%x offset:%d\n", regval, offset);
  regval >>= offset;
  regval &= 7;
  if (0)
    printf("read reg val: 0x%x\n", regval);
  return regval;
}


x86 assembly (clang, -O0):
<gpio_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x3,%ecx
shl    $0x3,%ecx
sub    %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0x14(%rbp)
imul   $0x24,-0xc(%rbp),%eax
add    $0x1c20800,%eax
mov    -0x10(%rbp),%ecx
sar    $0x3,%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <readl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%eax
sar    %cl,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_function>:
push   %rbx
mov    %edi,%eax
sar    $0x5,%eax
mov    %edi,%ebx
and    $0x1f,%ebx
mov    %edi,%ecx
and    $0x18,%ecx
sub    %ecx,%ebx
shl    $0x2,%ebx
lea    (%rax,%rax,8),%eax
shr    %edi
and    $0xc,%edi
lea    (%rdi,%rax,4),%edi
add    $0x1c20800,%edi
call   1030 <readl@plt>
mov    %ebx,%ecx
sar    %cl,%eax
and    $0x7,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @gpio_function(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%8 = load i32, i32* %2
%9 = ashr i32 %8, 5
store i32 %9, i32* %4
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = shl i32 %11, 5
%13 = sub nsw i32 %10, %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = load i32, i32* %5
%16 = ashr i32 %15, 3
%17 = shl i32 %16, 3
%18 = sub nsw i32 %14, %17
%19 = shl i32 %18, 2
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 36
%22 = add nsw i32 29493248, %21
%23 = load i32, i32* %5
%24 = ashr i32 %23, 3
%25 = shl i32 %24, 2
%26 = add nsw i32 %22, %25
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i32 @readl(i32 %27)
store i32 %28, i32* %3
%29 = load i32, i32* %6
%30 = load i32, i32* %3
%31 = ashr i32 %30, %29
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = and i32 %32, 7
store i32 %33, i32* %3
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @gpio_function(i32 %0) {
%2 = ashr i32 %0, 5
%3 = and i32 %0, 31
%4 = and i32 %0, 24
%5 = sub nsw i32 %3, %4
%6 = shl nsw i32 %5, 2
%7 = mul nsw i32 %2, 36
%8 = add nsw i32 %7, 29493248
%9 = lshr i32 %0, 1
%10 = and i32 %9, 12
%11 = add nsw i32 %8, %10
%12 = tail call i32 @readl(i32 %11)
%13 = ashr i32 %12, %6
%14 = and i32 %13, 7
ret i32 %14
}