#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 */
unsigned int emac_mdio_read(unsigned int, int);
int /*<<< orphan*/ emac_mdio_write(unsigned int, int, unsigned int);
void emac_mdio_phy_reset(unsigned int phy_addr) {
  unsigned int control;
  emac_mdio_write(phy_addr, 0, (1 << 15));
  do {
    control = emac_mdio_read(phy_addr, 0);
  } while (control & (1 << 15));
  control = emac_mdio_read(phy_addr, 26);
  emac_mdio_write(phy_addr, 26, (control | 0x800));
  control = emac_mdio_read(phy_addr, 26);
}


x86 assembly (clang, -O0):
<emac_mdio_phy_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x8000,%edx
call   1040 <emac_mdio_write@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <emac_mdio_read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
jne    113a <emac_mdio_phy_reset+0x1a>
mov    -0x4(%rbp),%edi
mov    $0x1a,%esi
call   1030 <emac_mdio_read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
or     $0x800,%edx
mov    $0x1a,%esi
call   1040 <emac_mdio_write@plt>
mov    -0x4(%rbp),%edi
mov    $0x1a,%esi
call   1030 <emac_mdio_read@plt>
mov    %eax,-0x8(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emac_mdio_phy_reset>:
push   %rbx
mov    %edi,%ebx
xor    %esi,%esi
mov    $0x8000,%edx
call   1040 <emac_mdio_write@plt>
nop
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <emac_mdio_read@plt>
test   $0x8000,%eax
jne    1130 <emac_mdio_phy_reset+0x10>
mov    %ebx,%edi
mov    $0x1a,%esi
call   1030 <emac_mdio_read@plt>
or     $0x800,%eax
mov    %ebx,%edi
mov    $0x1a,%esi
mov    %eax,%edx
call   1040 <emac_mdio_write@plt>
mov    %ebx,%edi
mov    $0x1a,%esi
pop    %rbx
jmp    1030 <emac_mdio_read@plt>

LLVM IR (-O0):
define void @emac_mdio_phy_reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @emac_mdio_write(i32 %4, i32 0, i32 32768)
br label %6
6: ; preds = %9, %1
%7 = load i32, i32* %2
%8 = call i32 @emac_mdio_read(i32 %7, i32 0)
store i32 %8, i32* %3
br label %9
9: ; preds = %6
%10 = load i32, i32* %3
%11 = and i32 %10, 32768
%12 = icmp ne i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 @emac_mdio_read(i32 %14, i32 26)
store i32 %15, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = or i32 %17, 2048
%19 = call i32 @emac_mdio_write(i32 %16, i32 26, i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @emac_mdio_read(i32 %20, i32 26)
store i32 %21, i32* %3
ret void
}

LLVM IR (-O2):
define void @emac_mdio_phy_reset(i32 %0) {
%2 = tail call i32 @emac_mdio_write(i32 %0, i32 0, i32 32768)
br label %3
3: ; preds = %3, %1
%4 = tail call i32 @emac_mdio_read(i32 %0, i32 0)
%5 = and i32 %4, 32768
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %3
7: ; preds = %3
%8 = tail call i32 @emac_mdio_read(i32 %0, i32 26)
%9 = or i32 %8, 2048
%10 = tail call i32 @emac_mdio_write(i32 %0, i32 26, i32 %9)
%11 = tail call i32 @emac_mdio_read(i32 %0, i32 26)
ret void
}