#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 */
scalar_t__ tube_is_rst_active();
int /*<<< orphan*/ tube_reset();
void tube_wait_for_rst_release() {
  volatile int i;
  do {
    while (tube_is_rst_active())
      ;
    for (i = 0; i < 10000 && !tube_is_rst_active(); i++)
      ;
  } while (i < 10000);
  tube_reset();
}


x86 assembly (clang, -O0):
<tube_wait_for_rst_release>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
jmp    112d <tube_wait_for_rst_release+0xd>
mov    $0x0,%al
call   1040 <tube_is_rst_active@plt>
cmp    $0x0,%rax
je     1143 <tube_wait_for_rst_release+0x23>
jmp    112d <tube_wait_for_rst_release+0xd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    $0x2710,%ecx
mov    %al,-0x5(%rbp)
jge    1171 <tube_wait_for_rst_release+0x51>
mov    $0x0,%al
call   1040 <tube_is_rst_active@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    1181 <tube_wait_for_rst_release+0x61>
jmp    1194 <tube_wait_for_rst_release+0x74>
jmp    1186 <tube_wait_for_rst_release+0x66>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114a <tube_wait_for_rst_release+0x2a>
jmp    1199 <tube_wait_for_rst_release+0x79>
mov    -0x4(%rbp),%eax
cmp    $0x2710,%eax
jl     1128 <tube_wait_for_rst_release+0x8>
mov    $0x0,%al
call   1030 <tube_reset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tube_wait_for_rst_release>:
push   %rax
jmp    113b <tube_wait_for_rst_release+0x1b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%eax
cmp    $0x2710,%eax
jge    117e <tube_wait_for_rst_release+0x5e>
xor    %eax,%eax
call   1040 <tube_is_rst_active@plt>
test   %rax,%rax
jne    113b <tube_wait_for_rst_release+0x1b>
movl   $0x0,0x4(%rsp)
mov    0x4(%rsp),%eax
cmp    $0x270f,%eax
jg     1130 <tube_wait_for_rst_release+0x10>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <tube_is_rst_active@plt>
test   %rax,%rax
jne    1130 <tube_wait_for_rst_release+0x10>
addl   $0x1,0x4(%rsp)
mov    0x4(%rsp),%eax
cmp    $0x2710,%eax
jl     1160 <tube_wait_for_rst_release+0x40>
jmp    1130 <tube_wait_for_rst_release+0x10>
xor    %eax,%eax
pop    %rcx
jmp    1030 <tube_reset@plt>

LLVM IR (-O0):
define void @tube_wait_for_rst_release() {
%1 = alloca i32
br label %2
2: ; preds = %22, %0
br label %3
3: ; preds = %6, %2
%4 = call i64 (...) @tube_is_rst_active()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %3
br label %3
7: ; preds = %3
store volatile i32 0, i32* %1
br label %8
8: ; preds = %18, %7
%9 = load volatile i32, i32* %1
%10 = icmp slt i32 %9, 10000
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i64 (...) @tube_is_rst_active()
%13 = icmp ne i64 %12, 0
%14 = xor i1 %13, true
br label %15
15: ; preds = %11, %8
%16 = phi i1 [ false, %8 ], [ %14, %11 ]
br i1 %16, label %17, label %21
17: ; preds = %15
br label %18
18: ; preds = %17
%19 = load volatile i32, i32* %1
%20 = add nsw i32 %19, 1
store volatile i32 %20, i32* %1
br label %8
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load volatile i32, i32* %1
%24 = icmp slt i32 %23, 10000
br i1 %24, label %2, label %25
25: ; preds = %22
%26 = call i32 (...) @tube_reset()
ret void
}

LLVM IR (-O2):
define void @tube_wait_for_rst_release() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %6, %0
%4 = tail call i64 (...) @tube_is_rst_active()
%5 = icmp eq i64 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %3, %18
br label %3
7: ; preds = %3
store volatile i32 0, i32* %1
%8 = load volatile i32, i32* %1
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %18
10: ; preds = %7, %13
%11 = tail call i64 (...) @tube_is_rst_active()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load volatile i32, i32* %1
%15 = add nsw i32 %14, 1
store volatile i32 %15, i32* %1
%16 = load volatile i32, i32* %1
%17 = icmp slt i32 %16, 10000
br i1 %17, label %10, label %18
18: ; preds = %13, %10, %7
%19 = load volatile i32, i32* %1
%20 = icmp slt i32 %19, 10000
br i1 %20, label %6, label %21
21: ; preds = %18
%22 = tail call i32 (...) @tube_reset()
ret void
}