// File: /workspace/github_cpp_makefile_star2_O1/phillip-h[P]todo/src/typer.cpp
// Function: type(Win*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string type(Win *win, unsigned size, string base)
{
    char* buf = new char[size];
    for (unsigned i = 0; i < size; i++)
        buf[i] = i < base.size() ? base.at(i) : 0;
    unsigned pos = base.size();
   
    curs_set(1);

    int in;
    bool typing = true;
    while(typing){

        win->clear();
        win->print(string(buf));
        win->color(BORDER_COLOR_PAIR, true);       
        win->draw();
        
        switch(in = getch()){
            case 27: // ESCAPE
                curs_set(0);
                return base;
            case '\n':
                typing = false;
                break;
            case KEY_BACKSPACE:
                if (pos)
                    pos--;
                buf[pos] = 0;
                break;
            default:
                buf[pos] = in;
                if (pos < size)
                    pos++;
                break;
        }
    }
    
    curs_set(0);

    string ret(buf);
    delete[] buf;
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
movl %edx, %r13d
movq %r13, %rdi
callq 0x3030
movq %rax, %r15
movl %ebp, 0x4(%rsp)
testl %ebp, %ebp
je 0xb49c
movq 0x8(%r14), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
jbe 0xb48e
movq (%r14), %rdx
movb (%rdx,%rcx), %dl
jmp 0xb490
xorl %edx, %edx
movb %dl, (%r15,%rcx)
incq %rcx
cmpq %rcx, %r13
jne 0xb481
movq %rbx, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl 0x8(%r14), %ebx
movl $0x1, %edi
callq 0x3240
movb $0x1, %r14b
leaq 0x28(%rsp), %rbp
leaq 0x18(%rsp), %r13
movq %r12, %rdi
callq 0xb71e
movq %rbp, 0x18(%rsp)
movq %r15, %rdi
callq 0x3170
leaq (%rax,%r15), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x5d4c
movq %r12, %rdi
movq %r13, %rsi
callq 0xb8ae
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0xb507
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %r12, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0xb8ce
movq %r12, %rdi
callq 0xb734
movq 0x4aa0(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x3140
cmpl $0xa, %eax
je 0xb562
cmpl $0x107, %eax            # imm = 0x107
je 0xb550
cmpl $0x1b, %eax
je 0xb5a5
movl %ebx, %ecx
movb %al, (%r15,%rcx)
cmpl 0x4(%rsp), %ebx
adcl $0x0, %ebx
jmp 0xb565
subl $0x1, %ebx
movl $0x0, %eax
cmovbl %eax, %ebx
movb $0x0, (%r15,%rbx)
jmp 0xb565
xorl %r14d, %r14d
testb $0x1, %r14b
jne 0xb4c1
xorl %edi, %edi
callq 0x3240
movq 0x8(%rsp), %rbx
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq %r15, %rdi
callq 0x3170
movq %r15, %rdx
addq %rax, %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5d4c
movq %r15, %rdi
callq 0x3390
jmp 0xb5f2
xorl %edi, %edi
callq 0x3240
movq 0x8(%rsp), %rbx
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
movq 0x10(%rsp), %rsi
movq (%rsi), %rdx
leaq 0x10(%rsi), %rax
cmpq %rax, %rdx
je 0xb5d5
movq %rdx, (%rbx)
movq (%rax), %rcx
movq %rcx, 0x10(%rbx)
jmp 0xb5db
movups (%rax), %xmm0
movups %xmm0, (%rcx)
movq 0x8(%rsi), %rcx
movq %rcx, 0x8(%rbx)
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
movb $0x0, 0x10(%rsi)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0xb61e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3500
nop