#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*/ alink_busy_status();
int /*<<< orphan*/ alink_flush_fifo();
int /*<<< orphan*/ alink_init(int);
int /*<<< orphan*/ alink_txbuf_count();
int /*<<< orphan*/ asic_test_work(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ delay(int);
void alink_asic_idle() {
  int i;
  alink_flush_fifo();
  for (i = 0; i < 5; i++) {
    ;
    alink_init(1 << i);
    asic_test_work(i, 0, 1);
    while (!alink_txbuf_count())
      ;
    while (!alink_busy_status())
      ;
    delay(1);
  }
  alink_init(0x1f);
}


x86 assembly (clang, -O0):
<alink_asic_idle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <alink_flush_fifo@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    11fd <alink_asic_idle+0x9d>
mov    -0x4(%rbp),%ecx
mov    $0x1,%edi
shl    %cl,%edi
call   1030 <alink_init@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
mov    $0x0,%al
call   1080 <alink_txbuf_count@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ba <alink_asic_idle+0x5a>
jmp    11bf <alink_asic_idle+0x5f>
jmp    119e <alink_asic_idle+0x3e>
jmp    11c4 <alink_asic_idle+0x64>
mov    $0x0,%al
call   1060 <alink_busy_status@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e0 <alink_asic_idle+0x80>
jmp    11e5 <alink_asic_idle+0x85>
jmp    11c4 <alink_asic_idle+0x64>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <alink_asic_idle+0x16>
mov    $0x1f,%edi
call   1030 <alink_init@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alink_asic_idle>:
push   %rax
xor    %eax,%eax
call   1040 <alink_flush_fifo@plt>
mov    $0x1,%edi
call   1030 <alink_init@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
xor    %eax,%eax
call   1080 <alink_txbuf_count@plt>
test   %eax,%eax
je     1180 <alink_asic_idle+0x20>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <alink_busy_status@plt>
test   %eax,%eax
je     1190 <alink_asic_idle+0x30>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    $0x2,%edi
call   1030 <alink_init@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
xor    %eax,%eax
call   1080 <alink_txbuf_count@plt>
test   %eax,%eax
je     11c0 <alink_asic_idle+0x60>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <alink_busy_status@plt>
test   %eax,%eax
je     11d0 <alink_asic_idle+0x70>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    $0x4,%edi
call   1030 <alink_init@plt>
mov    $0x2,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
xor    %eax,%eax
call   1080 <alink_txbuf_count@plt>
test   %eax,%eax
je     1200 <alink_asic_idle+0xa0>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <alink_busy_status@plt>
test   %eax,%eax
je     1210 <alink_asic_idle+0xb0>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    $0x8,%edi
call   1030 <alink_init@plt>
mov    $0x3,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
xor    %eax,%eax
call   1080 <alink_txbuf_count@plt>
test   %eax,%eax
je     1240 <alink_asic_idle+0xe0>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <alink_busy_status@plt>
test   %eax,%eax
je     1250 <alink_asic_idle+0xf0>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    $0x10,%edi
call   1030 <alink_init@plt>
mov    $0x4,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1070 <asic_test_work@plt>
xor    %eax,%eax
call   1080 <alink_txbuf_count@plt>
test   %eax,%eax
je     1280 <alink_asic_idle+0x120>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <alink_busy_status@plt>
test   %eax,%eax
je     1290 <alink_asic_idle+0x130>
mov    $0x1,%edi
call   1050 <delay@plt>
mov    $0x1f,%edi
pop    %rax
jmp    1030 <alink_init@plt>

LLVM IR (-O0):
define void @alink_asic_idle() {
%1 = alloca i32
%2 = call i32 (...) @alink_flush_fifo()
store i32 0, i32* %1
br label %3
3: ; preds = %25, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 5
br i1 %5, label %6, label %28
6: ; preds = %3
%7 = load i32, i32* %1
%8 = shl i32 1, %7
%9 = call i32 @alink_init(i32 %8)
%10 = load i32, i32* %1
%11 = call i32 @asic_test_work(i32 %10, i32 0, i32 1)
br label %12
12: ; preds = %16, %6
%13 = call i32 (...) @alink_txbuf_count()
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %17
16: ; preds = %12
br label %12
17: ; preds = %12
br label %18
18: ; preds = %22, %17
%19 = call i32 (...) @alink_busy_status()
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %23
22: ; preds = %18
br label %18
23: ; preds = %18
%24 = call i32 @delay(i32 1)
br label %25
25: ; preds = %23
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
br label %3
28: ; preds = %3
%29 = call i32 @alink_init(i32 31)
ret void
}

LLVM IR (-O2):
define void @alink_asic_idle() {
%1 = tail call i32 (...) @alink_flush_fifo()
%2 = tail call i32 @alink_init(i32 1)
%3 = tail call i32 @asic_test_work(i32 0, i32 0, i32 1)
br label %4
4: ; preds = %4, %0
%5 = tail call i32 (...) @alink_txbuf_count()
%6 = icmp eq i32 %5, 0
br i1 %6, label %4, label %7
7: ; preds = %4, %7
%8 = tail call i32 (...) @alink_busy_status()
%9 = icmp eq i32 %8, 0
br i1 %9, label %7, label %10
10: ; preds = %7
%11 = tail call i32 @delay(i32 1)
%12 = tail call i32 @alink_init(i32 2)
%13 = tail call i32 @asic_test_work(i32 1, i32 0, i32 1)
br label %14
14: ; preds = %14, %10
%15 = tail call i32 (...) @alink_txbuf_count()
%16 = icmp eq i32 %15, 0
br i1 %16, label %14, label %17
17: ; preds = %14, %17
%18 = tail call i32 (...) @alink_busy_status()
%19 = icmp eq i32 %18, 0
br i1 %19, label %17, label %20
20: ; preds = %17
%21 = tail call i32 @delay(i32 1)
%22 = tail call i32 @alink_init(i32 4)
%23 = tail call i32 @asic_test_work(i32 2, i32 0, i32 1)
br label %24
24: ; preds = %24, %20
%25 = tail call i32 (...) @alink_txbuf_count()
%26 = icmp eq i32 %25, 0
br i1 %26, label %24, label %27
27: ; preds = %24, %27
%28 = tail call i32 (...) @alink_busy_status()
%29 = icmp eq i32 %28, 0
br i1 %29, label %27, label %30
30: ; preds = %27
%31 = tail call i32 @delay(i32 1)
%32 = tail call i32 @alink_init(i32 8)
%33 = tail call i32 @asic_test_work(i32 3, i32 0, i32 1)
br label %34
34: ; preds = %34, %30
%35 = tail call i32 (...) @alink_txbuf_count()
%36 = icmp eq i32 %35, 0
br i1 %36, label %34, label %37
37: ; preds = %34, %37
%38 = tail call i32 (...) @alink_busy_status()
%39 = icmp eq i32 %38, 0
br i1 %39, label %37, label %40
40: ; preds = %37
%41 = tail call i32 @delay(i32 1)
%42 = tail call i32 @alink_init(i32 16)
%43 = tail call i32 @asic_test_work(i32 4, i32 0, i32 1)
br label %44
44: ; preds = %44, %40
%45 = tail call i32 (...) @alink_txbuf_count()
%46 = icmp eq i32 %45, 0
br i1 %46, label %44, label %47
47: ; preds = %44, %47
%48 = tail call i32 (...) @alink_busy_status()
%49 = icmp eq i32 %48, 0
br i1 %49, label %47, label %50
50: ; preds = %47
%51 = tail call i32 @delay(i32 1)
%52 = tail call i32 @alink_init(i32 31)
ret void
}