#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 volatile uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
uint16_t EMACPHYRead(uint32_t ui32Base, uint8_t ui8PhyAddr,
                     uint8_t ui8RegAddr) {
  ASSERT(ui8PhyAddr < 32);
  ASSERT(ui32Base == 0x400EC000);
  while ((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x00000001) {
  }
  (*((volatile uint32_t *)(ui32Base + 0x00000010))) =
      (((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x0000003C) |
       (ui8RegAddr << 6) | (ui8PhyAddr << 11) | 0x00000001);
  while ((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x00000001) {
  }
  return ((*((volatile uint32_t *)(ui32Base + 0x00000014))) & 0x0000FFFF);
}


x86 assembly (clang, -O0):
<EMACPHYRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x20,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
cmpl   $0x400ec000,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1161 <EMACPHYRead+0x51>
jmp    1146 <EMACPHYRead+0x36>
mov    -0x4(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%ecx
and    $0x3c,%ecx
mov    -0xc(%rbp),%eax
shl    $0x6,%eax
or     %eax,%ecx
mov    -0x8(%rbp),%eax
shl    $0xb,%eax
or     %eax,%ecx
or     $0x1,%ecx
mov    -0x4(%rbp),%eax
add    $0x10,%eax
cltq
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x10,%eax
cltq
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11a6 <EMACPHYRead+0x96>
jmp    118b <EMACPHYRead+0x7b>
mov    -0x4(%rbp),%eax
add    $0x14,%eax
cltq
mov    (%rax),%eax
and    $0xffff,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EMACPHYRead>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
xor    %edi,%edi
cmp    $0x20,%esi
setl   %dil
call   1030 <ASSERT@plt>
xor    %edi,%edi
cmp    $0x400ec000,%r14d
sete   %dil
call   1030 <ASSERT@plt>
movslq %r14d,%rax
xchg   %ax,%ax
mov    0x10(%rax),%ecx
test   $0x1,%cl
jne    1140 <EMACPHYRead+0x30>
mov    0x10(%rax),%ecx
and    $0x3c,%ecx
shl    $0x6,%ebp
or     %ecx,%ebp
shl    $0xb,%ebx
or     %ebp,%ebx
or     $0x1,%ebx
mov    %ebx,0x10(%rax)
xchg   %ax,%ax
mov    0x10(%rax),%ecx
test   $0x1,%cl
jne    1160 <EMACPHYRead+0x50>
mov    0x14(%rax),%eax
movzwl %ax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @EMACPHYRead(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 32
%9 = zext i1 %8 to i32
%10 = call i32 @ASSERT(i32 %9)
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1074708480
%13 = zext i1 %12 to i32
%14 = call i32 @ASSERT(i32 %13)
br label %15
15: ; preds = %23, %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 16
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load volatile i32, i32* %19
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
br label %15
24: ; preds = %15
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 16
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = load volatile i32, i32* %28
%30 = and i32 %29, 60
%31 = load i32, i32* %6
%32 = shl i32 %31, 6
%33 = or i32 %30, %32
%34 = load i32, i32* %5
%35 = shl i32 %34, 11
%36 = or i32 %33, %35
%37 = or i32 %36, 1
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 16
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i32*
store volatile i32 %37, i32* %41
br label %42
42: ; preds = %50, %24
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 16
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
%47 = load volatile i32, i32* %46
%48 = and i32 %47, 1
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
br label %42
51: ; preds = %42
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 20
%54 = sext i32 %53 to i64
%55 = inttoptr i64 %54 to i32*
%56 = load volatile i32, i32* %55
%57 = and i32 %56, 65535
ret i32 %57
}

LLVM IR (-O2):
define i32 @EMACPHYRead(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 32
%5 = zext i1 %4 to i32
%6 = tail call i32 @ASSERT(i32 %5)
%7 = icmp eq i32 %0, 1074708480
%8 = zext i1 %7 to i32
%9 = tail call i32 @ASSERT(i32 %8)
%10 = add nsw i32 %0, 16
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
br label %13
13: ; preds = %13, %3
%14 = load volatile i32, i32* %12
%15 = and i32 %14, 1
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %13
17: ; preds = %13
%18 = load volatile i32, i32* %12
%19 = and i32 %18, 60
%20 = shl i32 %2, 6
%21 = or i32 %19, %20
%22 = shl i32 %1, 11
%23 = or i32 %22, %21
%24 = or i32 %23, 1
store volatile i32 %24, i32* %12
br label %25
25: ; preds = %25, %17
%26 = load volatile i32, i32* %12
%27 = and i32 %26, 1
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %25
29: ; preds = %25
%30 = add nsw i32 %0, 20
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
%33 = load volatile i32, i32* %32
%34 = and i32 %33, 65535
ret i32 %34
}