#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*/ panic(char *);
int /*<<< orphan*/ putstr(char *);
int /*<<< orphan*/ sd_flush_fifo();
scalar_t__ sd_send_if_cond();
int /*<<< orphan*/ sd_send_initial_clock();
scalar_t__ sd_send_read_ocr();
scalar_t__ sd_send_reset();
scalar_t__ sd_set_blocklen();
scalar_t__ sd_wait_ready();
void sd_init(void) {
  sd_send_initial_clock();
  sd_flush_fifo();
  if (sd_send_reset())
    panic("Failed to reset SD card");
  if (sd_send_if_cond())
    panic("Failed to send interface conditions to SD card");
  if (sd_send_read_ocr())
    panic("Failed to read OCR for SD card");
  if (sd_wait_ready())
    panic("Failed to wait for SD card init");
  if (sd_send_read_ocr())
    panic("Failed to re-read OCR for SD card");
  if (sd_set_blocklen())
    panic("Failed to wait for SD card init");
  putstr("SD card ready\n");
}


x86 assembly (clang, -O0):
<sd_init>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1040 <sd_send_initial_clock@plt>
mov    $0x0,%al
call   1030 <sd_flush_fifo@plt>
mov    $0x0,%al
call   1060 <sd_send_reset@plt>
cmp    $0x0,%rax
je     11bf <sd_init+0x2f>
lea    0xe46(%rip),%rdi
call   1080 <panic@plt>
mov    $0x0,%al
call   1050 <sd_send_if_cond@plt>
cmp    $0x0,%rax
je     11dc <sd_init+0x4c>
lea    0xe41(%rip),%rdi
call   1080 <panic@plt>
mov    $0x0,%al
call   1070 <sd_send_read_ocr@plt>
cmp    $0x0,%rax
je     11f9 <sd_init+0x69>
lea    0xe53(%rip),%rdi
call   1080 <panic@plt>
mov    $0x0,%al
call   1090 <sd_wait_ready@plt>
cmp    $0x0,%rax
je     1216 <sd_init+0x86>
lea    0xe55(%rip),%rdi
call   1080 <panic@plt>
mov    $0x0,%al
call   1070 <sd_send_read_ocr@plt>
cmp    $0x0,%rax
je     1233 <sd_init+0xa3>
lea    0xe58(%rip),%rdi
call   1080 <panic@plt>
mov    $0x0,%al
call   10b0 <sd_set_blocklen@plt>
cmp    $0x0,%rax
je     1250 <sd_init+0xc0>
lea    0xe1b(%rip),%rdi
call   1080 <panic@plt>
lea    0xe51(%rip),%rdi
call   10a0 <putstr@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<sd_init>:
push   %rax
xor    %eax,%eax
call   1040 <sd_send_initial_clock@plt>
xor    %eax,%eax
call   1030 <sd_flush_fifo@plt>
xor    %eax,%eax
call   1060 <sd_send_reset@plt>
test   %rax,%rax
je     11b7 <sd_init+0x27>
lea    0xe4e(%rip),%rdi
call   1080 <panic@plt>
xor    %eax,%eax
call   1050 <sd_send_if_cond@plt>
test   %rax,%rax
je     11cf <sd_init+0x3f>
lea    0xe4e(%rip),%rdi
call   1080 <panic@plt>
xor    %eax,%eax
call   1070 <sd_send_read_ocr@plt>
test   %rax,%rax
je     11e7 <sd_init+0x57>
lea    0xe65(%rip),%rdi
call   1080 <panic@plt>
xor    %eax,%eax
call   1090 <sd_wait_ready@plt>
test   %rax,%rax
je     11ff <sd_init+0x6f>
lea    0xe6c(%rip),%rdi
call   1080 <panic@plt>
xor    %eax,%eax
call   1070 <sd_send_read_ocr@plt>
test   %rax,%rax
je     1217 <sd_init+0x87>
lea    0xe74(%rip),%rdi
call   1080 <panic@plt>
xor    %eax,%eax
call   10b0 <sd_set_blocklen@plt>
test   %rax,%rax
je     122f <sd_init+0x9f>
lea    0xe3c(%rip),%rdi
call   1080 <panic@plt>
lea    0xe72(%rip),%rdi
pop    %rax
jmp    10a0 <putstr@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Failed to reset SD card\00"
@.str.1 = [47 x i8] c"Failed to send interface conditions to SD card\00"
@.str.2 = [31 x i8] c"Failed to read OCR for SD card\00"
@.str.3 = [32 x i8] c"Failed to wait for SD card init\00"
@.str.4 = [34 x i8] c"Failed to re-read OCR for SD card\00"
@.str.5 = [15 x i8] c"SD card ready\0A\00"
define void @sd_init() {
%1 = call i32 (...) @sd_send_initial_clock()
%2 = call i32 (...) @sd_flush_fifo()
%3 = call i64 (...) @sd_send_reset()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @panic(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i64 (...) @sd_send_if_cond()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @panic(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i64 (...) @sd_send_read_ocr()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @panic(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i64 (...) @sd_wait_ready()
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @panic(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = call i64 (...) @sd_send_read_ocr()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @panic(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = call i64 (...) @sd_set_blocklen()
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @panic(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = call i32 @putstr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Failed to reset SD card\00"
@.str.1 = [47 x i8] c"Failed to send interface conditions to SD card\00"
@.str.2 = [31 x i8] c"Failed to read OCR for SD card\00"
@.str.3 = [32 x i8] c"Failed to wait for SD card init\00"
@.str.4 = [34 x i8] c"Failed to re-read OCR for SD card\00"
@.str.5 = [15 x i8] c"SD card ready\0A\00"
define void @sd_init() {
%1 = tail call i32 (...) @sd_send_initial_clock()
%2 = tail call i32 (...) @sd_flush_fifo()
%3 = tail call i64 (...) @sd_send_reset()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @panic(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i64 (...) @sd_send_if_cond()
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @panic(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i64 (...) @sd_send_read_ocr()
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @panic(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = tail call i64 (...) @sd_wait_ready()
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @panic(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = tail call i64 (...) @sd_send_read_ocr()
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @panic(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = tail call i64 (...) @sd_set_blocklen()
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @panic(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @putstr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
ret void
}