#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 ce_close_scheduler();
int ce_coroutine_cnt();
int /*<<< orphan*/ ce_coroutine_resume(int);
int ce_get_coroutine_status(int);
scalar_t__ ce_poller_poll(int);
scalar_t__ ce_poller_react();
int ce_run() {
  while (ce_coroutine_cnt() > 0) {
    int crtn_id;
    if (ce_poller_poll(1) != 0) {
      return -1;
    }
    if (ce_poller_react() != 0) {
      return -1;
    }
    for (crtn_id = 0; crtn_id < ce_coroutine_cnt(); crtn_id++) {
      int status = ce_get_coroutine_status(crtn_id);
      if (status == 1 || status == 3) {
        ce_coroutine_resume(crtn_id);
      }
    }
  }
  return ce_close_scheduler();
}


x86 assembly (clang, -O0):
<ce_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <ce_coroutine_cnt@plt>
cmp    $0x0,%eax
jle    1215 <ce_run+0xb5>
mov    $0x1,%edi
call   1060 <ce_poller_poll@plt>
cmp    $0x0,%rax
je     1198 <ce_run+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <ce_run+0xbf>
mov    $0x0,%al
call   1050 <ce_poller_react@plt>
cmp    $0x0,%rax
je     11b5 <ce_run+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <ce_run+0xbf>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <ce_coroutine_cnt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    1210 <ce_run+0xb0>
mov    -0x8(%rbp),%edi
call   1070 <ce_get_coroutine_status@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11f5 <ce_run+0x95>
cmpl   $0x3,-0xc(%rbp)
jne    11fd <ce_run+0x9d>
mov    -0x8(%rbp),%edi
call   1080 <ce_coroutine_resume@plt>
jmp    1202 <ce_run+0xa2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bc <ce_run+0x5c>
jmp    1168 <ce_run+0x8>
mov    $0x0,%al
call   1040 <ce_close_scheduler@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ce_run>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ce_coroutine_cnt@plt>
test   %eax,%eax
jle    11d6 <ce_run+0x76>
mov    $0x1,%edi
call   1060 <ce_poller_poll@plt>
test   %rax,%rax
jne    11de <ce_run+0x7e>
xor    %eax,%eax
call   1050 <ce_poller_react@plt>
test   %rax,%rax
jne    11de <ce_run+0x7e>
xor    %eax,%eax
call   1030 <ce_coroutine_cnt@plt>
test   %eax,%eax
jle    1170 <ce_run+0x10>
xor    %ebx,%ebx
jmp    11be <ce_run+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
xor    %eax,%eax
call   1030 <ce_coroutine_cnt@plt>
cmp    %eax,%ebx
jge    1170 <ce_run+0x10>
mov    %ebx,%edi
call   1070 <ce_get_coroutine_status@plt>
and    $0xfffffffd,%eax
cmp    $0x1,%eax
jne    11b0 <ce_run+0x50>
mov    %ebx,%edi
call   1080 <ce_coroutine_resume@plt>
jmp    11b0 <ce_run+0x50>
xor    %eax,%eax
pop    %rbx
jmp    1040 <ce_close_scheduler@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ce_run() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
br label %4
4: ; preds = %35, %0
%5 = call i32 (...) @ce_coroutine_cnt()
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %36
7: ; preds = %4
%8 = call i64 @ce_poller_poll(i32 1)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 -1, i32* %1
br label %38
11: ; preds = %7
%12 = call i64 (...) @ce_poller_react()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %1
br label %38
15: ; preds = %11
store i32 0, i32* %2
br label %16
16: ; preds = %32, %15
%17 = load i32, i32* %2
%18 = call i32 (...) @ce_coroutine_cnt()
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i32, i32* %2
%22 = call i32 @ce_get_coroutine_status(i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %31
28: ; preds = %25, %20
%29 = load i32, i32* %2
%30 = call i32 @ce_coroutine_resume(i32 %29)
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %16
35: ; preds = %16
br label %4
36: ; preds = %4
%37 = call i32 (...) @ce_close_scheduler()
store i32 %37, i32* %1
br label %38
38: ; preds = %36, %14, %10
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
define i32 @ce_run() {
%1 = tail call i32 (...) @ce_coroutine_cnt()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %6, label %26
3: ; preds = %22, %12
%4 = tail call i32 (...) @ce_coroutine_cnt()
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %26
6: ; preds = %0, %3
%7 = tail call i64 @ce_poller_poll(i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = tail call i64 (...) @ce_poller_react()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = tail call i32 (...) @ce_coroutine_cnt()
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %3
15: ; preds = %12, %22
%16 = phi i32 [ %23, %22 ], [ 0, %12 ]
%17 = tail call i32 @ce_get_coroutine_status(i32 %16)
%18 = and i32 %17, -3
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @ce_coroutine_resume(i32 %16)
br label %22
22: ; preds = %15, %20
%23 = add nuw nsw i32 %16, 1
%24 = tail call i32 (...) @ce_coroutine_cnt()
%25 = icmp slt i32 %23, %24
br i1 %25, label %15, label %3
26: ; preds = %3, %0
%27 = tail call i32 (...) @ce_close_scheduler()
br label %28
28: ; preds = %9, %6, %26
%29 = phi i32 [ %27, %26 ], [ -1, %6 ], [ -1, %9 ]
ret i32 %29
}