// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rdi, %r15
movq %rsi, %rdi
callq 0x3b7f1
movq %rax, -0x58(%rbp)
xorl %r14d, %r14d
testq %rbx, %rbx
sete %r12b
leaq 0x359e9(%rip), %rdi     # 0x54396
callq 0x1839c
shrq $0x2f, %rax
cmpl $0x1fff1, %eax          # imm = 0x1FFF1
jne 0x1e9c6
movl $0x0, -0x2c(%rbp)
jmp 0x1ea22
movabsq $-0x800000000000, %r13  # imm = 0xFFFF800000000000
leaq 0x359bf(%rip), %rdi     # 0x54396
callq 0x1839c
andq %r13, %rax
movabsq $-0x7000000000000, %rcx # imm = 0xFFF9000000000000
cmpq %rcx, %rax
jne 0x1e9fe
leaq 0x359a1(%rip), %rdi     # 0x54396
callq 0x1839c
testb $0x1, %al
je 0x1e9bd
movq 0x615eb(%rip), %rax     # 0x7fff0
movq (%rax), %rsi
leaq 0x3800f(%rip), %rdi     # 0x56a1e
leaq 0x3598a(%rip), %rdx     # 0x543a0
xorl %eax, %eax
callq 0x2c621
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movb %r12b, %r14b
movq $0x0, -0x38(%rbp)
pushq $0x8
popq %r12
testq %r15, %r15
je 0x1ea71
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x1ea4a
movl -0x4(%rdi), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rdi), %ecx
jl 0x1ea5e
pushq $0x1
popq %rsi
movl %r12d, %edx
callq 0x4799c
movq %rax, %rdi
movl -0x4(%rax), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cltq
movq %rdi, -0x38(%rbp)
movq %r15, (%rdi,%rax,8)
movq 0x38(%r15), %r15
jmp 0x1ea31
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x1ea81
movl -0x4(%rax), %eax
decl %eax
jmp 0x1ea84
pushq $-0x1
popq %rax
testq %rbx, %rbx
leaq 0x4966f(%rip), %rcx     # 0x680fd
cmovneq %rbx, %rcx
movq %rcx, -0x50(%rbp)
movq 0x61553(%rip), %r13     # 0x7fff0
testl %eax, %eax
movq -0x38(%rbp), %rbx
js 0x1ed24
movl %eax, -0x3c(%rbp)
movl %eax, %eax
movq (%rbx,%rax,8), %rax
movq %rax, -0x48(%rbp)
movl 0x14(%rax), %ecx
testl %ecx, %ecx
jle 0x1ed1a
movq -0x48(%rbp), %rax
movq 0x30(%rax), %r15
movl %ecx, %r12d
movl -0x8(%r15,%r12,8), %eax
movl %eax, -0x40(%rbp)
testl %r14d, %r14d
jne 0x1eb17
movq -0x48(%rbp), %rdi
callq 0x27553
movq -0x58(%rbp), %r9
testq %r9, %r9
movq (%r13), %rsi
movl %eax, %eax
leaq 0x60a0a(%rip), %rcx     # 0x7f500
movq (%rcx,%rax,8), %r8
cmoveq %r8, %r9
leaq 0x37f19(%rip), %rdi     # 0x56a1e
leaq 0x3589a(%rip), %rdx     # 0x543a6
movq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0x2c621
movq (%r13), %rsi
leaq 0x37efc(%rip), %rbx     # 0x56a1e
movq %rbx, %rdi
leaq 0x35884(%rip), %rdx     # 0x543b0
xorl %eax, %eax
callq 0x2c621
movq -0x20(%r15,%r12,8), %rax
testq %rax, %rax
je 0x1eb8f
movq %r13, %r14
movq 0x10(%rax), %r13
movq (%r14), %rsi
movq 0x48(%r13), %rcx
testq %rcx, %rcx
leaq 0x35860(%rip), %rax     # 0x543b5
cmoveq %rax, %rcx
movq %rbx, %rdi
leaq 0x454ce(%rip), %rdx     # 0x64031
xorl %eax, %eax
callq 0x2c621
movq 0x40(%r13), %rcx
testq %rcx, %rcx
je 0x1eb87
movq (%r14), %rsi
movq %rbx, %rdi
leaq 0x35841(%rip), %rdx     # 0x543c1
xorl %eax, %eax
callq 0x2c621
xorl %r14d, %r14d
jmp 0x1ec29
movq -0x18(%r15,%r12,8), %rdi
testq %rdi, %rdi
je 0x1ebee
callq 0x4513c
movq %rax, %r14
testq %rax, %rax
je 0x1ebd3
movq 0x8(%r14), %r8
testq %r8, %r8
je 0x1ebd3
movq 0x10(%r14), %rcx
movq (%r13), %rsi
leaq 0x37e60(%rip), %rdi     # 0x56a1e
testq %rcx, %rcx
je 0x1ebf3
leaq 0x357fd(%rip), %rdx     # 0x543c7
xorl %eax, %eax
callq 0x2c621
jmp 0x1ec04
movq (%r13), %rsi
leaq 0x37e40(%rip), %rdi     # 0x56a1e
leaq 0x357e9(%rip), %rdx     # 0x543ce
xorl %eax, %eax
callq 0x2c621
jmp 0x1ec26
xorl %r14d, %r14d
jmp 0x1ec26
leaq 0x45437(%rip), %rdx     # 0x64031
movq %r8, %rcx
xorl %eax, %eax
callq 0x2c621
movq 0x18(%r14), %rcx
testq %rcx, %rcx
je 0x1ec26
movq (%r13), %rsi
leaq 0x37e06(%rip), %rdi     # 0x56a1e
leaq 0x357a2(%rip), %rdx     # 0x543c1
xorl %eax, %eax
callq 0x2c621
xorl %r13d, %r13d
testb $0x1, -0x4(%r15,%r12,8)
je 0x1ec50
movq 0x613b8(%rip), %rax     # 0x7fff0
movq (%rax), %rsi
leaq 0x37ddc(%rip), %rdi     # 0x56a1e
leaq 0x35792(%rip), %rdx     # 0x543db
xorl %eax, %eax
callq 0x2c621
cmpq $0x0, -0x20(%r15,%r12,8)
je 0x1eca3
movq -0x18(%r15,%r12,8), %rcx
testq %rcx, %rcx
je 0x1eca3
subq 0x28(%r13), %rcx
movq 0x38(%r13), %rax
shrq $0x2, %rcx
testq %rax, %rax
je 0x1ecd6
movslq %ecx, %rdx
movl (%rax,%rdx,8), %ecx
movl 0x4(%rax,%rdx,8), %r8d
movq 0x6136b(%rip), %r13     # 0x7fff0
movq (%r13), %rsi
leaq 0x37d8e(%rip), %rbx     # 0x56a1e
movq %rbx, %rdi
leaq 0x3574e(%rip), %rdx     # 0x543e8
xorl %eax, %eax
callq 0x2c621
jmp 0x1ecf9
testq %r14, %r14
movq 0x61343(%rip), %r13     # 0x7fff0
leaq 0x37d6a(%rip), %rbx     # 0x56a1e
je 0x1ecf9
movslq 0x20(%r14), %rcx
testq %rcx, %rcx
jle 0x1ecf9
movq (%r13), %rsi
movq %rbx, %rdi
leaq 0x35739(%rip), %rdx     # 0x54406
xorl %eax, %eax
callq 0x2c621
jmp 0x1ecf9
movq 0x61313(%rip), %r13     # 0x7fff0
movq (%r13), %rsi
leaq 0x37d36(%rip), %rbx     # 0x56a1e
movq %rbx, %rdi
leaq 0x3570d(%rip), %rdx     # 0x543ff
xorl %eax, %eax
callq 0x2c621
movq (%r13), %rsi
movq %rbx, %rdi
leaq 0x493f5(%rip), %rdx     # 0x680fc
xorl %eax, %eax
callq 0x2c621
pushq $0x1
popq %r14
movl -0x40(%rbp), %ecx
jmp 0x1eab9
movl -0x3c(%rbp), %eax
decl %eax
jmp 0x1ea9d
cmpb $0x0, -0x2c(%rbp)
je 0x1ed43
movq (%r13), %rsi
leaq 0x37ce9(%rip), %rdi     # 0x56a1e
leaq 0x356d6(%rip), %rdx     # 0x54412
xorl %eax, %eax
callq 0x2c621
testq %rbx, %rbx
je 0x1ed62
addq $-0x8, %rbx
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x298c1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq