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

/* Variables and functions */
int /*<<< orphan*/ ASSERT(int);
int EMACPHYRead(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ EMACPHYWrite(int /*<<< orphan*/, int, int, int);
uint16_t EMACPHYMMDRead(uint32_t ui32Base, uint8_t ui8PhyAddr,
                        uint16_t ui16RegAddr) {
  ASSERT(ui8PhyAddr < 32);
  EMACPHYWrite(ui32Base, ui8PhyAddr, 0x0000000D,
               ((ui16RegAddr & 0xF000) >> 12));
  EMACPHYWrite(ui32Base, ui8PhyAddr, 0x0000000E, ((ui16RegAddr & 0x0FFF)));
  EMACPHYWrite(ui32Base, ui8PhyAddr, 0x0000000D,
               (0x4000 | ((ui16RegAddr & 0xF000) >> 12)));
  return (EMACPHYRead(ui32Base, ui8PhyAddr, 0x0000000E));
}


x86 assembly (clang, -O0):
<EMACPHYMMDRead>:
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   1040 <ASSERT@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
and    $0xf000,%ecx
sar    $0xc,%ecx
mov    $0xd,%edx
call   1050 <EMACPHYWrite@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
and    $0xfff,%ecx
mov    $0xe,%edx
call   1050 <EMACPHYWrite@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
and    $0xf000,%ecx
sar    $0xc,%ecx
or     $0x4000,%ecx
mov    $0xd,%edx
call   1050 <EMACPHYWrite@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xe,%edx
call   1030 <EMACPHYRead@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EMACPHYMMDRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%r14d
xor    %edi,%edi
cmp    $0x20,%esi
setl   %dil
call   1040 <ASSERT@plt>
mov    %ebx,%ebp
shr    $0xc,%ebp
and    $0xf,%ebp
mov    %r14d,%edi
mov    %r15d,%esi
mov    $0xd,%edx
mov    %ebp,%ecx
call   1050 <EMACPHYWrite@plt>
and    $0xfff,%ebx
mov    %r14d,%edi
mov    %r15d,%esi
mov    $0xe,%edx
mov    %ebx,%ecx
call   1050 <EMACPHYWrite@plt>
or     $0x4000,%ebp
mov    %r14d,%edi
mov    %r15d,%esi
mov    $0xd,%edx
mov    %ebp,%ecx
call   1050 <EMACPHYWrite@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    $0xe,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <EMACPHYRead@plt>

LLVM IR (-O0):
define i32 @EMACPHYMMDRead(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 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = and i32 %13, 61440
%15 = ashr i32 %14, 12
%16 = call i32 @EMACPHYWrite(i32 %11, i32 %12, i32 13, i32 %15)
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = and i32 %19, 4095
%21 = call i32 @EMACPHYWrite(i32 %17, i32 %18, i32 14, i32 %20)
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = and i32 %24, 61440
%26 = ashr i32 %25, 12
%27 = or i32 16384, %26
%28 = call i32 @EMACPHYWrite(i32 %22, i32 %23, i32 13, i32 %27)
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @EMACPHYRead(i32 %29, i32 %30, i32 14)
ret i32 %31
}

LLVM IR (-O2):
define i32 @EMACPHYMMDRead(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 = lshr i32 %2, 12
%8 = and i32 %7, 15
%9 = tail call i32 @EMACPHYWrite(i32 %0, i32 %1, i32 13, i32 %8)
%10 = and i32 %2, 4095
%11 = tail call i32 @EMACPHYWrite(i32 %0, i32 %1, i32 14, i32 %10)
%12 = or i32 %8, 16384
%13 = tail call i32 @EMACPHYWrite(i32 %0, i32 %1, i32 13, i32 %12)
%14 = tail call i32 @EMACPHYRead(i32 %0, i32 %1, i32 14)
ret i32 %14
}