#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
unsigned long rareg(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
void wait_pciephy_busy(void) {
  unsigned long reg_value = 0x0;
  int retry = 0;
  while (1) {
    reg_value = rareg(0x0, 0x10140090, 0);
    if (reg_value & 0x80000000) {
      printf("PCIE-PHY is busy, sleep 1 sec.\n");
      sleep(1);
      retry++;
    } else
      break;
    if (retry > 3) {
      printf("PCIE-PHY retry failed.\n");
      exit(-1);
    }
  }
}


x86 assembly (clang, -O0):
<wait_pciephy_busy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %edx,%edx
mov    $0x10140090,%esi
mov    %edx,%edi
call   1060 <rareg@plt>
mov    %rax,-0x8(%rbp)
movabs $0x80000000,%rax
and    -0x8(%rbp),%rax
cmp    $0x0,%rax
je     11a5 <wait_pciephy_busy+0x65>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11aa <wait_pciephy_busy+0x6a>
jmp    11cf <wait_pciephy_busy+0x8f>
cmpl   $0x3,-0xc(%rbp)
jle    11ca <wait_pciephy_busy+0x8a>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
jmp    1157 <wait_pciephy_busy+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_pciephy_busy>:
push   %rax
xor    %edi,%edi
mov    $0x10140090,%esi
xor    %edx,%edx
call   1060 <rareg@plt>
test   $0x80000000,%eax
je     11db <wait_pciephy_busy+0x9b>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
mov    $0x10140090,%esi
xor    %edx,%edx
call   1060 <rareg@plt>
test   $0x80000000,%eax
je     11db <wait_pciephy_busy+0x9b>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
mov    $0x10140090,%esi
xor    %edx,%edx
call   1060 <rareg@plt>
test   $0x80000000,%eax
je     11db <wait_pciephy_busy+0x9b>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
mov    $0x10140090,%esi
xor    %edx,%edx
call   1060 <rareg@plt>
test   $0x80000000,%eax
jne    11dd <wait_pciephy_busy+0x9d>
pop    %rax
ret
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"PCIE-PHY is busy, sleep 1 sec.\0A\00"
@.str.1 = [24 x i8] c"PCIE-PHY retry failed.\0A\00"
define void @wait_pciephy_busy() {
%1 = alloca i64
%2 = alloca i32
store i64 0, i64* %1
store i32 0, i32* %2
br label %3
3: ; preds = %0, %20
%4 = call i64 @rareg(i32 0, i32 269746320, i32 0)
store i64 %4, i64* %1
%5 = load i64, i64* %1
%6 = and i64 %5, 2147483648
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @sleep(i32 1)
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
br label %14
13: ; preds = %3
br label %21
14: ; preds = %8
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 3
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %14
br label %3
21: ; preds = %13
ret void
}

LLVM IR (-O2):
@str = [31 x i8] c"PCIE-PHY is busy, sleep 1 sec.\00"
@str.2 = [23 x i8] c"PCIE-PHY retry failed.\00"
define void @wait_pciephy_busy() {
%1 = tail call i64 @rareg(i32 0, i32 269746320, i32 0)
%2 = and i64 %1, 2147483648
%3 = icmp eq i64 %2, 0
br i1 %3, label %27, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i64 @rareg(i32 0, i32 269746320, i32 0)
%8 = and i64 %7, 2147483648
%9 = icmp eq i64 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i64 @rareg(i32 0, i32 269746320, i32 0)
%14 = and i64 %13, 2147483648
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i64 @rareg(i32 0, i32 269746320, i32 0)
%20 = and i64 %19, 2147483648
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @sleep(i32 1)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %16, %10, %4, %0
ret void
}