// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, %r14
movq %rdi, %r15
movq %rsi, %rdi
callq 0x3f44a
movq %rax, -0x60(%rbp)
xorl %r12d, %r12d
testq %r14, %r14
sete %bl
leaq 0x387d4(%rip), %rdi     # 0x59396
callq 0x19f23
shrq $0x2f, %rax
cmpl $0x1fff1, %eax          # imm = 0x1FFF1
jne 0x20bd6
xorl %eax, %eax
jmp 0x20c0e
movabsq $-0x800000000000, %r13  # imm = 0xFFFF800000000000
leaq 0x387af(%rip), %rdi     # 0x59396
callq 0x19f23
andq %r13, %rax
movabsq $-0x7000000000000, %rcx # imm = 0xFFF9000000000000
cmpq %rcx, %rax
movb $0x1, %al
jne 0x20c0e
leaq 0x3878f(%rip), %rdi     # 0x59396
callq 0x19f23
andb $0x1, %al
movq %rax, -0x40(%rbp)
testb %al, %al
je 0x20c35
movq 0x653d3(%rip), %rax     # 0x85ff0
movq (%rax), %rsi
leaq 0x3adf7(%rip), %rdi     # 0x5ba1e
leaq 0x38772(%rip), %rdx     # 0x593a0
xorl %eax, %eax
callq 0x2f340
xorl %edi, %edi
testq %r15, %r15
je 0x20c71
testq %rdi, %rdi
je 0x20c4b
movl -0x4(%rdi), %eax
incl %eax
cmpl -0x8(%rdi), %eax
jl 0x20c5d
movl $0x1, %esi
movl $0x8, %edx
callq 0x4c0b4
movq %rax, %rdi
movslq -0x4(%rdi), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
movq %r15, (%rdi,%rax,8)
movq 0x38(%r15), %r15
jmp 0x20c37
testq %rdi, %rdi
je 0x20c7d
movl -0x4(%rdi), %eax
decl %eax
jmp 0x20c82
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x20f44
movb %bl, %r12b
testq %r14, %r14
leaq 0x4c466(%rip), %rcx     # 0x6d0fd
cmovneq %r14, %rcx
movq %rcx, -0x58(%rbp)
movl %eax, %ecx
movq 0x65348(%rip), %r13     # 0x85ff0
movq %rdi, -0x48(%rbp)
movq (%rdi,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movl 0x14(%rax), %edx
testl %edx, %edx
jle 0x20f34
movq %rcx, -0x50(%rbp)
testl %r12d, %r12d
sete %r14b
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r12
movl %edx, %r15d
movl -0x8(%r12,%r15,8), %eax
movl %eax, -0x2c(%rbp)
testb $0x1, %r14b
je 0x20d21
movq -0x38(%rbp), %rdi
callq 0x29e47
movq -0x60(%rbp), %r9
testq %r9, %r9
movq (%r13), %rsi
movl %eax, %eax
leaq 0x64800(%rip), %rcx     # 0x85500
movq (%rcx,%rax,8), %r8
cmoveq %r8, %r9
leaq 0x3ad0f(%rip), %rdi     # 0x5ba1e
leaq 0x38690(%rip), %rdx     # 0x593a6
movq -0x58(%rbp), %rcx
xorl %eax, %eax
callq 0x2f340
movq (%r13), %rsi
leaq 0x3acf2(%rip), %rbx     # 0x5ba1e
movq %rbx, %rdi
leaq 0x3867a(%rip), %rdx     # 0x593b0
xorl %eax, %eax
callq 0x2f340
movq -0x20(%r12,%r15,8), %rax
testq %rax, %rax
je 0x20d99
movq %r13, %r14
movq 0x10(%rax), %r13
movq (%r14), %rsi
movq 0x48(%r13), %rcx
testq %rcx, %rcx
leaq 0x38656(%rip), %rax     # 0x593b5
cmoveq %rax, %rcx
movq %rbx, %rdi
leaq 0x482c4(%rip), %rdx     # 0x69031
xorl %eax, %eax
callq 0x2f340
movq 0x40(%r13), %rcx
testq %rcx, %rcx
je 0x20d91
movq (%r14), %rsi
movq %rbx, %rdi
leaq 0x38637(%rip), %rdx     # 0x593c1
xorl %eax, %eax
callq 0x2f340
xorl %r14d, %r14d
jmp 0x20e33
movq -0x18(%r12,%r15,8), %rdi
testq %rdi, %rdi
je 0x20df8
callq 0x496ca
movq %rax, %r14
testq %rax, %rax
je 0x20ddd
movq 0x8(%r14), %r8
testq %r8, %r8
je 0x20ddd
movq 0x10(%r14), %rcx
movq (%r13), %rsi
leaq 0x3ac56(%rip), %rdi     # 0x5ba1e
testq %rcx, %rcx
je 0x20dfd
leaq 0x385f3(%rip), %rdx     # 0x593c7
xorl %eax, %eax
callq 0x2f340
jmp 0x20e0e
movq (%r13), %rsi
leaq 0x3ac36(%rip), %rdi     # 0x5ba1e
leaq 0x385df(%rip), %rdx     # 0x593ce
xorl %eax, %eax
callq 0x2f340
jmp 0x20e30
xorl %r14d, %r14d
jmp 0x20e30
leaq 0x4822d(%rip), %rdx     # 0x69031
movq %r8, %rcx
xorl %eax, %eax
callq 0x2f340
movq 0x18(%r14), %rcx
testq %rcx, %rcx
je 0x20e30
movq (%r13), %rsi
leaq 0x3abfc(%rip), %rdi     # 0x5ba1e
leaq 0x38598(%rip), %rdx     # 0x593c1
xorl %eax, %eax
callq 0x2f340
xorl %r13d, %r13d
testb $0x1, -0x4(%r12,%r15,8)
je 0x20e5a
movq 0x651ae(%rip), %rax     # 0x85ff0
movq (%rax), %rsi
leaq 0x3abd2(%rip), %rdi     # 0x5ba1e
leaq 0x38588(%rip), %rdx     # 0x593db
xorl %eax, %eax
callq 0x2f340
cmpq $0x0, -0x20(%r12,%r15,8)
je 0x20ead
movq -0x18(%r12,%r15,8), %rcx
testq %rcx, %rcx
je 0x20ead
subq 0x28(%r13), %rcx
movq 0x38(%r13), %rax
shrq $0x2, %rcx
testq %rax, %rax
je 0x20ee0
movslq %ecx, %rdx
movl (%rax,%rdx,8), %ecx
movl 0x4(%rax,%rdx,8), %r8d
movq 0x65161(%rip), %r13     # 0x85ff0
movq (%r13), %rsi
leaq 0x3ab84(%rip), %rbx     # 0x5ba1e
movq %rbx, %rdi
leaq 0x38544(%rip), %rdx     # 0x593e8
xorl %eax, %eax
callq 0x2f340
jmp 0x20f03
testq %r14, %r14
movq 0x65139(%rip), %r13     # 0x85ff0
leaq 0x3ab60(%rip), %rbx     # 0x5ba1e
je 0x20f03
movslq 0x20(%r14), %rcx
testq %rcx, %rcx
jle 0x20f03
movq (%r13), %rsi
movq %rbx, %rdi
leaq 0x3852f(%rip), %rdx     # 0x59406
xorl %eax, %eax
callq 0x2f340
jmp 0x20f03
movq 0x65109(%rip), %r13     # 0x85ff0
movq (%r13), %rsi
leaq 0x3ab2c(%rip), %rbx     # 0x5ba1e
movq %rbx, %rdi
leaq 0x38503(%rip), %rdx     # 0x593ff
xorl %eax, %eax
callq 0x2f340
movq (%r13), %rsi
xorl %r14d, %r14d
movq %rbx, %rdi
leaq 0x4c1e8(%rip), %rdx     # 0x6d0fc
xorl %eax, %eax
callq 0x2f340
movl -0x2c(%rbp), %edx
testl %edx, %edx
jg 0x20cca
movl $0x1, %r12d
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rcx
leaq -0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
jg 0x20cac
cmpb $0x0, -0x40(%rbp)
je 0x20f6f
movq 0x6509f(%rip), %rax     # 0x85ff0
movq (%rax), %rsi
movq %rdi, %rbx
leaq 0x3aac0(%rip), %rdi     # 0x5ba1e
leaq 0x384ad(%rip), %rdx     # 0x59412
xorl %eax, %eax
callq 0x2f340
movq %rbx, %rdi
testq %rdi, %rdi
je 0x20f8b
addq $-0x8, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c187
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq