#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*/ fflush(int /*<<< orphan*/);
int mdio_read(long, int, int);
int /*<<< orphan*/ printf(char *, char *, unsigned int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
void monitor_status(long ioaddr, int phy_id) {
  unsigned int baseline_1 = 0x55555555;
  while (1) {
    unsigned int new_1 = mdio_read(ioaddr, phy_id, 1);
    if (new_1 != baseline_1) {
      printf("%-12s 0x%4.4x 0x%4.4x\n",
             new_1 & 0x04   ? (new_1 == 0xffff ? "unknown" : "up")
             : new_1 & 0x20 ? "negotiating"
                            : "down",
             new_1, mdio_read(ioaddr, phy_id, 5));
      fflush(stdout);
      baseline_1 = new_1;
    }
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<monitor_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x55555555,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1050 <mdio_read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1210 <monitor_status+0xd0>
mov    -0x14(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11a9 <monitor_status+0x69>
mov    -0x14(%rbp),%edx
lea    0xe90(%rip),%rax
lea    0xe81(%rip),%rcx
cmp    $0xffff,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11c8 <monitor_status+0x88>
mov    -0x14(%rbp),%edx
and    $0x20,%edx
lea    0xe78(%rip),%rax
lea    0xe65(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x5,%edx
call   1050 <mdio_read@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1156 <monitor_status+0x16>

x86 assembly (clang, -O2):
<monitor_status>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
mov    $0x55555555,%ebx
lea    0xea3(%rip),%r14
mov    0x2e7c(%rip),%r13
jmp    11ba <monitor_status+0x7a>
cs nopw 0x0(%rax,%rax,1)
test   $0x20,%bpl
lea    0xea7(%rip),%rbx
lea    0xeac(%rip),%rax
cmove  %rax,%rbx
mov    %r12,%rdi
mov    %r15d,%esi
mov    $0x5,%edx
call   1050 <mdio_read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    0x0(%r13),%edi
call   1040 <fflush@plt>
mov    %ebp,%ebx
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1050 <mdio_read@plt>
cmp    %ebx,%eax
je     11b0 <monitor_status+0x70>
mov    %eax,%ebp
test   $0x4,%bpl
je     1170 <monitor_status+0x30>
cmp    $0xffff,%ebp
lea    0xe3c(%rip),%rbx
lea    0xe2d(%rip),%rax
jmp    1182 <monitor_status+0x42>

LLVM IR (-O0):
@.str = [23 x i8] c"%-12s 0x%4.4x 0x%4.4x\0A\00"
@.str.1 = [8 x i8] c"unknown\00"
@.str.2 = [3 x i8] c"up\00"
@.str.3 = [12 x i8] c"negotiating\00"
@.str.4 = [5 x i8] c"down\00"
@stdout = global i32 0
define void @monitor_status(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
store i32 1431655765, i32* %5
br label %7
7: ; preds = %2, %39
%8 = load i64, i64* %3
%9 = load i32, i32* %4
%10 = call i32 @mdio_read(i64 %8, i32 %9, i32 1)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %39
14: ; preds = %7
%15 = load i32, i32* %6
%16 = and i32 %15, 4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 65535
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %29
23: ; preds = %14
%24 = load i32, i32* %6
%25 = and i32 %24, 32
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
br label %29
29: ; preds = %23, %18
%30 = phi i8* [ %22, %18 ], [ %28, %23 ]
%31 = load i32, i32* %6
%32 = load i64, i64* %3
%33 = load i32, i32* %4
%34 = call i32 @mdio_read(i64 %32, i32 %33, i32 5)
%35 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %30, i32 %31, i32 %34)
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
%38 = load i32, i32* %6
store i32 %38, i32* %5
br label %39
39: ; preds = %29, %7
%40 = call i32 @sleep(i32 1)
br label %7
}

LLVM IR (-O2):
@.str = [23 x i8] c"%-12s 0x%4.4x 0x%4.4x\0A\00"
@.str.1 = [8 x i8] c"unknown\00"
@.str.2 = [3 x i8] c"up\00"
@.str.3 = [12 x i8] c"negotiating\00"
@.str.4 = [5 x i8] c"down\00"
@stdout = global i32 0
define void @monitor_status(i64 %0, i32 %1) {
br label %3
3: ; preds = %23, %2
%4 = phi i32 [ 1431655765, %2 ], [ %24, %23 ]
%5 = tail call i32 @mdio_read(i64 %0, i32 %1, i32 1)
%6 = icmp eq i32 %5, %4
br i1 %6, label %23, label %7
7: ; preds = %3
%8 = and i32 %5, 4
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = icmp eq i32 %5, 65535
%12 = select i1 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %17
13: ; preds = %7
%14 = and i32 %5, 32
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0)
br label %17
17: ; preds = %13, %10
%18 = phi i8* [ %12, %10 ], [ %16, %13 ]
%19 = tail call i32 @mdio_read(i64 %0, i32 %1, i32 5)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %5, i32 %19)
%21 = load i32, i32* @stdout
%22 = tail call i32 @fflush(i32 %21)
br label %23
23: ; preds = %17, %3
%24 = phi i32 [ %5, %17 ], [ %4, %3 ]
%25 = tail call i32 @sleep(i32 1)
br label %3
}