#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 /*<<< orphan*/ ASSERT(int);
void EMACPHYWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr,
                  uint16_t ui16Data) {
  ASSERT(ui32Base == 0x400EC000);
  ASSERT(ui8PhyAddr < 32);
  while ((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x00000001) {
  }
  (*((volatile uint32_t *)(ui32Base + 0x00000014))) = ui16Data;
  (*((volatile uint32_t *)(ui32Base + 0x00000010))) =
      (((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x0000003C) |
       (ui8RegAddr << 6) | (ui8PhyAddr << 11) | 0x00000002 | 0x00000001);
  while ((*((volatile uint32_t *)(ui32Base + 0x00000010))) & 0x00000001) {
  }
}


x86 assembly (clang, -O0):
<EMACPHYWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x400ec000,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
cmpl   $0x20,-0x8(%rbp)
setl   %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     1164 <EMACPHYWrite+0x54>
jmp    1149 <EMACPHYWrite+0x39>
mov    -0x10(%rbp),%ecx
mov    -0x4(%rbp),%eax
add    $0x14,%eax
cltq
mov    %ecx,(%rax)
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     $0x2,%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     11b9 <EMACPHYWrite+0xa9>
jmp    119e <EMACPHYWrite+0x8e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EMACPHYWrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r15d
xor    %edi,%edi
cmp    $0x400ec000,%r15d
sete   %dil
call   1030 <ASSERT@plt>
xor    %edi,%edi
cmp    $0x20,%ebx
setl   %dil
call   1030 <ASSERT@plt>
movslq %r15d,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rax),%ecx
test   $0x1,%cl
jne    1150 <EMACPHYWrite+0x40>
mov    %r14d,0x14(%rax)
mov    0x10(%rax),%ecx
and    $0x3c,%ecx
shl    $0x6,%ebp
or     %ecx,%ebp
shl    $0xb,%ebx
or     %ebp,%ebx
or     $0x3,%ebx
mov    %ebx,0x10(%rax)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rax),%ecx
test   $0x1,%cl
jne    1180 <EMACPHYWrite+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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