// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/debug.c
// Function: janet_debug_find
void janet_debug_find(
    JanetFuncDef **def_out, int32_t *pc_out,
    const uint8_t *source, int32_t sourceLine, int32_t sourceColumn) {
    /* Scan the heap for right func def */
    JanetGCObject *current = janet_vm.blocks;
    /* Keep track of the best source mapping we have seen so far */
    int32_t besti = -1;
    int32_t best_line = -1;
    int32_t best_column = -1;
    JanetFuncDef *best_def = NULL;
    while (NULL != current) {
        if ((current->flags & JANET_MEM_TYPEBITS) == JANET_MEMORY_FUNCDEF) {
            JanetFuncDef *def = (JanetFuncDef *)(current);
            if (def->sourcemap &&
                    def->source &&
                    !janet_string_compare(source, def->source)) {
                /* Correct source file, check mappings. The chosen
                 * pc index is the instruction closest to the given line column, but
                 * not after. */
                int32_t i;
                for (i = 0; i < def->bytecode_length; i++) {
                    int32_t line = def->sourcemap[i].line;
                    int32_t column = def->sourcemap[i].column;
                    if (line <= sourceLine && line >= best_line) {
                        if (column <= sourceColumn &&
                                (line > best_line || column > best_column)) {
                            best_line = line;
                            best_column = column;
                            besti = i;
                            best_def = def;
                        }
                    }
                }
            }
        }
        current = current->data.next;
    }
    if (best_def) {
        *def_out = best_def;
        *pc_out = besti;
    } else {
        janet_panic("could not find breakpoint");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdx, -0x48(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x90(%rax), %r14
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
testq %r14, %r14
je 0x20b3e
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %ebx, -0x30(%rbp)
movl %r15d, -0x2c(%rbp)
cmpb $0xc, (%r14)
jne 0x20b31
cmpq $0x0, 0x38(%r14)
je 0x20b31
movq 0x40(%r14), %rsi
testq %rsi, %rsi
je 0x20b31
movq %r9, %r15
movl %r8d, %ebx
movq -0x48(%rbp), %rdi
callq 0x450ed
testl %eax, %eax
je 0x20ae2
movl %ebx, %r8d
movq %r15, %r9
jmp 0x20b31
movslq 0x70(%r14), %rax
testq %rax, %rax
movl %ebx, %r8d
movq %r15, %r9
jle 0x20b31
movq 0x38(%r14), %rcx
xorl %edx, %edx
movl -0x30(%rbp), %ebx
movl -0x2c(%rbp), %r15d
movl (%rcx,%rdx,8), %esi
cmpl %r15d, %esi
jg 0x20b29
cmpl %r13d, %esi
jl 0x20b29
movl 0x4(%rcx,%rdx,8), %edi
cmpl %ebx, %edi
jg 0x20b29
cmpl %r13d, %esi
jg 0x20b1d
cmpl %r12d, %edi
jle 0x20b29
movl %edi, %r12d
movq %r14, %r9
movl %esi, %r13d
movl %edx, %r8d
incq %rdx
cmpq %rdx, %rax
jne 0x20afe
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0x20ab1
testq %r9, %r9
je 0x20b60
movq -0x38(%rbp), %rax
movq %r9, (%rax)
movq -0x40(%rbp), %rax
movl %r8d, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38815(%rip), %rdi     # 0x5937c
callq 0x19263