// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/build/c/shell.c
// Function: kshowcomp
static void kshowcomp(void) {
    JanetTable *env = gbl_complete_env;
    if (env == NULL) {
        insert(' ', 0);
        insert(' ', 0);
        return;
    }

    /* Advance while on symbol char */
    while (is_symbol_char_gen(gbl_buf[gbl_pos]))
        gbl_pos++;

    JanetByteView prefix = get_symprefix();
    if (prefix.len == 0) return;

    find_matches(prefix);

    check_specials(prefix);

    JanetByteView lcp = longest_common_prefix();
    for (int i = prefix.len; i < lcp.len; i++) {
        insert(lcp.bytes[i], 0);
    }

    if (!gbl_lines_below && prefix.len != lcp.len) return;

    int32_t maxlen = 0;
    for (int i = 0; i < gbl_match_count; i++)
        if (gbl_matches[i].len > maxlen)
            maxlen = gbl_matches[i].len;

    int num_cols = getcols();
    clearlines();
    if (gbl_match_count >= 2) {

        /* Second pass, print */
        int col_width = maxlen + 4;
        int cols = num_cols / col_width;
        if (cols == 0) cols = 1;
        int current_col = 0;
        for (int i = 0; i < gbl_match_count; i++) {
            if (current_col == 0) {
                putc('\n', stderr);
                gbl_lines_below++;
            }
            JanetByteView s = gbl_matches[i];
            fprintf(stderr, "%s", (const char *) s.bytes);
            for (int j = s.len; j < col_width; j++) {
                putc(' ', stderr);
            }
            current_col = (current_col + 1) % cols;
        }

        /* Go up to original line (zsh-like autocompletion) */
        fprintf(stderr, "\x1B[%dA", gbl_lines_below);

        fflush(stderr);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %fs:0x0, %rax
leaq -0x1790(%rax), %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x80729
movl $0x20, %edi
xorl %esi, %esi
callq 0x7fb30
movl $0x20, %edi
xorl %esi, %esi
callq 0x7fb30
jmp 0x80a24
jmp 0x8072b
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movq %rax, -0x68(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movq -0x68(%rbp), %rax
leaq -0x1010(%rcx), %rcx
movslq (%rcx), %rcx
movzbl (%rax,%rcx), %edi
callq 0x813f0
cmpl $0x0, %eax
je 0x80789
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x8072b
callq 0x81590
movq %rax, -0x18(%rbp)
movl %edx, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x807a0
jmp 0x80a24
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x822d0
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x82400
callq 0x82510
movq %rax, -0x28(%rbp)
movl %edx, -0x20(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x807f0
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
xorl %esi, %esi
movsbl (%rax,%rcx), %edi
callq 0x7fb30
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x807ca
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
cmpl $0x0, (%rax)
jne 0x80815
movl -0x10(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x80815
jmp 0x80a24
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movl -0x6c(%rbp), %eax
leaq -0x1008(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x8089d
movq %fs:0x0, %rax
leaq -0x1000(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x30(%rbp), %eax
jle 0x80890
movq %fs:0x0, %rax
leaq -0x1000(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x80892
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x80823
callq 0x7f8a0
movl %eax, -0x38(%rbp)
callq 0x80020
movq %fs:0x0, %rax
leaq -0x1008(%rax), %rax
cmpl $0x2, (%rax)
jl 0x80a24
movl -0x30(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cltd
idivl -0x3c(%rbp)
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x808e6
movl $0x1, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x70(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movl -0x70(%rbp), %eax
leaq -0x1008(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x809e0
cmpl $0x0, -0x44(%rbp)
jne 0x8094f
movq 0x6c6c8(%rip), %rax     # 0xecff0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x155c0
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq %fs:0x0, %rax
leaq -0x1000(%rax), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq 0x6c66d(%rip), %rax     # 0xecff0
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0x5505b(%rip), %rsi     # 0xd59ec
movb $0x0, %al
callq 0x15600
movl -0x50(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x809c5
movq 0x6c643(%rip), %rax     # 0xecff0
movq (%rax), %rsi
movl $0x20, %edi
callq 0x155c0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8099e
movl -0x44(%rbp), %eax
addl $0x1, %eax
cltd
idivl -0x40(%rbp)
movl %edx, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x808f4
movq 0x6c609(%rip), %rax     # 0xecff0
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq %fs:0x0, %rax
movq -0x78(%rbp), %rdi
leaq -0x100c(%rax), %rax
movl (%rax), %edx
leaq 0x55eef(%rip), %rsi     # 0xd68fd
movb $0x0, %al
callq 0x15600
movq 0x6c5d4(%rip), %rax     # 0xecff0
movq (%rax), %rdi
callq 0x15790
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)