#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*/ OSD_Puts(char *);
int SPI_PUMP();
int cmd_write(int, int);
int /*<<< orphan*/ spi_spin();
int /*<<< orphan*/ wait_init();
scalar_t__ wait_initV2();
int is_sdhc() {
  int i, r;
  spi_spin();
  r = cmd_write(0x870048, 0x1AA);
  if (r != 1) {
    wait_init();
    return (0);
  }
  r = SPI_PUMP();
  if ((r & 0xffff) != 0x01aa) {
    wait_init();
    return (0);
  }
  *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
  i = 50;
  while (--i) {
    if (wait_initV2()) {
      if ((r = cmd_write(0xff007A, 0)) == 0) {
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        r = (*(volatile unsigned int *)(0xFFFFFFD0 + 0x04) & 255);
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        if (r & 0x40)
          return (1);
        else
          return (0);
      }
    }
    if (i == 2) {
      OSD_Puts("SDHC error!\n");
      return (0);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<is_sdhc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <spi_spin@plt>
mov    $0x870048,%edi
mov    $0x1aa,%esi
call   1080 <cmd_write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     119e <is_sdhc+0x3e>
mov    $0x0,%al
call   1030 <wait_init@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bb <is_sdhc+0x15b>
mov    $0x0,%al
call   1050 <SPI_PUMP@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
cmp    $0x1aa,%eax
je     11ce <is_sdhc+0x6e>
mov    $0x0,%al
call   1030 <wait_init@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bb <is_sdhc+0x15b>
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
movl   $0x32,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     12b4 <is_sdhc+0x154>
mov    $0x0,%al
call   1070 <wait_initV2@plt>
cmp    $0x0,%rax
je     128d <is_sdhc+0x12d>
mov    $0xff007a,%edi
xor    %esi,%esi
call   1080 <cmd_write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    1288 <is_sdhc+0x128>
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    $0xffffffd4,%eax
mov    (%rax),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    -0xc(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     127c <is_sdhc+0x11c>
movl   $0x1,-0x4(%rbp)
jmp    12bb <is_sdhc+0x15b>
movl   $0x0,-0x4(%rbp)
jmp    12bb <is_sdhc+0x15b>
jmp    128d <is_sdhc+0x12d>
cmpl   $0x2,-0x8(%rbp)
jne    12af <is_sdhc+0x14f>
lea    0xd62(%rip),%rdi
call   1060 <OSD_Puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bb <is_sdhc+0x15b>
jmp    11e0 <is_sdhc+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_sdhc>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <spi_spin@plt>
mov    $0x870048,%edi
mov    $0x1aa,%esi
call   1080 <cmd_write@plt>
cmp    $0x1,%eax
jne    11fe <is_sdhc+0x9e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <SPI_PUMP@plt>
movzwl %ax,%eax
cmp    $0x1aa,%eax
jne    11fe <is_sdhc+0x9e>
mov    $0xffffffd4,%r14d
movl   $0xff,(%r14)
mov    $0xffffffd0,%ebx
jmp    11b4 <is_sdhc+0x54>
nopl   0x0(%rax,%rax,1)
inc    %ebx
je     120f <is_sdhc+0xaf>
xor    %eax,%eax
call   1070 <wait_initV2@plt>
test   %rax,%rax
je     11b0 <is_sdhc+0x50>
mov    $0xff007a,%edi
xor    %esi,%esi
call   1080 <cmd_write@plt>
test   %eax,%eax
jne    11b0 <is_sdhc+0x50>
movl   $0xff,(%r14)
mov    (%r14),%ebx
movl   $0xff,(%r14)
movl   $0xff,(%r14)
movl   $0xff,(%r14)
movl   $0xff,(%r14)
shr    $0x6,%ebx
and    $0x1,%ebx
jmp    1205 <is_sdhc+0xa5>
xor    %eax,%eax
call   1030 <wait_init@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdea(%rip),%rdi
call   1060 <OSD_Puts@plt>
xor    %ebx,%ebx
jmp    1205 <is_sdhc+0xa5>

LLVM IR (-O0):
@.str = [13 x i8] c"SDHC error!\0A\00"
define i32 @is_sdhc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @spi_spin()
%5 = call i32 @cmd_write(i32 8847432, i32 426)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (...) @wait_init()
store i32 0, i32* %1
br label %44
10: ; preds = %0
%11 = call i32 (...) @SPI_PUMP()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = and i32 %12, 65535
%14 = icmp ne i32 %13, 426
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 (...) @wait_init()
store i32 0, i32* %1
br label %44
17: ; preds = %10
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store i32 50, i32* %2
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, -1
store i32 %20, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = call i64 (...) @wait_initV2()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = call i32 @cmd_write(i32 16711802, i32 0)
store i32 %26, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %25
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%29 = load volatile i32, i32* inttoptr (i64 4294967252 to i32*)
%30 = and i32 %29, 255
store i32 %30, i32* %3
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%31 = load i32, i32* %3
%32 = and i32 %31, 64
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 1, i32* %1
br label %44
35: ; preds = %28
store i32 0, i32* %1
br label %44
36: ; preds = %25
br label %37
37: ; preds = %36, %22
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @OSD_Puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %44
42: ; preds = %37
br label %18
43: ; preds = %18
store i32 0, i32* %1
br label %44
44: ; preds = %43, %40, %35, %34, %15, %8
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [13 x i8] c"SDHC error!\0A\00"
define i32 @is_sdhc() {
%1 = tail call i32 (...) @spi_spin()
%2 = tail call i32 @cmd_write(i32 8847432, i32 426)
%3 = icmp eq i32 %2, 1
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 (...) @wait_init()
br label %29
6: ; preds = %0
%7 = tail call i32 (...) @SPI_PUMP()
%8 = and i32 %7, 65535
%9 = icmp eq i32 %8, 426
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 (...) @wait_init()
br label %29
12: ; preds = %6
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
br label %13
13: ; preds = %12, %25
%14 = phi i32 [ 50, %12 ], [ %15, %25 ]
%15 = add nsw i32 %14, -1
%16 = tail call i64 (...) @wait_initV2()
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %13
%19 = tail call i32 @cmd_write(i32 16711802, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%22 = load volatile i32, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%23 = lshr i32 %22, 6
%24 = and i32 %23, 1
br label %29
25: ; preds = %18, %13
%26 = icmp eq i32 %15, 2
br i1 %26, label %27, label %13
27: ; preds = %25
%28 = tail call i32 @OSD_Puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %21, %27, %10, %4
%30 = phi i32 [ 0, %4 ], [ 0, %10 ], [ 0, %27 ], [ %24, %21 ]
ret i32 %30
}