#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 /*<<< orphan*/ printk(char *);
int /*<<< orphan*/ read_mbr();
int sd_set_blocklen();
int sd_wait_ready();
int send_if_cond();
int /*<<< orphan*/ send_initial_clock();
int send_read_ocr();
int send_reset();
void readmbr_handler(const char *buf) {
  int rc;
  send_initial_clock();
  rc = send_reset();
  if (rc) {
    printk("readmbr: failed to reset\n");
    return;
  }
  rc = send_if_cond();
  if (rc) {
    printk("readmbr: failed to send interface conditions\n");
    return;
  }
  rc = send_read_ocr();
  if (rc) {
    printk("readmbr: failed to read OCR\n");
    return;
  }
  rc = sd_wait_ready();
  if (rc) {
    printk("readmbr: failed to wait for SD to become ready\n");
    return;
  }
  rc = sd_set_blocklen();
  if (rc) {
    printk("readmbr: failed to set blocklen\n");
    return;
  }
  read_mbr();
}


x86 assembly (clang, -O0):
<readmbr_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <send_initial_clock@plt>
mov    $0x0,%al
call   1060 <send_reset@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b8 <readmbr_handler+0x38>
lea    0xe52(%rip),%rdi
call   1030 <printk@plt>
jmp    1253 <readmbr_handler+0xd3>
mov    $0x0,%al
call   1050 <send_if_cond@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11dd <readmbr_handler+0x5d>
lea    0xe47(%rip),%rdi
call   1030 <printk@plt>
jmp    1253 <readmbr_handler+0xd3>
mov    $0x0,%al
call   1090 <send_read_ocr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1202 <readmbr_handler+0x82>
lea    0xe50(%rip),%rdi
call   1030 <printk@plt>
jmp    1253 <readmbr_handler+0xd3>
mov    $0x0,%al
call   1070 <sd_wait_ready@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1227 <readmbr_handler+0xa7>
lea    0xe48(%rip),%rdi
call   1030 <printk@plt>
jmp    1253 <readmbr_handler+0xd3>
mov    $0x0,%al
call   1080 <sd_set_blocklen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     124c <readmbr_handler+0xcc>
lea    0xe53(%rip),%rdi
call   1030 <printk@plt>
jmp    1253 <readmbr_handler+0xd3>
mov    $0x0,%al
call   10a0 <read_mbr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readmbr_handler>:
push   %rax
xor    %eax,%eax
call   1040 <send_initial_clock@plt>
xor    %eax,%eax
call   1060 <send_reset@plt>
test   %eax,%eax
je     11a0 <readmbr_handler+0x20>
lea    0xe66(%rip),%rdi
pop    %rax
jmp    1030 <printk@plt>
xor    %eax,%eax
call   1050 <send_if_cond@plt>
test   %eax,%eax
je     11b8 <readmbr_handler+0x38>
lea    0xe68(%rip),%rdi
pop    %rax
jmp    1030 <printk@plt>
xor    %eax,%eax
call   1090 <send_read_ocr@plt>
test   %eax,%eax
je     11d0 <readmbr_handler+0x50>
lea    0xe7e(%rip),%rdi
pop    %rax
jmp    1030 <printk@plt>
xor    %eax,%eax
call   1070 <sd_wait_ready@plt>
test   %eax,%eax
je     11e8 <readmbr_handler+0x68>
lea    0xe83(%rip),%rdi
pop    %rax
jmp    1030 <printk@plt>
xor    %eax,%eax
call   1080 <sd_set_blocklen@plt>
test   %eax,%eax
je     1200 <readmbr_handler+0x80>
lea    0xe9b(%rip),%rdi
pop    %rax
jmp    1030 <printk@plt>
xor    %eax,%eax
pop    %rcx
jmp    10a0 <read_mbr@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"readmbr: failed to reset\0A\00"
@.str.1 = [46 x i8] c"readmbr: failed to send interface conditions\0A\00"
@.str.2 = [29 x i8] c"readmbr: failed to read OCR\0A\00"
@.str.3 = [48 x i8] c"readmbr: failed to wait for SD to become ready\0A\00"
@.str.4 = [33 x i8] c"readmbr: failed to set blocklen\0A\00"
define void @readmbr_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 (...) @send_initial_clock()
%5 = call i32 (...) @send_reset()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %36
10: ; preds = %1
%11 = call i32 (...) @send_if_cond()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @printk(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %36
16: ; preds = %10
%17 = call i32 (...) @send_read_ocr()
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @printk(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %36
22: ; preds = %16
%23 = call i32 (...) @sd_wait_ready()
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @printk(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %36
28: ; preds = %22
%29 = call i32 (...) @sd_set_blocklen()
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @printk(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %36
34: ; preds = %28
%35 = call i32 (...) @read_mbr()
br label %36
36: ; preds = %34, %32, %26, %20, %14, %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"readmbr: failed to reset\0A\00"
@.str.1 = [46 x i8] c"readmbr: failed to send interface conditions\0A\00"
@.str.2 = [29 x i8] c"readmbr: failed to read OCR\0A\00"
@.str.3 = [48 x i8] c"readmbr: failed to wait for SD to become ready\0A\00"
@.str.4 = [33 x i8] c"readmbr: failed to set blocklen\0A\00"
define void @readmbr_handler(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @send_initial_clock()
%3 = tail call i32 (...) @send_reset()
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %29
7: ; preds = %1
%8 = tail call i32 (...) @send_if_cond()
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @printk(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %29
12: ; preds = %7
%13 = tail call i32 (...) @send_read_ocr()
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @printk(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %29
17: ; preds = %12
%18 = tail call i32 (...) @sd_wait_ready()
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @printk(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %29
22: ; preds = %17
%23 = tail call i32 (...) @sd_set_blocklen()
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @printk(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %29
27: ; preds = %22
%28 = tail call i32 (...) @read_mbr()
br label %29
29: ; preds = %27, %25, %20, %15, %10, %5
ret void
}