#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 readl(unsigned int);
unsigned int s5p_mshc_init(unsigned int, int);
unsigned int s5p_sdhci_init(unsigned int, int, int, int);
int samsung_get_base_mmc();
unsigned int s5p_mmc_init(int index, int bus_width) {
  unsigned int base = samsung_get_base_mmc() + (0x10000 * index);
  unsigned int mshc_ver_main_id = readl(base + 0x6C) >> 16;
  if (mshc_ver_main_id == 0x5342)
    return s5p_mshc_init(base, index);
  else
    return s5p_sdhci_init(base, 52000000, 400000, index);
}


x86 assembly (clang, -O0):
<s5p_mmc_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <samsung_get_base_mmc@plt>
mov    -0x8(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x6c,%edi
call   1040 <readl@plt>
sar    $0x10,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x5342,-0x14(%rbp)
jne    1191 <s5p_mmc_init+0x51>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <s5p_mshc_init@plt>
mov    %eax,-0x4(%rbp)
jmp    11a9 <s5p_mmc_init+0x69>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%ecx
mov    $0x3197500,%esi
mov    $0x61a80,%edx
call   1030 <s5p_sdhci_init@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s5p_mmc_init>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <samsung_get_base_mmc@plt>
mov    %ebx,%ecx
shl    $0x10,%ecx
lea    (%rax,%rcx,1),%ebp
lea    (%rax,%rcx,1),%edi
add    $0x6c,%edi
call   1040 <readl@plt>
and    $0xffff0000,%eax
mov    %ebp,%edi
cmp    $0x53420000,%eax
jne    117a <s5p_mmc_init+0x3a>
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <s5p_mshc_init@plt>
mov    $0x3197500,%esi
mov    $0x61a80,%edx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <s5p_sdhci_init@plt>

LLVM IR (-O0):
define i32 @s5p_mmc_init(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = call i32 (...) @samsung_get_base_mmc()
%9 = load i32, i32* %4
%10 = mul nsw i32 65536, %9
%11 = add nsw i32 %8, %10
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = add i32 %12, 108
%14 = call i32 @readl(i32 %13)
%15 = ashr i32 %14, 16
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 21314
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = call i32 @s5p_mshc_init(i32 %19, i32 %20)
store i32 %21, i32* %3
br label %26
22: ; preds = %2
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = call i32 @s5p_sdhci_init(i32 %23, i32 52000000, i32 400000, i32 %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %22, %18
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @s5p_mmc_init(i32 %0, i32 %1) {
%3 = tail call i32 (...) @samsung_get_base_mmc()
%4 = shl nsw i32 %0, 16
%5 = add nsw i32 %3, %4
%6 = add i32 %5, 108
%7 = tail call i32 @readl(i32 %6)
%8 = and i32 %7, -65536
%9 = icmp eq i32 %8, 1396834304
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @s5p_mshc_init(i32 %5, i32 %0)
br label %14
12: ; preds = %2
%13 = tail call i32 @s5p_sdhci_init(i32 %5, i32 52000000, i32 400000, i32 %0)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
ret i32 %15
}