#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 */
scalar_t__ INR_MDIO_read_b(int /*<<< orphan*/ *);
int /*<<< orphan*/ INR_PCI_MMI_write(int, int);
int /*<<< orphan*/ usleep(int);
void INR_MDIO_write_b(uint8_t write, uint8_t PHY_addr, uint8_t REG_addr,
                      uint16_t data) {
  uint32_t value = 0, i = 0;
  value = ((1 & write) << 26) | ((PHY_addr & 0x1f) << 21) |
          ((REG_addr & 0x1f) << 16) | (data);
  INR_PCI_MMI_write(value, ((0x00 << 0) | (0x0001 << 8)));
  usleep(50);
  while (INR_MDIO_read_b(NULL)) {
    i++;
    if (i > 10)
      break;
  }
}


x86 assembly (clang, -O0):
<INR_MDIO_write_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
shl    $0x1a,%eax
mov    -0x8(%rbp),%ecx
and    $0x1f,%ecx
shl    $0x15,%ecx
or     %ecx,%eax
mov    -0xc(%rbp),%ecx
and    $0x1f,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x100,%esi
call   1040 <INR_PCI_MMI_write@plt>
mov    $0x32,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <INR_MDIO_read_b@plt>
cmp    $0x0,%rax
je     11be <INR_MDIO_write_b+0x8e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jle    11b9 <INR_MDIO_write_b+0x89>
jmp    11be <INR_MDIO_write_b+0x8e>
jmp    118e <INR_MDIO_write_b+0x5e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INR_MDIO_write_b>:
push   %rbx
and    $0x1,%edi
shl    $0x1a,%edi
and    $0x1f,%esi
shl    $0x15,%esi
or     %esi,%edi
and    $0x1f,%edx
shl    $0x10,%edx
or     %ecx,%edx
or     %edx,%edi
mov    $0x100,%esi
call   1040 <INR_PCI_MMI_write@plt>
mov    $0x32,%edi
call   1050 <usleep@plt>
xor    %ebx,%ebx
nop
xor    %edi,%edi
call   1030 <INR_MDIO_read_b@plt>
test   %rax,%rax
je     1176 <INR_MDIO_write_b+0x46>
lea    0x1(%rbx),%eax
cmp    $0xa,%ebx
mov    %eax,%ebx
jb     1160 <INR_MDIO_write_b+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @INR_MDIO_write_b(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %5
%12 = and i32 1, %11
%13 = shl i32 %12, 26
%14 = load i32, i32* %6
%15 = and i32 %14, 31
%16 = shl i32 %15, 21
%17 = or i32 %13, %16
%18 = load i32, i32* %7
%19 = and i32 %18, 31
%20 = shl i32 %19, 16
%21 = or i32 %17, %20
%22 = load i32, i32* %8
%23 = or i32 %21, %22
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = call i32 @INR_PCI_MMI_write(i32 %24, i32 256)
%26 = call i32 @usleep(i32 50)
br label %27
27: ; preds = %36, %4
%28 = call i64 @INR_MDIO_read_b(i32* null)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = icmp sgt i32 %33, 10
br i1 %34, label %35, label %36
35: ; preds = %30
br label %37
36: ; preds = %30
br label %27
37: ; preds = %35, %27
ret void
}

LLVM IR (-O2):
define void @INR_MDIO_write_b(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %0, 26
%6 = and i32 %5, 67108864
%7 = shl i32 %1, 21
%8 = and i32 %7, 65011712
%9 = or i32 %8, %6
%10 = shl i32 %2, 16
%11 = and i32 %10, 2031616
%12 = or i32 %9, %3
%13 = or i32 %12, %11
%14 = tail call i32 @INR_PCI_MMI_write(i32 %13, i32 256)
%15 = tail call i32 @usleep(i32 50)
br label %16
16: ; preds = %16, %4
%17 = phi i32 [ 0, %4 ], [ %20, %16 ]
%18 = tail call i64 @INR_MDIO_read_b(i32* null)
%19 = icmp eq i64 %18, 0
%20 = add nuw nsw i32 %17, 1
%21 = icmp ugt i32 %17, 9
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %16
23: ; preds = %16
ret void
}