// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/build/c/shell.c
// Function: line
static int line() {
    gbl_cols = getcols();
    gbl_plen = 0;
    gbl_len = 0;
    gbl_pos = 0;
    while (gbl_prompt[gbl_plen]) gbl_plen++;
    gbl_buf[0] = '\0';

    addhistory();

    if (write_console((char *) gbl_prompt, gbl_plen) == -1) return -1;
    for (;;) {
        char c;
        char seq[5];

        int rc;
        do {
            rc = read_console(&c, 1);
        } while (rc < 0 && errno == EINTR);
        if (rc <= 0) return -1;

        switch (c) {
            default:
                if ((unsigned char) c < 0x20) break;
                if (insert(c, 1)) return -1;
                break;
            case 1:     /* ctrl-a */
                gbl_pos = 0;
                refresh();
                break;
            case 2:     /* ctrl-b */
                kleft();
                break;
            case 3:     /* ctrl-c */
                clearlines();
                norawmode();
#ifdef _WIN32
                ExitProcess(1);
#else
                kill(getpid(), SIGINT);
#endif
            /* fallthrough */
            case 17:    /* ctrl-q */
                gbl_cancel_current_repl_form = 1;
                clearlines();
                return -1;
            case 4:     /* ctrl-d, eof */
                if (gbl_len == 0) {   /* quit on empty line */
                    clearlines();
                    return -1;
                }
                kdelete(1);
                break;
            case 5:     /* ctrl-e */
                gbl_pos = gbl_len;
                refresh();
                break;
            case 6:     /* ctrl-f */
                kright();
                break;
            case 7: /* ctrl-g */
                kshowdoc();
                refresh();
                break;
            case 127:   /* backspace */
            case 8:     /* ctrl-h */
                kbackspace(1);
                break;
            case 9:     /* tab */
                kshowcomp();
                refresh();
                break;
            case 11: /* ctrl-k */
                gbl_buf[gbl_pos] = '\0';
                gbl_len = gbl_pos;
                refresh();
                break;
            case 12:    /* ctrl-l */
                clear();
                refresh();
                break;
            case 13:    /* enter */
                clearlines();
                return 0;
            case 14: /* ctrl-n */
                historymove(-1);
                break;
            case 16: /* ctrl-p */
                historymove(1);
                break;
            case 21: { /* ctrl-u */
                memmove(gbl_buf, gbl_buf + gbl_pos, gbl_len - gbl_pos);
                gbl_len -= gbl_pos;
                gbl_buf[gbl_len] = '\0';
                gbl_pos = 0;
                refresh();
                break;
            }
            case 23: /* ctrl-w */
                kbackspacew();
                break;
#ifndef _WIN32
            case 26: /* ctrl-z */
                clearlines();
                norawmode();
                kill(getpid(), SIGSTOP);
                rawmode();
                refresh();
                break;
#endif
            case 27:    /* escape sequence */
                /* Read the next two bytes representing the escape sequence.
                 * Use two calls to handle slow terminals returning the two
                 * chars at different times. */
                if (read_console(seq, 1) == -1) break;
                /* Esc[ = Control Sequence Introducer (CSI) */
                if (seq[0] == '[') {
                    if (read_console(seq + 1, 1) == -1) break;
                    if (seq[1] >= '0' && seq[1] <= '9') {
                        /* Extended escape, read additional byte. */
                        if (read_console(seq + 2, 1) == -1) break;
                        if (seq[2] == '~') {
                            switch (seq[1]) {
                                case '1': /* Home */
                                    gbl_pos = 0;
                                    refresh();
                                    break;
                                case '3': /* delete */
                                    kdelete(1);
                                    break;
                                case '4': /* End */
                                    gbl_pos = gbl_len;
                                    refresh();
                                    break;
                                default:
                                    break;
                            }
                        } else if (seq[2] == ';') {
                            if (read_console(seq + 3, 2) == -1) break;
                            if (seq[3] == '5') {
                                switch (seq[4]) {
                                    case 'C': /* ctrl-right */
                                        krightw();
                                        break;
                                    case 'D': /* ctrl-left */
                                        kleftw();
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                    } else if (seq[0] == 'O') {
                        if (read_console(seq + 1, 1) == -1) break;
                        switch (seq[1]) {
                            default:
                                break;
                            case 'H': /* Home (some keyboards) */
                                gbl_pos = 0;
                                refresh();
                                break;
                            case 'F': /* End (some keyboards) */
                                gbl_pos = gbl_len;
                                refresh();
                                break;
                        }
                    } else {
                        switch (seq[1]) {
                            /* Single escape sequences */
                            default:
                                break;
                            case 'A': /* Up */
                                historymove(1);
                                break;
                            case 'B': /* Down */
                                historymove(-1);
                                break;
                            case 'C': /* Right */
                                kright();
                                break;
                            case 'D': /* Left */
                                kleft();
                                break;
                            case 'H': /* Home */
                                gbl_pos = 0;
                                refresh();
                                break;
                            case 'F': /* End */
                                gbl_pos = gbl_len;
                                refresh();
                                break;
                        }
                    }
                } else {
                    /* Check alt-(shift) bindings */
                    switch (seq[0]) {
                        default:
                            break;
                        case 'd': /* Alt-d */
                            kdeletew();
                            break;
                        case 'b': /* Alt-b */
                            kleftw();
                            break;
                        case 'f': /* Alt-f */
                            krightw();
                            break;
                        case ',': /* Alt-, */
                            historymove(JANET_HISTORY_MAX);
                            break;
                        case '.': /* Alt-. */
                            historymove(-JANET_HISTORY_MAX);
                            break;
                        case 127: /* Alt-backspace */
                            kbackspacew();
                            break;
                    }
                }
                break;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
callq 0x7f8a0
movl %eax, -0x14(%rbp)
movq %fs:0x0, %rax
movl -0x14(%rbp), %ecx
leaq -0x1af0(%rax), %rax
movl %ecx, (%rax)
movq %fs:0x0, %rax
leaq -0x1aec(%rax), %rax
movl $0x0, (%rax)
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl $0x0, (%rax)
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
movq %fs:0x0, %rax
leaq -0x1af8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
leaq -0x1aec(%rcx), %rcx
movslq (%rcx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x7f0ff
movq %fs:0x0, %rax
leaq -0x1aec(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x7f0a6
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movb $0x0, (%rax)
callq 0x7f980
movq %fs:0x0, %rax
leaq -0x1af8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq %fs:0x0, %rax
movq -0x28(%rbp), %rdi
leaq -0x1aec(%rax), %rax
movslq (%rax), %rsi
callq 0x7fad0
cmpq $-0x1, %rax
jne 0x7f165
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f886
jmp 0x7f167
jmp 0x7f169
leaq -0x5(%rbp), %rdi
movl $0x1, %esi
callq 0x7fb00
movl %eax, -0x10(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x29(%rbp)
jge 0x7f193
callq 0x15120
cmpl $0x4, (%rax)
sete %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x7f169
cmpl $0x0, -0x10(%rbp)
jg 0x7f1ac
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f886
movsbl -0x5(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x7e, %eax
ja 0x7f1d1
movq -0x38(%rbp), %rax
leaq 0x574ac(%rip), %rcx     # 0xd6674
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x5(%rbp), %eax
cmpl $0x20, %eax
jge 0x7f1df
jmp 0x7f881
movl $0x1, %esi
movsbl -0x5(%rbp), %edi
callq 0x7fb30
cmpl $0x0, %eax
je 0x7f1fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f886
jmp 0x7f881
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
callq 0x7fe10
jmp 0x7f881
callq 0x7ffe0
jmp 0x7f881
callq 0x80020
callq 0x7e970
callq 0x15260
movl %eax, %edi
movl $0x2, %esi
callq 0x156f0
movq %fs:0x0, %rax
leaq -0x1788(%rax), %rax
movl $0x1, (%rax)
callq 0x80020
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f886
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
cmpl $0x0, (%rax)
jne 0x7f29e
callq 0x80020
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7f886
movl $0x1, %edi
callq 0x800f0
jmp 0x7f881
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq %fs:0x0, %rax
movl -0x3c(%rbp), %ecx
leaq -0x1010(%rax), %rax
movl %ecx, (%rax)
callq 0x7fe10
jmp 0x7f881
callq 0x80250
jmp 0x7f881
callq 0x802c0
callq 0x7fe10
jmp 0x7f881
movl $0x1, %edi
callq 0x80590
jmp 0x7f881
callq 0x806e0
callq 0x7fe10
jmp 0x7f881
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movq %rax, -0x48(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movq -0x48(%rbp), %rax
leaq -0x1010(%rcx), %rcx
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq %fs:0x0, %rax
movl -0x40(%rbp), %ecx
leaq -0x145c(%rax), %rax
movl %ecx, (%rax)
callq 0x7fe10
jmp 0x7f881
callq 0x80a30
callq 0x7fe10
jmp 0x7f881
callq 0x80020
movl $0x0, -0x4(%rbp)
jmp 0x7f886
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x80a60
jmp 0x7f881
movl $0x1, %edi
callq 0x80a60
jmp 0x7f881
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movq %rax, -0x68(%rbp)
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movq %rax, -0x70(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movq -0x70(%rbp), %rax
leaq -0x1010(%rcx), %rcx
movslq (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq %fs:0x0, %rax
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rcx
movl -0x58(%rbp), %eax
leaq -0x1010(%rcx), %rcx
subl (%rcx), %eax
movslq %eax, %rdx
callq 0x15950
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq %fs:0x0, %rax
movl -0x54(%rbp), %edx
leaq -0x145c(%rax), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movq %fs:0x0, %rax
leaq -0x1450(%rax), %rax
movq %rax, -0x50(%rbp)
movq %fs:0x0, %rax
movq %rax, %rcx
movq -0x50(%rbp), %rax
leaq -0x145c(%rcx), %rcx
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
callq 0x7fe10
jmp 0x7f881
callq 0x80cd0
jmp 0x7f881
callq 0x80020
callq 0x7e970
callq 0x15260
movl %eax, %edi
movl $0x13, %esi
callq 0x156f0
callq 0x7eec0
callq 0x7fe10
jmp 0x7f881
leaq -0xa(%rbp), %rdi
movl $0x1, %esi
callq 0x7fb00
cmpq $-0x1, %rax
jne 0x7f53f
jmp 0x7f881
movsbl -0xa(%rbp), %eax
cmpl $0x5b, %eax
jne 0x7f7f7
leaq -0xa(%rbp), %rdi
addq $0x1, %rdi
movl $0x1, %esi
callq 0x7fb00
cmpq $-0x1, %rax
jne 0x7f569
jmp 0x7f881
movsbl -0x9(%rbp), %eax
cmpl $0x30, %eax
jl 0x7f698
movsbl -0x9(%rbp), %eax
cmpl $0x39, %eax
jg 0x7f698
leaq -0xa(%rbp), %rdi
addq $0x2, %rdi
movl $0x1, %esi
callq 0x7fb00
cmpq $-0x1, %rax
jne 0x7f5a0
jmp 0x7f881
movsbl -0x8(%rbp), %eax
cmpl $0x7e, %eax
jne 0x7f636
movsbl -0x9(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0x31, %eax
je 0x7f5cf
jmp 0x7f5bb
movl -0x74(%rbp), %eax
subl $0x33, %eax
je 0x7f5ef
jmp 0x7f5c5
movl -0x74(%rbp), %eax
subl $0x34, %eax
je 0x7f5fb
jmp 0x7f632
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
callq 0x7fe10
jmp 0x7f634
movl $0x1, %edi
callq 0x800f0
jmp 0x7f634
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl (%rax), %eax
movl %eax, -0x78(%rbp)
movq %fs:0x0, %rax
movl -0x78(%rbp), %ecx
leaq -0x1010(%rax), %rax
movl %ecx, (%rax)
callq 0x7fe10
jmp 0x7f634
jmp 0x7f634
jmp 0x7f693
movsbl -0x8(%rbp), %eax
cmpl $0x3b, %eax
jne 0x7f691
leaq -0xa(%rbp), %rdi
addq $0x3, %rdi
movl $0x2, %esi
callq 0x7fb00
cmpq $-0x1, %rax
jne 0x7f65c
jmp 0x7f881
movsbl -0x7(%rbp), %eax
cmpl $0x35, %eax
jne 0x7f68f
movsbl -0x6(%rbp), %eax
movl %eax, -0x7c(%rbp)
subl $0x43, %eax
je 0x7f67d
jmp 0x7f673
movl -0x7c(%rbp), %eax
subl $0x44, %eax
je 0x7f684
jmp 0x7f68b
callq 0x80e20
jmp 0x7f68d
callq 0x80fc0
jmp 0x7f68d
jmp 0x7f68d
jmp 0x7f68f
jmp 0x7f691
jmp 0x7f693
jmp 0x7f7f2
movsbl -0xa(%rbp), %eax
cmpl $0x4f, %eax
jne 0x7f73c
leaq -0xa(%rbp), %rdi
addq $0x1, %rdi
movl $0x1, %esi
callq 0x7fb00
cmpq $-0x1, %rax
jne 0x7f6c2
jmp 0x7f881
movsbl -0x9(%rbp), %eax
movl %eax, -0x80(%rbp)
subl $0x46, %eax
je 0x7f6fc
jmp 0x7f6d0
movl -0x80(%rbp), %eax
subl $0x48, %eax
je 0x7f6dc
jmp 0x7f6da
jmp 0x7f737
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
callq 0x7fe10
jmp 0x7f737
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movq %fs:0x0, %rax
movl -0x84(%rbp), %ecx
leaq -0x1010(%rax), %rax
movl %ecx, (%rax)
callq 0x7fe10
jmp 0x7f7f0
movsbl -0x9(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x7, %eax
ja 0x7f768
movq -0x90(%rbp), %rax
leaq 0x57111(%rip), %rcx     # 0xd6870
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x7f7ee
movl $0x1, %edi
callq 0x80a60
jmp 0x7f7ee
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x80a60
jmp 0x7f7ee
callq 0x80250
jmp 0x7f7ee
callq 0x7ffe0
jmp 0x7f7ee
movq %fs:0x0, %rax
leaq -0x1010(%rax), %rax
movl $0x0, (%rax)
callq 0x7fe10
jmp 0x7f7ee
movq %fs:0x0, %rax
leaq -0x145c(%rax), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
movq %fs:0x0, %rax
movl -0x94(%rbp), %ecx
leaq -0x1010(%rax), %rax
movl %ecx, (%rax)
callq 0x7fe10
jmp 0x7f7f0
jmp 0x7f7f2
jmp 0x7f87f
movsbl -0xa(%rbp), %eax
movl %eax, -0x98(%rbp)
subl $0x2c, %eax
je 0x7f860
jmp 0x7f808
movl -0x98(%rbp), %eax
subl $0x2e, %eax
je 0x7f86c
jmp 0x7f815
movl -0x98(%rbp), %eax
subl $0x62, %eax
je 0x7f852
jmp 0x7f822
movl -0x98(%rbp), %eax
subl $0x64, %eax
je 0x7f84b
jmp 0x7f82f
movl -0x98(%rbp), %eax
subl $0x66, %eax
je 0x7f859
jmp 0x7f83c
movl -0x98(%rbp), %eax
subl $0x7f, %eax
je 0x7f878
jmp 0x7f849
jmp 0x7f87d
callq 0x81130
jmp 0x7f87d
callq 0x80fc0
jmp 0x7f87d
callq 0x80e20
jmp 0x7f87d
movl $0x64, %edi
callq 0x80a60
jmp 0x7f87d
movl $0xffffff9c, %edi       # imm = 0xFFFFFF9C
callq 0x80a60
jmp 0x7f87d
callq 0x80cd0
jmp 0x7f87f
jmp 0x7f881
jmp 0x7f167
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)