// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/debug.c
// Function: janet_stacktrace_ext
void janet_stacktrace_ext(JanetFiber *fiber, Janet err, const char *prefix) {

    int32_t fi;
    const char *errstr = (const char *)janet_to_string(err);
    JanetFiber **fibers = NULL;
    int wrote_error = !prefix;

    int print_color = janet_truthy(janet_dyn("err-color"));
    if (print_color) janet_eprintf("\x1b[31m");

    while (fiber) {
        janet_v_push(fibers, fiber);
        fiber = fiber->child;
    }

    for (fi = janet_v_count(fibers) - 1; fi >= 0; fi--) {
        fiber = fibers[fi];
        int32_t i = fiber->frame;
        while (i > 0) {
            JanetCFunRegistry *reg = NULL;
            JanetStackFrame *frame = (JanetStackFrame *)(fiber->data + i - JANET_FRAME_SIZE);
            JanetFuncDef *def = NULL;
            i = frame->prevframe;

            /* Print prelude to stack frame */
            if (!wrote_error) {
                JanetFiberStatus status = janet_fiber_status(fiber);
                janet_eprintf("%s%s: %s\n",
                              prefix ? prefix : "",
                              janet_status_names[status],
                              errstr ? errstr : janet_status_names[status]);
                wrote_error = 1;
            }

            janet_eprintf("  in");

            if (frame->func) {
                def = frame->func->def;
                janet_eprintf(" %s", def->name ? (const char *)def->name : "<anonymous>");
                if (def->source) {
                    janet_eprintf(" [%s]", (const char *)def->source);
                }
            } else {
                JanetCFunction cfun = (JanetCFunction)(frame->pc);
                if (cfun) {
                    reg = janet_registry_get(cfun);
                    if (NULL != reg && NULL != reg->name) {
                        if (reg->name_prefix) {
                            janet_eprintf(" %s/%s", reg->name_prefix, reg->name);
                        } else {
                            janet_eprintf(" %s", reg->name);
                        }
                        if (NULL != reg->source_file) {
                            janet_eprintf(" [%s]", reg->source_file);
                        }
                    } else {
                        janet_eprintf(" <cfunction>");
                    }
                }
            }
            if (frame->flags & JANET_STACKFRAME_TAILCALL)
                janet_eprintf(" (tail call)");
            if (frame->func && frame->pc) {
                int32_t off = (int32_t)(frame->pc - def->bytecode);
                if (def->sourcemap) {
                    JanetSourceMapping mapping = def->sourcemap[off];
                    janet_eprintf(" on line %d, column %d", mapping.line, mapping.column);
                } else {
                    janet_eprintf(" pc=%d", off);
                }
            } else if (NULL != reg) {
                /* C Function */
                if (reg->source_line > 0) {
                    janet_eprintf(" on line %d", (long) reg->source_line);
                }
            }
            janet_eprintf("\n");
            /* Print fiber points optionally. Clutters traces but provides info
            if (i <= 0 && fi > 0) {
                janet_eprintf("  in parent fiber\n");
            }
            */
        }
    }

    if (print_color) janet_eprintf("\x1b[0m");

    janet_v_free(fibers);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rdi, -0x38(%rbp)
movq %rsi, %rdi
callq 0x3ed51
movq %rax, -0x68(%rbp)
xorl %r15d, %r15d
testq %rbx, %rbx
sete %r14b
leaq 0x37b40(%rip), %rdi     # 0x58396
callq 0x19e4d
shrq $0x2f, %rax
cmpl $0x1fff1, %eax          # imm = 0x1FFF1
jne 0x2086f
movl $0x0, -0x2c(%rbp)
jmp 0x208cb
movabsq $-0x800000000000, %r12  # imm = 0xFFFF800000000000
leaq 0x37b16(%rip), %rdi     # 0x58396
callq 0x19e4d
andq %r12, %rax
movabsq $-0x7000000000000, %rcx # imm = 0xFFF9000000000000
cmpq %rcx, %rax
jne 0x208a7
leaq 0x37af8(%rip), %rdi     # 0x58396
callq 0x19e4d
testb $0x1, %al
je 0x20866
movq 0x64742(%rip), %rax     # 0x84ff0
movq (%rax), %rsi
leaq 0x3a166(%rip), %rdi     # 0x5aa1e
leaq 0x37ae1(%rip), %rdx     # 0x583a0
xorl %eax, %eax
callq 0x2ed91
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x20bdd
movb %r14b, %r15b
xorl %edi, %edi
movq %rax, %r14
testq %rdi, %rdi
je 0x208f0
movl -0x4(%rdi), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rdi), %ecx
jl 0x20908
movl $0x1, %esi
movl $0x8, %edx
callq 0x4b4e8
movq %rax, %rdi
movl -0x4(%rax), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cltq
movq %r14, (%rdi,%rax,8)
movq 0x38(%r14), %r14
testq %r14, %r14
jne 0x208e0
movl -0x4(%rdi), %ecx
testl %ecx, %ecx
jle 0x20bd7
decl %ecx
testq %rbx, %rbx
leaq 0x4b7ac(%rip), %rax     # 0x6c0dd
cmovneq %rbx, %rax
movq %rax, -0x60(%rbp)
movq 0x646b0(%rip), %r13     # 0x84ff0
movq %rdi, -0x50(%rbp)
movq (%rdi,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movl 0x14(%rax), %edx
testl %edx, %edx
jle 0x20bc7
movq %rcx, -0x58(%rbp)
testl %r15d, %r15d
sete %bl
movq -0x48(%rbp), %rax
movq 0x30(%rax), %r12
movl %edx, %r15d
movl -0x8(%r12,%r15,8), %eax
movl %eax, -0x3c(%rbp)
testb $0x1, %bl
je 0x209b7
movq -0x48(%rbp), %rdi
callq 0x2996f
movq -0x68(%rbp), %r9
testq %r9, %r9
movq (%r13), %rsi
movl %eax, %eax
leaq 0x63b6a(%rip), %rcx     # 0x84500
movq (%rcx,%rax,8), %r8
cmoveq %r8, %r9
leaq 0x3a079(%rip), %rdi     # 0x5aa1e
leaq 0x379fa(%rip), %rdx     # 0x583a6
movq -0x60(%rbp), %rcx
xorl %eax, %eax
callq 0x2ed91
movq (%r13), %rsi
leaq 0x3a05c(%rip), %r14     # 0x5aa1e
movq %r14, %rdi
leaq 0x379e4(%rip), %rdx     # 0x583b0
xorl %eax, %eax
callq 0x2ed91
movq -0x20(%r12,%r15,8), %rax
testq %rax, %rax
je 0x20a2e
movq %r13, %rbx
movq 0x10(%rax), %r13
movq (%rbx), %rsi
movq 0x48(%r13), %rcx
testq %rcx, %rcx
leaq 0x379c0(%rip), %rax     # 0x583b5
cmoveq %rax, %rcx
movq %r14, %rdi
leaq 0x4760e(%rip), %rdx     # 0x68011
xorl %eax, %eax
callq 0x2ed91
movq 0x40(%r13), %rcx
testq %rcx, %rcx
je 0x20a27
movq (%rbx), %rsi
movq %r14, %rdi
leaq 0x379a1(%rip), %rdx     # 0x583c1
xorl %eax, %eax
callq 0x2ed91
xorl %ebx, %ebx
jmp 0x20ac7
movq -0x18(%r12,%r15,8), %rdi
testq %rdi, %rdi
je 0x20a8d
callq 0x48bbc
movq %rax, %rbx
testq %rax, %rax
je 0x20a72
movq 0x8(%rbx), %r8
testq %r8, %r8
je 0x20a72
movq 0x10(%rbx), %rcx
movq (%r13), %rsi
leaq 0x39fc1(%rip), %rdi     # 0x5aa1e
testq %rcx, %rcx
je 0x20a91
leaq 0x3795e(%rip), %rdx     # 0x583c7
xorl %eax, %eax
callq 0x2ed91
jmp 0x20aa2
movq (%r13), %rsi
leaq 0x39fa1(%rip), %rdi     # 0x5aa1e
leaq 0x3794a(%rip), %rdx     # 0x583ce
xorl %eax, %eax
callq 0x2ed91
jmp 0x20ac4
xorl %ebx, %ebx
jmp 0x20ac4
leaq 0x47579(%rip), %rdx     # 0x68011
movq %r8, %rcx
xorl %eax, %eax
callq 0x2ed91
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
je 0x20ac4
movq (%r13), %rsi
leaq 0x39f68(%rip), %rdi     # 0x5aa1e
leaq 0x37904(%rip), %rdx     # 0x583c1
xorl %eax, %eax
callq 0x2ed91
xorl %r13d, %r13d
testb $0x1, -0x4(%r12,%r15,8)
je 0x20aee
movq 0x6451a(%rip), %rax     # 0x84ff0
movq (%rax), %rsi
leaq 0x39f3e(%rip), %rdi     # 0x5aa1e
leaq 0x378f4(%rip), %rdx     # 0x583db
xorl %eax, %eax
callq 0x2ed91
cmpq $0x0, -0x20(%r12,%r15,8)
je 0x20b41
movq -0x18(%r12,%r15,8), %rcx
testq %rcx, %rcx
je 0x20b41
subq 0x28(%r13), %rcx
movq 0x38(%r13), %rax
shrq $0x2, %rcx
testq %rax, %rax
je 0x20b74
movslq %ecx, %rdx
movl (%rax,%rdx,8), %ecx
movl 0x4(%rax,%rdx,8), %r8d
movq 0x644cd(%rip), %r13     # 0x84ff0
movq (%r13), %rsi
leaq 0x39ef0(%rip), %r14     # 0x5aa1e
movq %r14, %rdi
leaq 0x378b0(%rip), %rdx     # 0x583e8
xorl %eax, %eax
callq 0x2ed91
jmp 0x20b97
testq %rbx, %rbx
movq 0x644a5(%rip), %r13     # 0x84ff0
leaq 0x39ecc(%rip), %r14     # 0x5aa1e
je 0x20b97
movslq 0x20(%rbx), %rcx
testq %rcx, %rcx
jle 0x20b97
movq (%r13), %rsi
movq %r14, %rdi
leaq 0x3789b(%rip), %rdx     # 0x58406
xorl %eax, %eax
callq 0x2ed91
jmp 0x20b97
movq 0x64475(%rip), %r13     # 0x84ff0
movq (%r13), %rsi
leaq 0x39e98(%rip), %r14     # 0x5aa1e
movq %r14, %rdi
leaq 0x3786f(%rip), %rdx     # 0x583ff
xorl %eax, %eax
callq 0x2ed91
movq (%r13), %rsi
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0x4b535(%rip), %rdx     # 0x6c0dc
xorl %eax, %eax
callq 0x2ed91
movl -0x3c(%rbp), %edx
testl %edx, %edx
jg 0x20961
movl $0x1, %r15d
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rcx
leaq -0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
jg 0x20944
movq -0x38(%rbp), %rax
jmp 0x20bdf
xorl %edi, %edi
cmpb $0x0, -0x2c(%rbp)
je 0x20c0e
movq 0x64404(%rip), %rax     # 0x84ff0
movq (%rax), %rsi
movq %rdi, %rbx
leaq 0x39e25(%rip), %rdi     # 0x5aa1e
leaq 0x37812(%rip), %rdx     # 0x58412
xorl %eax, %eax
callq 0x2ed91
movq %rbx, %rdi
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x20c2a
addq $-0x8, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2bcd9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq