// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movabsq $-0x6000000000000, %r14 # imm = 0xFFFA000000000000
callq 0x2327e
movq %rax, %r15
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rbx
leaq 0x36d49(%rip), %r13     # 0x5b939
movq 0x220(%rbx), %rax
testq %rax, %rax
je 0x24c23
movq 0x248(%rbx), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm2, -0x90(%rbp)
movaps %xmm1, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
testq %rax, %rax
je 0x24ced
cmpq %r15, -0xb0(%rbp)
jg 0x24ced
callq 0x23000
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x24c5f
callq 0x2a67c
testl %eax, %eax
je 0x24ca5
movq -0xa8(%rbp), %r12
movq %r13, %rdi
jmp 0x24c83
movq -0xa8(%rbp), %r12
movl 0x48(%r12), %eax
cmpl -0x98(%rbp), %eax
jne 0x24ca5
cmpl $0x0, -0x94(%rbp)
je 0x24cd4
leaq 0x36cc7(%rip), %rdi     # 0x5b94a
callq 0x4516c
movq %rax, %rdi
movq %r14, %rsi
callq 0x4f9ad
movq %r12, %rdi
movq %rax, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x22b9f
movaps -0xb0(%rbp), %xmm0
movaps -0xa0(%rbp), %xmm1
movaps -0x90(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
xorl %edi, %edi
callq 0x22fb6
jmp 0x24bf0
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
jmp 0x24c9e
movl 0x234(%rbx), %eax
cmpl 0x238(%rbx), %eax
je 0x24f54
leaq 0x1c(%rbx), %rax
movq %rax, -0xc0(%rbp)
leaq 0x264(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq 0x298(%rbx), %rax
movq %rax, -0xb8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x1a266
testl %eax, %eax
jne 0x24f54
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, %r12
movslq 0x234(%rbx), %rax
cmpl 0x238(%rbx), %eax
jne 0x24d63
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x24d97
movq 0x240(%rbx), %rcx
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %r15
movq 0x8(%rcx,%rdx,8), %r12
movl 0x10(%rcx,%rdx,8), %r13d
incl %eax
cmpl 0x230(%rbx), %eax
movl 0x14(%rcx,%rdx,8), %r14d
movl $0x0, %ecx
cmovgel %ecx, %eax
movl %eax, 0x234(%rbx)
testb $0x2, 0x2(%r15)
je 0x24da7
movq -0x68(%rbp), %rdi
callq 0x1a24d
andb $-0x4, 0x2(%r15)
movl $0x4, %eax
cmpl 0x48(%r15), %r14d
jne 0x24f3a
movq %r15, %rdi
movq %r12, %rsi
leaq -0x78(%rbp), %rdx
movl %r13d, %ecx
callq 0x4f1dd
movl %eax, %r12d
movq %r15, %rdi
callq 0x2a67c
testl %eax, %eax
jne 0x24dfd
movq %r15, %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4f9f2
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x48127
cmpl $0xe, %r12d
setb %al
movl $0x3008, %r14d          # imm = 0x3008
movl %r12d, %ecx
shrl %cl, %r14d
movq 0x68(%r15), %r13
andb %al, %r14b
cmpb $0x1, %r14b
jne 0x24e2b
orb $0x2, 0x2(%r15)
movq -0x68(%rbp), %rdi
callq 0x1a23c
testq %r13, %r13
je 0x24e77
testl %r12d, %r12d
je 0x24e3f
movl 0x10(%r15), %eax
btl %r12d, %eax
jae 0x24e77
movl %r12d, %eax
leaq 0x60647(%rip), %rcx     # 0x85490
movq (%rcx,%rax,8), %rdi
movl 0x50(%r13), %r14d
callq 0x47cd3
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x4f9ad
movq %rax, -0x60(%rbp)
testl %r14d, %r14d
je 0x24e98
movq 0x40(%r15), %rax
jmp 0x24eaa
testb %r14b, %r14b
jne 0x24f25
movq -0x78(%rbp), %rsi
movq %r15, %rdi
leaq 0x4826f(%rip), %rdx     # 0x6d0fd
callq 0x20b8f
jmp 0x24f25
movq %r15, %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4f9f2
movq %rax, -0x58(%rbp)
movq 0x28(%r15), %r14
testq %r14, %r14
je 0x24ee2
leaq 0x36e53(%rip), %rdi     # 0x5bd11
callq 0x47cd3
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x4f9ad
movq %r14, %rdi
movq %rax, %rsi
callq 0x47f51
jmp 0x24ef1
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, -0x50(%rbp)
leaq -0x60(%rbp), %rdi
movl $0x3, %esi
callq 0x48a9f
movq %rax, %rdi
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
callq 0x4f9ad
movq %r13, %rdi
movq %rax, %rsi
movl $0x2, %edx
callq 0x23526
xorl %eax, %eax
cmpl $0xc, %r12d
sete %al
movq -0x70(%rbp), %rcx
cmoveq %r15, %rcx
movq %rcx, -0x70(%rbp)
testb $0x3, %al
jne 0x25072
movl 0x234(%rbx), %eax
cmpl 0x238(%rbx), %eax
jne 0x24d23
cmpq $0x0, 0x220(%rbx)
jne 0x24f72
leaq 0x264(%rbx), %rdi
callq 0x1a25e
testl %eax, %eax
je 0x2505e
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
leaq 0x298(%rbx), %r14
movq 0x220(%rbx), %rax
testq %rax, %rax
je 0x24fba
movq 0x248(%rbx), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm2, -0x40(%rbp)
movaps %xmm1, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movl $0x1, %r15d
jmp 0x24fbd
xorl %r15d, %r15d
testq %rax, %rax
je 0x25035
movq -0x50(%rbp), %r12
testq %r12, %r12
je 0x24ffb
movq %r12, %rdi
callq 0x2a67c
testl %eax, %eax
jne 0x25035
callq 0x23000
movq %r12, %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4f9f2
movq %r14, %rdi
movq %rax, %rsi
callq 0x48127
jmp 0x2500c
movq -0x58(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0x48(%rbp), %eax
je 0x25035
callq 0x23000
movaps -0x60(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
movaps -0x40(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
callq 0x22fb6
jmp 0x24f88
cmpq $0x0, 0x220(%rbx)
jne 0x25052
addq $0x264, %rbx            # imm = 0x264
movq %rbx, %rdi
callq 0x1a25e
testl %eax, %eax
je 0x2505e
movq -0x60(%rbp), %rsi
movl %r15d, %edi
callq 0x25078
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x70(%rbp), %rax
jmp 0x25060