// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/ev.c
// Function: janet_loop1
JanetFiber *janet_loop1(void) {
    /* Schedule expired timers */
    JanetTimeout to;
    JanetTimestamp now = ts_now();
    while (peek_timeout(&to) && to.when <= now) {
        pop_timeout(0);
        if (to.curr_fiber != NULL) {
            if (janet_fiber_can_resume(to.curr_fiber)) {
                janet_cancel(to.fiber, janet_cstringv("deadline expired"));
            }
        } else {
            /* This is a timeout (for a function call, not a whole fiber) */
            if (to.fiber->sched_id == to.sched_id) {
                if (to.is_error) {
                    janet_cancel(to.fiber, janet_cstringv("timeout"));
                } else {
                    janet_schedule(to.fiber, janet_wrap_nil());
                }
            }
        }
        handle_timeout_worker(to, 0);
    }

    /* Run scheduled fibers unless interrupts need to be handled. */
    while (janet_vm.spawn.head != janet_vm.spawn.tail) {
        /* Don't run until all interrupts have been marked as handled by calling janet_interpreter_interrupt_handled */
        if (janet_atomic_load_relaxed(&janet_vm.auto_suspend)) break;
        JanetTask task = {NULL, janet_wrap_nil(), JANET_SIGNAL_OK, 0};
        janet_q_pop(&janet_vm.spawn, &task, sizeof(task));
        if (task.fiber->gc.flags & JANET_FIBER_EV_FLAG_SUSPENDED) janet_ev_dec_refcount();
        task.fiber->gc.flags &= ~(JANET_FIBER_EV_FLAG_CANCELED | JANET_FIBER_EV_FLAG_SUSPENDED);
        if (task.expected_sched_id != task.fiber->sched_id) continue;
        Janet res;
        JanetSignal sig = janet_continue_signal(task.fiber, task.value, &res, task.sig);
        if (!janet_fiber_can_resume(task.fiber)) {
            janet_table_remove(&janet_vm.active_tasks, janet_wrap_fiber(task.fiber));
        }
        void *sv = task.fiber->supervisor_channel;
        int is_suspended = sig == JANET_SIGNAL_EVENT || sig == JANET_SIGNAL_YIELD || sig == JANET_SIGNAL_INTERRUPT;
        if (is_suspended) {
            task.fiber->gc.flags |= JANET_FIBER_EV_FLAG_SUSPENDED;
            janet_ev_inc_refcount();
        }
        if (NULL == sv) {
            if (!is_suspended) {
                janet_stacktrace_ext(task.fiber, res, "");
            }
        } else if (sig == JANET_SIGNAL_OK || (task.fiber->flags & (1 << sig))) {
            JanetChannel *chan = janet_channel_unwrap(sv);
            janet_channel_push(chan, make_supervisor_event(janet_signal_names[sig],
                               task.fiber, chan->is_threaded), 2);
        } else if (!is_suspended) {
            janet_stacktrace_ext(task.fiber, res, "");
        }
        if (sig == JANET_SIGNAL_INTERRUPT) {
            return task.fiber;
        }
    }

    /* Poll for events */
    if (janet_vm.tq_count || janet_atomic_load(&janet_vm.listener_count)) {
        JanetTimeout to;
        memset(&to, 0, sizeof(to));
        int has_timeout;
        /* Drop timeouts that are no longer needed */
        while ((has_timeout = peek_timeout(&to))) {
            if (to.curr_fiber != NULL) {
                if (!janet_fiber_can_resume(to.curr_fiber)) {
                    pop_timeout(0);
                    janet_table_remove(&janet_vm.active_tasks, janet_wrap_fiber(to.curr_fiber));
                    handle_timeout_worker(to, 1);
                    continue;
                }
            } else if (to.fiber->sched_id != to.sched_id) {
                pop_timeout(0);
                handle_timeout_worker(to, 1);
                continue;
            }
            break;
        }
        /* Run polling implementation only if pending timeouts or pending events */
        if (janet_vm.tq_count || janet_atomic_load(&janet_vm.listener_count)) {
            janet_loop1_impl(has_timeout, to.when);
        }
    }

    /* No fiber was interrupted */
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
callq 0x2bc70
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2b710
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xf9(%rbp)
je 0x2e07d
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setle %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x2e08c
jmp 0x2e197
xorl %eax, %eax
movl %eax, %edi
callq 0x2b850
cmpq $0x0, -0x28(%rbp)
je 0x2e0ec
movq -0x28(%rbp), %rdi
callq 0x378b0
cmpl $0x0, %eax
je 0x2e0e7
movq -0x30(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq 0x5988d(%rip), %rdi     # 0x87949
callq 0x64a70
movq %rax, %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x7b550
movq -0x108(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
callq 0x2b130
jmp 0x2e16f
movq -0x30(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x2e16d
cmpl $0x0, -0x1c(%rbp)
je 0x2e13d
movq -0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq 0x5984a(%rip), %rdi     # 0x8795a
callq 0x64a70
movq %rax, %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x7b550
movq -0x110(%rbp), %rdi
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
callq 0x2b130
jmp 0x2e16b
movq -0x30(%rbp), %rax
movq %rax, -0x118(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x118(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
callq 0x2b160
jmp 0x2e16d
jmp 0x2e16f
xorl %eax, %eax
movups -0x38(%rbp), %xmm0
movups -0x28(%rbp), %xmm1
movups -0x18(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
xorl %edi, %edi
callq 0x2b780
jmp 0x2e054
jmp 0x2e199
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl 0x234(%rax), %eax
movl %eax, -0x11c(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rcx
movl -0x11c(%rbp), %eax
cmpl 0x238(%rcx), %eax
je 0x2e44b
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rdi
addq $0x1c, %rdi
callq 0x1d6e0
cmpl $0x0, %eax
je 0x2e200
jmp 0x2e44b
movq $0x0, -0x70(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, -0x68(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rdi
addq $0x230, %rdi            # imm = 0x230
leaq -0x70(%rbp), %rsi
movl $0x18, %edx
callq 0x2d630
movq -0x70(%rbp), %rax
movl (%rax), %eax
andl $0x20000, %eax          # imm = 0x20000
cmpl $0x0, %eax
je 0x2e266
callq 0x2a820
movq -0x70(%rbp), %rax
movl (%rax), %ecx
andl $0xfffcffff, %ecx       # imm = 0xFFFCFFFF
movl %ecx, (%rax)
movl -0x5c(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpl 0x48(%rcx), %eax
je 0x2e285
jmp 0x2e199
movq -0x70(%rbp), %rdi
movl -0x60(%rbp), %ecx
movq -0x68(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x7a350
movl %eax, -0x7c(%rbp)
movq -0x70(%rbp), %rdi
callq 0x378b0
cmpl $0x0, %eax
jne 0x2e2fb
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
addq $0x298, %rax            # imm = 0x298
movq %rax, -0x128(%rbp)
movq -0x70(%rbp), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x7b610
movq -0x128(%rbp), %rdi
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rsi
callq 0x696c0
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x98(%rbp)
movb $0x1, %al
cmpl $0xd, -0x7c(%rbp)
movb %al, -0x129(%rbp)
je 0x2e333
movb $0x1, %al
cmpl $0x3, -0x7c(%rbp)
movb %al, -0x129(%rbp)
je 0x2e333
cmpl $0xc, -0x7c(%rbp)
sete %al
movb %al, -0x129(%rbp)
movb -0x129(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x2e360
movq -0x70(%rbp), %rax
movl (%rax), %ecx
orl $0x20000, %ecx          # imm = 0x20000
movl %ecx, (%rax)
callq 0x2a950
xorl %eax, %eax
cmpq -0x98(%rbp), %rax
jne 0x2e38d
cmpl $0x0, -0x9c(%rbp)
jne 0x2e388
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
leaq 0x6b102(%rip), %rdx     # 0x99485
callq 0x27d00
jmp 0x2e433
cmpl $0x0, -0x7c(%rbp)
je 0x2e3ad
movq -0x70(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x7c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x2e412
movq -0x98(%rbp), %rdi
callq 0x2c040
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %ecx
leaq 0x818d6(%rip), %rax     # 0xafcb0
movq (%rax,%rcx,8), %rdi
movq -0x70(%rbp), %rsi
movq -0xa8(%rbp), %rax
movl 0x50(%rax), %edx
callq 0x2e630
movq -0x138(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
movl $0x2, %edx
callq 0x2c160
jmp 0x2e431
cmpl $0x0, -0x9c(%rbp)
jne 0x2e42f
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
leaq 0x6b05b(%rip), %rdx     # 0x99485
callq 0x27d00
jmp 0x2e431
jmp 0x2e433
cmpl $0xc, -0x7c(%rbp)
jne 0x2e446
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2e61a
jmp 0x2e199
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
cmpq $0x0, 0x220(%rax)
jne 0x2e48d
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rdi
addq $0x264, %rdi            # imm = 0x264
callq 0x1d6c0
cmpl $0x0, %eax
je 0x2e612
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x12420
leaq -0xe0(%rbp), %rdi
callq 0x2b710
movl %eax, -0xe4(%rbp)
cmpl $0x0, %eax
je 0x2e5c0
cmpq $0x0, -0xd0(%rbp)
je 0x2e56f
movq -0xd0(%rbp), %rdi
callq 0x378b0
cmpl $0x0, %eax
jne 0x2e56d
xorl %eax, %eax
movl %eax, %edi
callq 0x2b850
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
addq $0x298, %rax            # imm = 0x298
movq %rax, -0x140(%rbp)
movq -0xd0(%rbp), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x7b610
movq -0x140(%rbp), %rdi
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rsi
callq 0x696c0
movq %rax, -0xf8(%rbp)
movups -0xe0(%rbp), %xmm0
movups -0xd0(%rbp), %xmm1
movups -0xc0(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movl $0x1, %edi
callq 0x2b780
jmp 0x2e4a0
jmp 0x2e5be
movq -0xd8(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0xc8(%rbp), %eax
je 0x2e5bc
xorl %eax, %eax
movl %eax, %edi
callq 0x2b850
movups -0xe0(%rbp), %xmm0
movups -0xd0(%rbp), %xmm1
movups -0xc0(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movl $0x1, %edi
callq 0x2b780
jmp 0x2e4a0
jmp 0x2e5be
jmp 0x2e5c0
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
cmpq $0x0, 0x220(%rax)
jne 0x2e5fe
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rdi
addq $0x264, %rdi            # imm = 0x264
callq 0x1d6c0
cmpl $0x0, %eax
je 0x2e610
movl -0xe4(%rbp), %edi
movq -0xe0(%rbp), %rsi
callq 0x2e760
jmp 0x2e612
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw (%rax,%rax)