#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*/ printf(char *);
int ide_wait_dma() {
  unsigned int status;
  int i;
  for (i = 0; i < 10000000; i++) {
    status = (*((volatile unsigned long *)(0xA05F7000 + 0x418)));
    if ((status & 1) == 0)
      return 0;
  }
  printf("[IDE] Timeout waiting for DMA to become ready\n");
  return 1;
}


x86 assembly (clang, -O0):
<ide_wait_dma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
cmpl   $0x989680,-0xc(%rbp)
jge    1165 <ide_wait_dma+0x55>
mov    $0xa05f7418,%eax
mov    (%rax),%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1152 <ide_wait_dma+0x42>
movl   $0x0,-0x4(%rbp)
jmp    1178 <ide_wait_dma+0x68>
jmp    1157 <ide_wait_dma+0x47>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    111f <ide_wait_dma+0xf>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ide_wait_dma>:
push   %rax
mov    $0x989680,%ecx
mov    $0xa05f7418,%edx
xor    %eax,%eax
nopl   (%rax)
testq  $0x1,(%rdx)
je     1163 <ide_wait_dma+0x53>
testq  $0x1,(%rdx)
je     1163 <ide_wait_dma+0x53>
testq  $0x1,(%rdx)
je     1163 <ide_wait_dma+0x53>
testq  $0x1,(%rdx)
je     1163 <ide_wait_dma+0x53>
testq  $0x1,(%rdx)
je     1163 <ide_wait_dma+0x53>
add    $0xfffffffb,%ecx
jne    1120 <ide_wait_dma+0x10>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@str = [46 x i8] c"[IDE] Timeout waiting for DMA to become ready\00"
define i32 @ide_wait_dma() {
br label %20
1: ; preds = %20
%2 = load volatile i64, i64* inttoptr (i64 2690610200 to i64*)
%3 = and i64 %2, 1
%4 = icmp eq i64 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = load volatile i64, i64* inttoptr (i64 2690610200 to i64*)
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %5
%10 = load volatile i64, i64* inttoptr (i64 2690610200 to i64*)
%11 = and i64 %10, 1
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %9
%14 = load volatile i64, i64* inttoptr (i64 2690610200 to i64*)
%15 = and i64 %14, 1
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = add nuw nsw i32 %21, 5
%19 = icmp eq i32 %18, 10000000
br i1 %19, label %25, label %20
20: ; preds = %17, %0
%21 = phi i32 [ 0, %0 ], [ %18, %17 ]
%22 = load volatile i64, i64* inttoptr (i64 2690610200 to i64*)
%23 = and i64 %22, 1
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %1
25: ; preds = %17
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %20, %1, %5, %9, %13, %25
%28 = phi i32 [ 1, %25 ], [ 0, %13 ], [ 0, %9 ], [ 0, %5 ], [ 0, %1 ], [ 0, %20 ]
ret i32 %28
}