#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*/ barrier();
int readb(void *);
int /*<<< orphan*/ udelay(int);
int /*<<< orphan*/ writeb(int, void *);
void rtl8169_chip_reset(void *ioaddr) {
  int i;
  writeb(0x10, ioaddr + 0x37);
  for (i = 1000; i > 0; i--) {
    barrier();
    if ((readb(ioaddr + 0x37) & 0x10) == 0)
      break;
    udelay(10);
  }
  return;
}


x86 assembly (clang, -O0):
<rtl8169_chip_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
add    $0x37,%rsi
mov    $0x10,%edi
call   1060 <writeb@plt>
movl   $0x3e8,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11ac <rtl8169_chip_reset+0x6c>
mov    $0x0,%al
call   1030 <barrier@plt>
mov    -0x8(%rbp),%rdi
add    $0x37,%rdi
call   1040 <readb@plt>
and    $0x10,%eax
cmp    $0x0,%eax
jne    1194 <rtl8169_chip_reset+0x54>
jmp    11ac <rtl8169_chip_reset+0x6c>
mov    $0xa,%edi
call   1050 <udelay@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <rtl8169_chip_reset+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtl8169_chip_reset>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x37,%rbx
mov    $0x10,%edi
mov    %rbx,%rsi
call   1060 <writeb@plt>
mov    $0x3e9,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <barrier@plt>
mov    %rbx,%rdi
call   1040 <readb@plt>
test   $0x10,%al
je     1185 <rtl8169_chip_reset+0x45>
mov    $0xa,%edi
call   1050 <udelay@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1160 <rtl8169_chip_reset+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @rtl8169_chip_reset(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr i8, i8* %4, i64 55
%6 = call i32 @writeb(i32 16, i8* %5)
store i32 1000, i32* %3
br label %7
7: ; preds = %20, %1
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = call i32 (...) @barrier()
%12 = load i8*, i8** %2
%13 = getelementptr i8, i8* %12, i64 55
%14 = call i32 @readb(i8* %13)
%15 = and i32 %14, 16
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
br label %23
18: ; preds = %10
%19 = call i32 @udelay(i32 10)
br label %20
20: ; preds = %18
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %7
23: ; preds = %17, %7
ret void
}

LLVM IR (-O2):
define void @rtl8169_chip_reset(i8* %0) {
%2 = getelementptr i8, i8* %0, i64 55
%3 = tail call i32 @writeb(i32 16, i8* %2)
br label %4
4: ; preds = %1, %10
%5 = phi i32 [ 1000, %1 ], [ %12, %10 ]
%6 = tail call i32 (...) @barrier()
%7 = tail call i32 @readb(i8* %2)
%8 = and i32 %7, 16
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = tail call i32 @udelay(i32 10)
%12 = add nsw i32 %5, -1
%13 = icmp ugt i32 %5, 1
br i1 %13, label %4, label %14
14: ; preds = %4, %10
ret void
}