#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*/ die(char *);
int read_word(int, unsigned int *);
int /*<<< orphan*/ usleep(int);
int wait_flash_ready(void) {
  int retry = 0, r;
  unsigned int status;
  do {
    r = read_word(0xFFFFFF68, &status);
    if (r)
      die("error while readying flash status");
    usleep(10000);
    if ((status & 1) == 1)
      return 0;
  } while (++retry < 100);
  return -1;
}


x86 assembly (clang, -O0):
<wait_flash_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0xffffff68,%edi
lea    -0x10(%rbp),%rsi
call   1030 <read_word@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1166 <wait_flash_ready+0x36>
lea    0xe9f(%rip),%rdi
call   1040 <die@plt>
mov    $0x2710,%edi
call   1050 <usleep@plt>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    118b <wait_flash_ready+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <wait_flash_ready+0x79>
jmp    1190 <wait_flash_ready+0x60>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x64,%eax
jl     113f <wait_flash_ready+0xf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_flash_ready>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x64,%ebp
lea    0xc(%rsp),%rbx
lea    0xeb7(%rip),%r14
nopl   0x0(%rax)
mov    $0xffffff68,%edi
mov    %rbx,%rsi
call   1030 <read_word@plt>
test   %eax,%eax
je     1169 <wait_flash_ready+0x39>
mov    %r14,%rdi
call   1040 <die@plt>
mov    $0x2710,%edi
call   1050 <usleep@plt>
testb  $0x1,0xc(%rsp)
jne    1186 <wait_flash_ready+0x56>
add    $0xffffffff,%ebp
jne    1150 <wait_flash_ready+0x20>
mov    $0xffffffff,%eax
jmp    1188 <wait_flash_ready+0x58>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"error while readying flash status\00"
define i32 @wait_flash_ready() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
br label %5
5: ; preds = %18, %0
%6 = call i32 @read_word(i32 -152, i32* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = call i32 @usleep(i32 10000)
%13 = load i32, i32* %4
%14 = and i32 %13, 1
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 0, i32* %1
br label %23
17: ; preds = %11
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = icmp slt i32 %20, 100
br i1 %21, label %5, label %22
22: ; preds = %18
store i32 -1, i32* %1
br label %23
23: ; preds = %22, %16
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [34 x i8] c"error while readying flash status\00"
define i32 @wait_flash_ready() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %14, %0
%4 = phi i32 [ 0, %0 ], [ %15, %14 ]
%5 = call i32 @read_word(i32 -152, i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = call i32 @usleep(i32 10000)
%11 = load i32, i32* %1
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 100
br i1 %16, label %17, label %3
17: ; preds = %14, %9
%18 = phi i32 [ 0, %9 ], [ -1, %14 ]
ret i32 %18
}