#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*/ mbox_read(int);
int /*<<< orphan*/ mbox_write(int, int);
int /*<<< orphan*/ printf(char *);
uint32_t sd_get_base_clock_hz() {
  uint32_t base_clock;
  uint32_t mb_addr = 0x40007000;
  volatile uint32_t *mailbuffer = (uint32_t *)mb_addr;
  mailbuffer[0] = 8 * 4;
  mailbuffer[1] = 0;
  mailbuffer[2] = 0x00030002;
  mailbuffer[3] = 0x8;
  mailbuffer[4] = 0x4;
  mailbuffer[5] = 0x1;
  mailbuffer[6] = 0;
  mailbuffer[7] = 0;
  mbox_write(8, mb_addr);
  mbox_read(8);
  if (mailbuffer[1] != 0x80000000) {
    printf("EMMC: property mailbox did not return a valid response.\n");
    return 0;
  }
  if (mailbuffer[5] != 0x1) {
    printf("EMMC: property mailbox did not return a valid clock id.\n");
    return 0;
  }
  base_clock = mailbuffer[6];
  return base_clock;
}


x86 assembly (clang, -O0):
<sd_get_base_clock_hz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x40007000,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x20,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x30002,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x8,0xc(%rax)
mov    -0x18(%rbp),%rax
movl   $0x4,0x10(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x14(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x18(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x1c(%rax)
mov    -0xc(%rbp),%esi
mov    $0x8,%edi
call   1050 <mbox_write@plt>
mov    $0x8,%edi
call   1030 <mbox_read@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
cmp    $0x80000000,%eax
je     11df <sd_get_base_clock_hz+0xaf>
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1217 <sd_get_base_clock_hz+0xe7>
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
cmp    $0x1,%eax
je     1207 <sd_get_base_clock_hz+0xd7>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1217 <sd_get_base_clock_hz+0xe7>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sd_get_base_clock_hz>:
push   %rax
movl   $0x20,0x40007000
movl   $0x0,0x40007004
movl   $0x30002,0x40007008
movl   $0x8,0x4000700c
movl   $0x4,0x40007010
movl   $0x1,0x40007014
movl   $0x0,0x40007018
movl   $0x0,0x4000701c
mov    $0x8,%edi
mov    $0x40007000,%esi
call   1050 <mbox_write@plt>
mov    $0x8,%edi
call   1040 <mbox_read@plt>
mov    0x40007004,%eax
cmp    $0x80000000,%eax
jne    11c5 <sd_get_base_clock_hz+0x95>
mov    0x40007014,%eax
cmp    $0x1,%eax
jne    11ce <sd_get_base_clock_hz+0x9e>
mov    0x40007018,%eax
pop    %rcx
ret
lea    0xe6c(%rip),%rdi
jmp    11d5 <sd_get_base_clock_hz+0xa5>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [57 x i8] c"EMMC: property mailbox did not return a valid response.\0A\00"
@.str.1 = [57 x i8] c"EMMC: property mailbox did not return a valid clock id.\0A\00"
define i32 @sd_get_base_clock_hz() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 1073770496, i32* %3
%5 = load i32, i32* %3
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = getelementptr inbounds i32, i32* %8, i64 0
store volatile i32 32, i32* %9
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 1
store volatile i32 0, i32* %11
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 2
store volatile i32 196610, i32* %13
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 3
store volatile i32 8, i32* %15
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 4
store volatile i32 4, i32* %17
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 5
store volatile i32 1, i32* %19
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i64 6
store volatile i32 0, i32* %21
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 7
store volatile i32 0, i32* %23
%24 = load i32, i32* %3
%25 = call i32 @mbox_write(i32 8, i32 %24)
%26 = call i32 @mbox_read(i32 8)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 1
%29 = load volatile i32, i32* %28
%30 = icmp ne i32 %29, -2147483648
br i1 %30, label %31, label %33
31: ; preds = %0
%32 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %45
33: ; preds = %0
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 5
%36 = load volatile i32, i32* %35
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %45
40: ; preds = %33
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 6
%43 = load volatile i32, i32* %42
store i32 %43, i32* %2
%44 = load i32, i32* %2
store i32 %44, i32* %1
br label %45
45: ; preds = %40, %38, %31
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@str = [56 x i8] c"EMMC: property mailbox did not return a valid clock id.\00"
@str.2 = [56 x i8] c"EMMC: property mailbox did not return a valid response.\00"
define i32 @sd_get_base_clock_hz() {
store volatile i32 32, i32* inttoptr (i64 1073770496 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073770500 to i32*)
store volatile i32 196610, i32* inttoptr (i64 1073770504 to i32*)
store volatile i32 8, i32* inttoptr (i64 1073770508 to i32*)
store volatile i32 4, i32* inttoptr (i64 1073770512 to i32*)
store volatile i32 1, i32* inttoptr (i64 1073770516 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073770520 to i32*)
store volatile i32 0, i32* inttoptr (i64 1073770524 to i32*)
%1 = tail call i32 @mbox_write(i32 8, i32 1073770496)
%2 = tail call i32 @mbox_read(i32 8)
%3 = load volatile i32, i32* inttoptr (i64 1073770500 to i32*)
%4 = icmp eq i32 %3, -2147483648
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.2, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = load volatile i32, i32* inttoptr (i64 1073770516 to i32*)
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = load volatile i32, i32* inttoptr (i64 1073770520 to i32*)
br label %14
14: ; preds = %12, %10, %5
%15 = phi i32 [ 0, %5 ], [ 0, %10 ], [ %13, %12 ]
ret i32 %15
}