// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movl %ecx, %r12d
movq %rdx, -0x50(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdi, -0x40(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq %rax, %rbx
addq $0x90, %rbx
pushq $-0x1
popq %r14
xorl %edi, %edi
movl %r14d, %r13d
movl %r14d, %r8d
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x1e928
cmpb $0xc, (%rbx)
jne 0x1e8d1
cmpq $0x0, 0x38(%rbx)
je 0x1e8d1
movq 0x40(%rbx), %rsi
testq %rsi, %rsi
je 0x1e8d1
movl %r8d, -0x2c(%rbp)
movq %rdi, -0x38(%rbp)
movq -0x50(%rbp), %rdi
callq 0x4116d
testl %eax, %eax
je 0x1e8d7
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %r8d
addq $0x8, %rbx
jmp 0x1e893
movl 0x70(%rbx), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %r8d
cmpq %rcx, %rax
je 0x1e8d1
movq 0x38(%rbx), %rsi
movl (%rsi,%rcx,8), %edx
cmpl %r12d, %edx
jg 0x1e923
cmpl %r13d, %edx
jl 0x1e923
movl 0x4(%rsi,%rcx,8), %esi
cmpl %r15d, %esi
jg 0x1e923
cmpl %r13d, %edx
jg 0x1e917
cmpl %r14d, %esi
jle 0x1e923
movl %esi, %r14d
movq %rbx, %rdi
movl %edx, %r13d
movl %ecx, %r8d
incq %rcx
jmp 0x1e8ee
testq %rdi, %rdi
je 0x1e94a
movq -0x40(%rbp), %rax
movq %rdi, (%rax)
movq -0x48(%rbp), %rax
movl %r8d, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35a2b(%rip), %rdi     # 0x5437c
callq 0x177b1