#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ SPI_Read(int *, int);
int /*<<< orphan*/ SPI_Send(int *, int);
scalar_t__ mmcStatus(int);
int /*<<< orphan*/ selectMMC();
int /*<<< orphan*/ spiGetByte();
int /*<<< orphan*/ unselectMMC();
bool _cc3_mmc_block_read(uint32_t sector, uint8_t *buf) {
  uint8_t MMCCmd[8];
  sector <<= 1;
  selectMMC();
  MMCCmd[0] = 0x51;
  MMCCmd[1] = (sector >> 16) & 0xff;
  MMCCmd[2] = (sector >> 8) & 0xff;
  MMCCmd[3] = sector & 0xff;
  MMCCmd[4] = 0;
  MMCCmd[5] = 0xff;
  SPI_Send(MMCCmd, 6);
  if (mmcStatus(0x00)) {
    if (mmcStatus(0xFE)) {
      SPI_Read(buf, 512);
      spiGetByte();
      spiGetByte();
    } else {
      unselectMMC();
      spiGetByte();
      return true;
    }
  } else {
    unselectMMC();
    spiGetByte();
    return true;
  }
  unselectMMC();
  spiGetByte();
  return false;
}


x86 assembly (clang, -O0):
<_cc3_mmc_block_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <selectMMC@plt>
movl   $0x51,-0x30(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xff,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x6,%esi
call   1070 <SPI_Send@plt>
xor    %edi,%edi
call   1080 <mmcStatus@plt>
cmp    $0x0,%rax
je     122e <_cc3_mmc_block_read+0xce>
mov    $0xfe,%edi
call   1080 <mmcStatus@plt>
cmp    $0x0,%rax
je     120f <_cc3_mmc_block_read+0xaf>
mov    -0x10(%rbp),%rdi
mov    $0x200,%esi
call   1040 <SPI_Read@plt>
mov    $0x0,%al
call   1060 <spiGetByte@plt>
mov    $0x0,%al
call   1060 <spiGetByte@plt>
jmp    1229 <_cc3_mmc_block_read+0xc9>
mov    $0x0,%al
call   1030 <unselectMMC@plt>
mov    $0x0,%al
call   1060 <spiGetByte@plt>
movl   $0x1,-0x4(%rbp)
jmp    125d <_cc3_mmc_block_read+0xfd>
jmp    1248 <_cc3_mmc_block_read+0xe8>
mov    $0x0,%al
call   1030 <unselectMMC@plt>
mov    $0x0,%al
call   1060 <spiGetByte@plt>
movl   $0x1,-0x4(%rbp)
jmp    125d <_cc3_mmc_block_read+0xfd>
mov    $0x0,%al
call   1030 <unselectMMC@plt>
mov    $0x0,%al
call   1060 <spiGetByte@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cc3_mmc_block_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x0(%rbp,%rbp,1),%ebx
xor    %eax,%eax
call   1050 <selectMMC@plt>
movl   $0x51,(%rsp)
mov    %ebp,%eax
shr    $0xf,%eax
movzbl %al,%eax
mov    %eax,0x4(%rsp)
shr    $0x7,%ebp
movzbl %bpl,%eax
mov    %eax,0x8(%rsp)
movzbl %bl,%eax
mov    %eax,0xc(%rsp)
movabs $0xff00000000,%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
mov    $0x6,%esi
call   1070 <SPI_Send@plt>
xor    %edi,%edi
call   1080 <mmcStatus@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11f6 <_cc3_mmc_block_read+0x96>
mov    $0xfe,%edi
call   1080 <mmcStatus@plt>
test   %rax,%rax
je     11f6 <_cc3_mmc_block_read+0x96>
mov    %r14,%rdi
mov    $0x200,%esi
call   1040 <SPI_Read@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <spiGetByte@plt>
xor    %eax,%eax
call   1060 <spiGetByte@plt>
xor    %eax,%eax
call   1030 <unselectMMC@plt>
xor    %eax,%eax
call   1060 <spiGetByte@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_cc3_mmc_block_read(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [8 x i32]
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = shl i32 %7, 1
store i32 %8, i32* %4
%9 = call i32 (...) @selectMMC()
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
store i32 81, i32* %10
%11 = load i32, i32* %4
%12 = ashr i32 %11, 16
%13 = and i32 %12, 255
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 1
store i32 %13, i32* %14
%15 = load i32, i32* %4
%16 = ashr i32 %15, 8
%17 = and i32 %16, 255
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 2
store i32 %17, i32* %18
%19 = load i32, i32* %4
%20 = and i32 %19, 255
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 3
store i32 %20, i32* %21
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 4
store i32 0, i32* %22
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 5
store i32 255, i32* %23
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%25 = call i32 @SPI_Send(i32* %24, i32 6)
%26 = call i64 @mmcStatus(i32 0)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %2
%29 = call i64 @mmcStatus(i32 254)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32*, i32** %5
%33 = call i32 @SPI_Read(i32* %32, i32 512)
%34 = call i32 (...) @spiGetByte()
%35 = call i32 (...) @spiGetByte()
br label %39
36: ; preds = %28
%37 = call i32 (...) @unselectMMC()
%38 = call i32 (...) @spiGetByte()
store i32 1, i32* %3
br label %46
39: ; preds = %31
br label %43
40: ; preds = %2
%41 = call i32 (...) @unselectMMC()
%42 = call i32 (...) @spiGetByte()
store i32 1, i32* %3
br label %46
43: ; preds = %39
%44 = call i32 (...) @unselectMMC()
%45 = call i32 (...) @spiGetByte()
store i32 0, i32* %3
br label %46
46: ; preds = %43, %40, %36
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @_cc3_mmc_block_read(i32 %0, i32* %1) {
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %3 to i8*
%5 = shl i32 %0, 1
%6 = tail call i32 (...) @selectMMC()
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
store i32 81, i32* %7
%8 = lshr i32 %5, 16
%9 = and i32 %8, 255
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 1
store i32 %9, i32* %10
%11 = lshr i32 %5, 8
%12 = and i32 %11, 255
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 2
store i32 %12, i32* %13
%14 = and i32 %5, 254
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 3
store i32 %14, i32* %15
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
store i32 0, i32* %16
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 5
store i32 255, i32* %17
%18 = call i32 @SPI_Send(i32* %7, i32 6)
%19 = call i64 @mmcStatus(i32 0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %2
%22 = call i64 @mmcStatus(i32 254)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @SPI_Read(i32* %1, i32 512)
%26 = call i32 (...) @spiGetByte()
%27 = call i32 (...) @spiGetByte()
br label %28
28: ; preds = %2, %21, %24
%29 = phi i32 [ 0, %24 ], [ 1, %21 ], [ 1, %2 ]
%30 = call i32 (...) @unselectMMC()
%31 = call i32 (...) @spiGetByte()
ret i32 %29
}