#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*/ ide_dump_registers();
int /*<<< orphan*/ printf(char *, unsigned char);
int ide_wait_ready() {
  unsigned char status;
  int i;
  for (i = 0; i < 10000000; i++) {
    status = (unsigned int)(*((volatile unsigned char *)(0xA05F7000 + 0x018)));
    if ((status & 0x80) == 0)
      return 0;
  }
  printf("Timeout waiting for IDE to become ready (status = 0x%02X)\n", status);
  ide_dump_registers();
  return 1;
}


x86 assembly (clang, -O0):
<ide_wait_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
cmpl   $0x989680,-0xc(%rbp)
jge    117a <ide_wait_ready+0x5a>
mov    $0xa05f7018,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1167 <ide_wait_ready+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1198 <ide_wait_ready+0x78>
jmp    116c <ide_wait_ready+0x4c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112f <ide_wait_ready+0xf>
lea    0xe7f(%rip),%rdi
movzbl -0x5(%rbp),%esi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <ide_dump_registers@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ide_wait_ready>:
push   %rax
mov    $0x989680,%ecx
mov    $0xa05f7018,%esi
xor    %eax,%eax
nopl   (%rax)
cmpb   $0x0,(%rsi)
jns    116b <ide_wait_ready+0x4b>
cmpb   $0x0,(%rsi)
jns    116b <ide_wait_ready+0x4b>
cmpb   $0x0,(%rsi)
jns    116b <ide_wait_ready+0x4b>
cmpb   $0x0,(%rsi)
jns    116b <ide_wait_ready+0x4b>
movzbl (%rsi),%edx
test   %dl,%dl
jns    116b <ide_wait_ready+0x4b>
add    $0xfffffffb,%ecx
jne    1130 <ide_wait_ready+0x10>
movzbl %dl,%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <ide_dump_registers@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Timeout waiting for IDE to become ready (status = 0x%02X)\0A\00"
define i32 @ide_wait_ready() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %17, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10000000
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%9 = zext i8 %8 to i32
%10 = trunc i32 %9 to i8
store i8 %10, i8* %2
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = and i32 %12, 128
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %7
store i32 0, i32* %1
br label %24
16: ; preds = %7
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %4
20: ; preds = %4
%21 = load i8, i8* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8 zeroext %21)
%23 = call i32 (...) @ide_dump_registers()
store i32 1, i32* %1
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [59 x i8] c"Timeout waiting for IDE to become ready (status = 0x%02X)\0A\00"
define i32 @ide_wait_ready() {
br label %16
1: ; preds = %16
%2 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%3 = icmp sgt i8 %2, -1
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%6 = icmp sgt i8 %5, -1
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%9 = icmp sgt i8 %8, -1
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%12 = icmp sgt i8 %11, -1
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = add nuw nsw i32 %17, 5
%15 = icmp eq i32 %14, 10000000
br i1 %15, label %20, label %16
16: ; preds = %13, %0
%17 = phi i32 [ 0, %0 ], [ %14, %13 ]
%18 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%19 = icmp sgt i8 %18, -1
br i1 %19, label %23, label %1
20: ; preds = %13
%21 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%22 = tail call i32 (...) @ide_dump_registers()
br label %23
23: ; preds = %16, %1, %4, %7, %10, %20
%24 = phi i32 [ 1, %20 ], [ 0, %10 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ], [ 0, %16 ]
ret i32 %24
}