// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/value.c
// Function: janet_next_impl
Janet janet_next_impl(Janet ds, Janet key, int is_interpreter) {
    JanetType t = janet_type(ds);
    switch (t) {
        default:
            janet_panicf("expected iterable type, got %v", ds);
        case JANET_TABLE:
        case JANET_STRUCT: {
            const JanetKV *start;
            int32_t cap;
            if (t == JANET_TABLE) {
                JanetTable *tab = janet_unwrap_table(ds);
                cap = tab->capacity;
                start = tab->data;
            } else {
                JanetStruct st = janet_unwrap_struct(ds);
                cap = janet_struct_capacity(st);
                start = st;
            }
            const JanetKV *end = start + cap;
            const JanetKV *kv = janet_checktype(key, JANET_NIL)
                                ? start
                                : janet_dict_find(start, cap, key) + 1;
            while (kv < end) {
                if (!janet_checktype(kv->key, JANET_NIL)) return kv->key;
                kv++;
            }
            break;
        }
        case JANET_STRING:
        case JANET_KEYWORD:
        case JANET_SYMBOL:
        case JANET_BUFFER:
        case JANET_ARRAY:
        case JANET_TUPLE: {
            int32_t i;
            if (janet_checktype(key, JANET_NIL)) {
                i = 0;
            } else if (janet_checkint(key)) {
                i = janet_unwrap_integer(key) + 1;
            } else {
                break;
            }
            int32_t len;
            if (t == JANET_BUFFER) {
                len = janet_unwrap_buffer(ds)->count;
            } else if (t == JANET_ARRAY) {
                len = janet_unwrap_array(ds)->count;
            } else if (t == JANET_TUPLE) {
                len = janet_tuple_length(janet_unwrap_tuple(ds));
            } else {
                len = janet_string_length(janet_unwrap_string(ds));
            }
            if (i < len && i >= 0) {
                return janet_wrap_integer(i);
            }
            break;
        }
        case JANET_ABSTRACT: {
            JanetAbstract abst = janet_unwrap_abstract(ds);
            const JanetAbstractType *at = janet_abstract_type(abst);
            if (NULL == at->next) break;
            return at->next(abst, key);
        }
        case JANET_FIBER: {
            JanetFiber *child = janet_unwrap_fiber(ds);
            Janet retreg;
            JanetFiberStatus status = janet_fiber_status(child);
            if (status == JANET_STATUS_ALIVE ||
                    status == JANET_STATUS_DEAD ||
                    status == JANET_STATUS_ERROR ||
                    status == JANET_STATUS_USER0 ||
                    status == JANET_STATUS_USER1 ||
                    status == JANET_STATUS_USER2 ||
                    status == JANET_STATUS_USER3 ||
                    status == JANET_STATUS_USER4) {
                return janet_wrap_nil();
            }
            janet_vm.fiber->child = child;
            JanetSignal sig = janet_continue(child, janet_wrap_nil(), &retreg);
            if (sig != JANET_SIGNAL_OK && !(child->flags & (1 << sig))) {
                if (is_interpreter) {
                    janet_signalv(sig, retreg);
                } else {
                    janet_vm.fiber->child = NULL;
                    janet_panicv(retreg);
                }
            }
            janet_vm.fiber->child = NULL;
            if (sig == JANET_SIGNAL_OK ||
                    sig == JANET_SIGNAL_ERROR ||
                    sig == JANET_SIGNAL_USER0 ||
                    sig == JANET_SIGNAL_USER1 ||
                    sig == JANET_SIGNAL_USER2 ||
                    sig == JANET_SIGNAL_USER3 ||
                    sig == JANET_SIGNAL_USER4) {
                /* Fiber cannot be resumed, so discard last value. */
                return janet_wrap_nil();
            } else {
                return janet_wrap_integer(0);
            }
        }
    }
    return janet_wrap_nil();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r12
movq %rdi, %xmm0
movq %rdi, %rax
shrq $0x2f, %rax
andl $0xf, %eax
xorl %r13d, %r13d
ucomisd %xmm0, %xmm0
cmovpl %eax, %r13d
leal -0x3(%r13), %eax
cmpl $0xb, %eax
ja 0x4a147
movq %rsi, %r14
movabsq $-0x77fffffffffff, %rbx # imm = 0xFFF8800000000001
leaq 0x21738(%rip), %rcx     # 0x6b6a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq %r14, %rax
leaq -0x1(%rbx), %rcx
xorl %r15d, %r15d
cmpq %rcx, %rax
je 0x49fa7
movq %r14, %rdi
callq 0x49912
testl %eax, %eax
je 0x4a1a7
movq %r14, %xmm0
cvttsd2si %xmm0, %r15d
incl %r15d
movq %r12, %rdi
callq 0x4ebc4
addl $-0x7, %r13d
movq $-0x8, %rcx
cmpl $0x4, %r13d
ja 0x49fce
movl %r13d, %ecx
leaq 0x218e6(%rip), %rdx     # 0x6b8b0
movq (%rdx,%rcx,8), %rcx
testl %r15d, %r15d
js 0x4a1a7
cmpl (%rax,%rcx), %r15d
jge 0x4a1a7
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ee44
movq %r12, %rdi
callq 0x4ebc4
movq %rax, %rcx
addq $-0x10, %rcx
jmp 0x4a08c
movl %edx, %r15d
movq %r12, %rdi
callq 0x4ebc4
movq %rax, %r14
movq %rax, %rdi
callq 0x2996f
cmpl $0xf, %eax
ja 0x4a0c6
movl $0x81f3, %ecx           # imm = 0x81F3
btl %eax, %ecx
jae 0x4a0c6
movq %rbx, %rdi
callq 0x4ece6
movq %rax, %rcx
jmp 0x4a195
movq %r12, %rdi
callq 0x4ebc4
movq -0x10(%rax), %rcx
movq 0x50(%rcx), %rcx
testq %rcx, %rcx
je 0x4a1a7
movq %rax, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
movq %r12, %rdi
callq 0x4ebc4
movq %rax, %rcx
movq 0x20(%rax), %rax
addq $0x14, %rcx
movabsq $-0x800000000000, %r15  # imm = 0xFFFF800000000000
movslq (%rcx), %rsi
movq %rsi, %r12
shlq $0x4, %r12
addq %rax, %r12
movq %r14, %rcx
andq %r15, %rcx
leaq -0x1(%rbx), %r13
cmpq %r13, %rcx
je 0x4a182
movq %rax, %rdi
movq %r14, %rdx
callq 0x48578
jmp 0x4a17e
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %r12
movq 0x20(%rax), %rax
movq %r14, 0x38(%rax)
movq %rbx, %rdi
callq 0x4ece6
leaq -0x30(%rbp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x4b6c1
testl %eax, %eax
je 0x4a135
movl 0x10(%r14), %ecx
btl %eax, %ecx
jae 0x4a158
movq 0x20(%r12), %rcx
movq $0x0, 0x38(%rcx)
leal -0x4(%rax), %ecx
cmpl $0x5, %ecx
jb 0x4a03a
cmpl $0x1, %eax
je 0x4a03a
xorpd %xmm0, %xmm0
callq 0x4ee44
jmp 0x4a042
movq 0x20(%r12), %rax
movq $0x0, 0x38(%rax)
jmp 0x4a03a
leaq 0x2178a(%rip), %rdi     # 0x6b8d8
movq %r12, %rsi
xorl %eax, %eax
callq 0x190bb
testl %r15d, %r15d
jne 0x4a173
movq 0x20(%r12), %rax
movq $0x0, 0x38(%rax)
movq -0x30(%rbp), %rdi
callq 0x190aa
movq -0x30(%rbp), %rsi
movl %eax, %edi
callq 0x18fc4
addq $0x10, %rax
cmpq %r12, %rax
jae 0x4a1a7
movq (%rax), %rcx
movq %rcx, %rdx
andq %r15, %rdx
cmpq %r13, %rdx
je 0x4a17e
movq %rcx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ece6