#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 */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int INR_PCI_MMI_read(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ usleep(int);
uint8_t INR_MDIO_read_b(uint16_t *data) {
  uint8_t busy = 0;
  uint32_t value = 0;
  value = INR_PCI_MMI_read(((0x04 << 0) | (0x0001 << 8)));
  usleep(50);
  if (value == 0xeeeeeeee) {
    printf("MMI read timeout\n");
    return 0;
  }
  busy = 1 & (value >> 31);
  if (data)
    *data = value & 0xffff;
  return busy;
}


x86 assembly (clang, -O0):
<INR_MDIO_read_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x104,%edi
call   1040 <INR_PCI_MMI_read@plt>
mov    %eax,-0x18(%rbp)
mov    $0x32,%edi
call   1050 <usleep@plt>
cmpl   $0xeeeeeeee,-0x18(%rbp)
jne    1186 <INR_MDIO_read_b+0x56>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <INR_MDIO_read_b+0x82>
mov    -0x18(%rbp),%eax
sar    $0x1f,%eax
and    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ac <INR_MDIO_read_b+0x7c>
mov    -0x18(%rbp),%ecx
and    $0xffff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INR_MDIO_read_b>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x104,%edi
call   1040 <INR_PCI_MMI_read@plt>
mov    %eax,%ebp
mov    $0x32,%edi
call   1050 <usleep@plt>
cmp    $0xeeeeeeee,%ebp
jne    1164 <INR_MDIO_read_b+0x34>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1173 <INR_MDIO_read_b+0x43>
mov    %ebp,%eax
shr    $0x1f,%eax
test   %rbx,%rbx
je     1173 <INR_MDIO_read_b+0x43>
movzwl %bp,%ecx
mov    %ecx,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"MMI read timeout\0A\00"
define i32 @INR_MDIO_read_b(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 @INR_PCI_MMI_read(i32 260)
store i32 %6, i32* %5
%7 = call i32 @usleep(i32 50)
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, -286331154
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %5
%14 = ashr i32 %13, 31
%15 = and i32 1, %14
store i32 %15, i32* %4
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* %5
%20 = and i32 %19, 65535
%21 = load i32*, i32** %3
store i32 %20, i32* %21
br label %22
22: ; preds = %18, %12
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@str = [17 x i8] c"MMI read timeout\00"
define i32 @INR_MDIO_read_b(i32* writeonly %0) {
%2 = tail call i32 @INR_PCI_MMI_read(i32 260)
%3 = tail call i32 @usleep(i32 50)
%4 = icmp eq i32 %2, -286331154
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %12
7: ; preds = %1
%8 = lshr i32 %2, 31
%9 = icmp eq i32* %0, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = and i32 %2, 65535
store i32 %11, i32* %0
br label %12
12: ; preds = %7, %10, %5
%13 = phi i32 [ 0, %5 ], [ %8, %10 ], [ %8, %7 ]
ret i32 %13
}