#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*/ DEBUG_ASSERT(int);
unsigned long EthernetPHYRead(unsigned long ulBase, unsigned char ucRegAddr) {
  DEBUG_ASSERT(ulBase == 0x40048000);
  while ((*((volatile unsigned long *)(ulBase + 0x00000020))) & 0x00000001) {
  }
  (*((volatile unsigned long *)(ulBase + 0x00000020))) =
      (((ucRegAddr << 3) & 0x000000F8) | 0x00000001);
  while ((*((volatile unsigned long *)(ulBase + 0x00000020))) & 0x00000001) {
  }
  return ((*((volatile unsigned long *)(ulBase + 0x00000030))) & 0x0000FFFF);
}


x86 assembly (clang, -O0):
<EthernetPHYRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
cmpq   $0x40048000,-0x8(%rbp)
40
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1152 <EthernetPHYRead+0x42>
jmp    1137 <EthernetPHYRead+0x27>
movzbl -0x9(%rbp),%eax
shl    $0x3,%eax
and    $0xf8,%eax
or     $0x1,%eax
movslq %eax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1187 <EthernetPHYRead+0x77>
jmp    116c <EthernetPHYRead+0x5c>
mov    -0x8(%rbp),%rax
mov    0x30(%rax),%rax
and    $0xffff,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EthernetPHYRead>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x40048000,%rbx
sete   %dil
call   1030 <DEBUG_ASSERT@plt>
nopw   0x0(%rax,%rax,1)
mov    0x20(%rbx),%rax
test   $0x1,%al
jne    1130 <EthernetPHYRead+0x20>
movzbl %bpl,%eax
lea    0x1(,%rax,8),%eax
movzbl %al,%eax
mov    %rax,0x20(%rbx)
nopw   0x0(%rax,%rax,1)
mov    0x20(%rbx),%rax
test   $0x1,%al
jne    1150 <EthernetPHYRead+0x40>
mov    0x30(%rbx),%rax
movzwl %ax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @EthernetPHYRead(i64 %0, i8 zeroext %1) {
%3 = alloca i64
%4 = alloca i8
store i64 %0, i64* %3
store i8 %1, i8* %4
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 1074036736
%7 = zext i1 %6 to i32
%8 = call i32 @DEBUG_ASSERT(i32 %7)
br label %9
9: ; preds = %16, %2
%10 = load i64, i64* %3
%11 = add i64 %10, 32
%12 = inttoptr i64 %11 to i64*
%13 = load volatile i64, i64* %12
%14 = and i64 %13, 1
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %9
17: ; preds = %9
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = shl i32 %19, 3
%21 = and i32 %20, 248
%22 = or i32 %21, 1
%23 = sext i32 %22 to i64
%24 = load i64, i64* %3
%25 = add i64 %24, 32
%26 = inttoptr i64 %25 to i64*
store volatile i64 %23, i64* %26
br label %27
27: ; preds = %34, %17
%28 = load i64, i64* %3
%29 = add i64 %28, 32
%30 = inttoptr i64 %29 to i64*
%31 = load volatile i64, i64* %30
%32 = and i64 %31, 1
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %27
br label %27
35: ; preds = %27
%36 = load i64, i64* %3
%37 = add i64 %36, 48
%38 = inttoptr i64 %37 to i64*
%39 = load volatile i64, i64* %38
%40 = and i64 %39, 65535
ret i64 %40
}

LLVM IR (-O2):
define i64 @EthernetPHYRead(i64 %0, i8 zeroext %1) {
%3 = icmp eq i64 %0, 1074036736
%4 = zext i1 %3 to i32
%5 = tail call i32 @DEBUG_ASSERT(i32 %4)
%6 = add i64 %0, 32
%7 = inttoptr i64 %6 to i64*
br label %8
8: ; preds = %8, %2
%9 = load volatile i64, i64* %7
%10 = and i64 %9, 1
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %8
12: ; preds = %8
%13 = zext i8 %1 to i64
%14 = shl nuw nsw i64 %13, 3
%15 = and i64 %14, 248
%16 = or i64 %15, 1
store volatile i64 %16, i64* %7
br label %17
17: ; preds = %17, %12
%18 = load volatile i64, i64* %7
%19 = and i64 %18, 1
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %17
21: ; preds = %17
%22 = add i64 %0, 48
%23 = inttoptr i64 %22 to i64*
%24 = load volatile i64, i64* %23
%25 = and i64 %24, 65535
ret i64 %25
}