#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 /*<<< orphan*/ sleep(int);
void eth_reset_phy(void) {
  printf("Resetting PHY, waiting for link");
  *((volatile unsigned long *)(0x92000000 + 0x30)) = (0 << 8) | (0x00 & 0xff);
  *((volatile unsigned long *)(0x92000000 + 0x34)) = 0x8000;
  *((volatile unsigned long *)(0x92000000 + 0x2C)) = 0x00000004;
  while (*((volatile unsigned long *)(0x92000000 + 0x3C)) & 0x00000002)
    ;
  sleep(100);
  while (1) {
    printf(".");
    *((volatile unsigned long *)(0x92000000 + 0x30)) = (0 << 8) | (0x00 & 0xff);
    *((volatile unsigned long *)(0x92000000 + 0x2C)) = 0x00000002;
    while (*((volatile unsigned long *)(0x92000000 + 0x3C)) & 0x00000002)
      ;
    if (!(*((volatile unsigned long *)(0x92000000 + 0x38)) & 0x8000))
      break;
  }
}


x86 assembly (clang, -O0):
<eth_reset_phy>:
push   %rbp
mov    %rsp,%rbp
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x92000030,%eax
movq   $0x0,(%rax)
mov    $0x92000034,%eax
movq   $0x8000,(%rax)
mov    $0x9200002c,%eax
movq   $0x4,(%rax)
mov    $0x9200003c,%eax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     116f <eth_reset_phy+0x4f>
jmp    1154 <eth_reset_phy+0x34>
mov    $0x64,%edi
call   1040 <sleep@plt>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x92000030,%eax
movq   $0x0,(%rax)
mov    $0x9200002c,%eax
movq   $0x2,(%rax)
mov    $0x9200003c,%eax
mov    (%rax),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     11b8 <eth_reset_phy+0x98>
jmp    119d <eth_reset_phy+0x7d>
mov    $0x92000038,%eax
mov    (%rax),%rax
and    $0x8000,%rax
cmp    $0x0,%rax
jne    11d5 <eth_reset_phy+0xb5>
jmp    11da <eth_reset_phy+0xba>
jmp    1179 <eth_reset_phy+0x59>
pop    %rbp
ret

x86 assembly (clang, -O2):
<eth_reset_phy>:
push   %rbx
mov    $0x9200002c,%ebx
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,0x4(%rbx)
movq   $0x8000,0x8(%rbx)
movq   $0x4,(%rbx)
nopl   0x0(%rax)
testq  $0x2,0x10(%rbx)
jne    1160 <eth_reset_phy+0x30>
mov    $0x64,%edi
call   1050 <sleep@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2e,%edi
call   1030 <putchar@plt>
movq   $0x0,0x4(%rbx)
movq   $0x2,(%rbx)
nopl   0x0(%rax)
testq  $0x2,0x10(%rbx)
jne    11a0 <eth_reset_phy+0x70>
testq  $0x8000,0xc(%rbx)
jne    1180 <eth_reset_phy+0x50>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Resetting PHY, waiting for link\00"
@.str.1 = [2 x i8] c".\00"
define void @eth_reset_phy() {
%1 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store volatile i64 0, i64* inttoptr (i64 2449473584 to i64*)
store volatile i64 32768, i64* inttoptr (i64 2449473588 to i64*)
store volatile i64 4, i64* inttoptr (i64 2449473580 to i64*)
br label %2
2: ; preds = %6, %0
%3 = load volatile i64, i64* inttoptr (i64 2449473596 to i64*)
%4 = and i64 %3, 2
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %2
br label %2
7: ; preds = %2
%8 = call i32 @sleep(i32 100)
br label %9
9: ; preds = %7, %21
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store volatile i64 0, i64* inttoptr (i64 2449473584 to i64*)
store volatile i64 2, i64* inttoptr (i64 2449473580 to i64*)
br label %11
11: ; preds = %15, %9
%12 = load volatile i64, i64* inttoptr (i64 2449473596 to i64*)
%13 = and i64 %12, 2
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
%17 = load volatile i64, i64* inttoptr (i64 2449473592 to i64*)
%18 = and i64 %17, 32768
%19 = icmp ne i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
br label %22
21: ; preds = %16
br label %9
22: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Resetting PHY, waiting for link\00"
define void @eth_reset_phy() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store volatile i64 0, i64* inttoptr (i64 2449473584 to i64*)
store volatile i64 32768, i64* inttoptr (i64 2449473588 to i64*)
store volatile i64 4, i64* inttoptr (i64 2449473580 to i64*)
br label %2
2: ; preds = %2, %0
%3 = load volatile i64, i64* inttoptr (i64 2449473596 to i64*)
%4 = and i64 %3, 2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %2
6: ; preds = %2
%7 = tail call i32 @sleep(i32 100)
br label %8
8: ; preds = %14, %6
%9 = tail call i32 @putchar(i32 46)
store volatile i64 0, i64* inttoptr (i64 2449473584 to i64*)
store volatile i64 2, i64* inttoptr (i64 2449473580 to i64*)
br label %10
10: ; preds = %10, %8
%11 = load volatile i64, i64* inttoptr (i64 2449473596 to i64*)
%12 = and i64 %11, 2
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = load volatile i64, i64* inttoptr (i64 2449473592 to i64*)
%16 = and i64 %15, 32768
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %14
ret void
}