#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*/ read_block(void *, unsigned long);
int /*<<< orphan*/ sd_delay(int);
int SD_read_lba(void *buff, unsigned long lba) {
  int retries = 5;
  sd_delay(8);
  while (retries--) {
    if (!read_block(buff, lba)) {
      return 0;
    }
    sd_delay(20);
  }
  return -1;
}


x86 assembly (clang, -O0):
<SD_read_lba>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
mov    $0x8,%edi
call   1030 <sd_delay@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1186 <SD_read_lba+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <read_block@plt>
cmp    $0x0,%eax
jne    1177 <SD_read_lba+0x57>
movl   $0x0,-0x4(%rbp)
jmp    118d <SD_read_lba+0x6d>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
jmp    1141 <SD_read_lba+0x21>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SD_read_lba>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x8,%edi
call   1030 <sd_delay@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <read_block@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11ba <SD_read_lba+0x9a>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <read_block@plt>
test   %eax,%eax
je     11ba <SD_read_lba+0x9a>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <read_block@plt>
test   %eax,%eax
je     11ba <SD_read_lba+0x9a>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <read_block@plt>
test   %eax,%eax
je     11ba <SD_read_lba+0x9a>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <read_block@plt>
test   %eax,%eax
je     11ba <SD_read_lba+0x9a>
mov    $0x14,%edi
call   1030 <sd_delay@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SD_read_lba(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 5, i32* %6
%7 = call i32 @sd_delay(i32 8)
br label %8
8: ; preds = %18, %2
%9 = load i32, i32* %6
%10 = add nsw i32 %9, -1
store i32 %10, i32* %6
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i32 @read_block(i8* %13, i64 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %3
br label %21
18: ; preds = %12
%19 = call i32 @sd_delay(i32 20)
br label %8
20: ; preds = %8
store i32 -1, i32* %3
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @SD_read_lba(i8* %0, i64 %1) {
%3 = tail call i32 @sd_delay(i32 8)
%4 = tail call i32 @read_block(i8* %0, i64 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = tail call i32 @sd_delay(i32 20)
%8 = tail call i32 @read_block(i8* %0, i64 %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = tail call i32 @sd_delay(i32 20)
%12 = tail call i32 @read_block(i8* %0, i64 %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = tail call i32 @sd_delay(i32 20)
%16 = tail call i32 @read_block(i8* %0, i64 %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = tail call i32 @sd_delay(i32 20)
%20 = tail call i32 @read_block(i8* %0, i64 %1)
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @sd_delay(i32 20)
br label %24
24: ; preds = %22, %18, %14, %10, %6, %2
%25 = phi i32 [ 0, %2 ], [ 0, %6 ], [ 0, %10 ], [ 0, %14 ], [ 0, %18 ], [ -1, %22 ]
ret i32 %25
}