#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);
void EthernetPHYWrite(unsigned long ulBase, unsigned char ucRegAddr,
                      unsigned long ulData) {
  DEBUG_ASSERT(ulBase == 0x40048000);
  while ((*((volatile unsigned long *)(ulBase + 0x00000020))) & 0x00000001) {
  }
  (*((volatile unsigned long *)(ulBase + 0x0000002C))) = ulData & 0x0000FFFF;
  (*((volatile unsigned long *)(ulBase + 0x00000020))) =
      (((ucRegAddr << 3) & 0x000000F8) | 0x00000002 | 0x00000001);
  while ((*((volatile unsigned long *)(ulBase + 0x00000020))) & 0x00000001) {
  }
}


x86 assembly (clang, -O0):
<EthernetPHYWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%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     1156 <EthernetPHYWrite+0x46>
jmp    113b <EthernetPHYWrite+0x2b>
mov    -0x18(%rbp),%rcx
and    $0xffff,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x2c(%rax)
movzbl -0x9(%rbp),%eax
shl    $0x3,%eax
and    $0xf8,%eax
or     $0x2,%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     11a1 <EthernetPHYWrite+0x91>
jmp    1186 <EthernetPHYWrite+0x76>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EthernetPHYWrite>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x40048000,%rbx
sete   %dil
call   1030 <DEBUG_ASSERT@plt>
nop
mov    0x20(%rbx),%rax
test   $0x1,%al
jne    1130 <EthernetPHYWrite+0x20>
movzwl %bp,%eax
mov    %rax,0x2c(%rbx)
movzbl %r14b,%eax
lea    0x3(,%rax,8),%eax
movzbl %al,%eax
mov    %rax,0x20(%rbx)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x20(%rbx),%rax
test   $0x1,%al
jne    1160 <EthernetPHYWrite+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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