#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 sunxi_readl(int volatile *);
int /*<<< orphan*/ sunxi_writel(int, int volatile *);
void sunxi_set_pullupdn(int gpio, int pud) {
  uint32_t regval = 0;
  int bank = gpio >> 5;
  int index = gpio - (bank << 5);
  int sub = index >> 4;
  int sub_index = index - 16 * sub;
  volatile uint32_t *phyaddr =
      (volatile uint32_t *)((0x01C20800) + (bank * 36) + 0x1c + 4 * sub);
  ;
  regval = sunxi_readl(phyaddr);
  ;
  regval &= ~(3 << (sub_index << 1));
  regval |= (pud << (sub_index << 1));
  ;
  sunxi_writel(regval, phyaddr);
  regval = sunxi_readl(phyaddr);
  ;
}


x86 assembly (clang, -O0):
<sunxi_set_pullupdn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x4,%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
imul   $0x24,-0x10(%rbp),%eax
add    $0x1c20800,%eax
add    $0x1c,%eax
mov    -0x18(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <sunxi_readl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
mov    $0x3,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <sunxi_writel@plt>
mov    -0x28(%rbp),%rdi
call   1030 <sunxi_readl@plt>
mov    %eax,-0xc(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sunxi_set_pullupdn>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%eax
sar    $0x5,%eax
mov    %edi,%ebp
and    $0x1f,%ebp
mov    %edi,%ecx
and    $0x10,%ecx
sub    %ecx,%ebp
lea    (%rax,%rax,8),%eax
shr    $0x2,%edi
and    $0x4,%edi
lea    (%rdi,%rax,4),%eax
add    $0x1c2081c,%eax
movslq %eax,%r14
mov    %r14,%rdi
call   1030 <sunxi_readl@plt>
add    %ebp,%ebp
mov    $0x3,%edx
mov    %ebp,%ecx
shl    %cl,%edx
not    %edx
and    %eax,%edx
shl    %cl,%ebx
or     %edx,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <sunxi_writel@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <sunxi_readl@plt>

LLVM IR (-O0):
define void @sunxi_set_pullupdn(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
%10 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%11 = load i32, i32* %3
%12 = ashr i32 %11, 5
store i32 %12, i32* %6
%13 = load i32, i32* %3
%14 = load i32, i32* %6
%15 = shl i32 %14, 5
%16 = sub nsw i32 %13, %15
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = ashr i32 %17, 4
store i32 %18, i32* %8
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = mul nsw i32 16, %20
%22 = sub nsw i32 %19, %21
store i32 %22, i32* %9
%23 = load i32, i32* %6
%24 = mul nsw i32 %23, 36
%25 = add nsw i32 29493248, %24
%26 = add nsw i32 %25, 28
%27 = load i32, i32* %8
%28 = mul nsw i32 4, %27
%29 = add nsw i32 %26, %28
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %10
%32 = load i32*, i32** %10
%33 = call i32 @sunxi_readl(i32* %32)
store i32 %33, i32* %5
%34 = load i32, i32* %9
%35 = shl i32 %34, 1
%36 = shl i32 3, %35
%37 = xor i32 %36, -1
%38 = load i32, i32* %5
%39 = and i32 %38, %37
store i32 %39, i32* %5
%40 = load i32, i32* %4
%41 = load i32, i32* %9
%42 = shl i32 %41, 1
%43 = shl i32 %40, %42
%44 = load i32, i32* %5
%45 = or i32 %44, %43
store i32 %45, i32* %5
%46 = load i32, i32* %5
%47 = load i32*, i32** %10
%48 = call i32 @sunxi_writel(i32 %46, i32* %47)
%49 = load i32*, i32** %10
%50 = call i32 @sunxi_readl(i32* %49)
store i32 %50, i32* %5
ret void
}

LLVM IR (-O2):
define void @sunxi_set_pullupdn(i32 %0, i32 %1) {
%3 = ashr i32 %0, 5
%4 = and i32 %0, 31
%5 = and i32 %0, 16
%6 = sub nsw i32 %4, %5
%7 = mul nsw i32 %3, 36
%8 = add nsw i32 %7, 29493276
%9 = lshr i32 %0, 2
%10 = and i32 %9, 4
%11 = add nsw i32 %8, %10
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = tail call i32 @sunxi_readl(i32* %13)
%15 = shl nsw i32 %6, 1
%16 = shl i32 3, %15
%17 = xor i32 %16, -1
%18 = and i32 %14, %17
%19 = shl i32 %1, %15
%20 = or i32 %18, %19
%21 = tail call i32 @sunxi_writel(i32 %20, i32* %13)
%22 = tail call i32 @sunxi_readl(i32* %13)
ret void
}