// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movl %edx, %r13d
movq %r13, %rdi
callq 0x3030
movq %rax, %r15
movq 0x8(%r14), %rbx
movl %ebp, 0x4(%rsp)
testl %ebp, %ebp
je 0xb2fe
xorl %eax, %eax
cmpq %rax, %rbx
jbe 0xb2f0
movq (%r14), %rcx
movb (%rcx,%rax), %cl
jmp 0xb2f2
xorl %ecx, %ecx
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r13
jne 0xb2e3
movq %r14, 0x10(%rsp)
movl $0x1, %edi
callq 0x3240
leaq 0x28(%rsp), %r14
leaq 0x18(%rsp), %r13
movq 0x4caa(%rip), %rbp      # 0xffc8
movq %r12, %rdi
callq 0xb56e
movq %r14, 0x18(%rsp)
movq %r15, %rdi
callq 0x3170
leaq (%rax,%r15), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x5c8a
movq %r12, %rdi
movq %r13, %rsi
callq 0xb6fe
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0xb364
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %r12, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0xb71e
movq %r12, %rdi
callq 0xb584
movq (%rbp), %rdi
callq 0x3140
cmpl $0x107, %eax            # imm = 0x107
je 0xb3aa
cmpl $0xa, %eax
je 0xb3bf
cmpl $0x1b, %eax
je 0xb3f5
movl %ebx, %ecx
movb %al, (%r15,%rcx)
cmpl 0x4(%rsp), %ebx
adcl $0x0, %ebx
jmp 0xb31e
subl $0x1, %ebx
movl $0x0, %eax
cmovbl %eax, %ebx
movb $0x0, (%r15,%rbx)
jmp 0xb31e
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 0x5c8a
movq %r15, %rdi
callq 0x3390
jmp 0xb442
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 0xb425
movq %rdx, (%rbx)
movq (%rax), %rcx
movq %rcx, 0x10(%rbx)
jmp 0xb42b
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 %r14, %rdi
je 0xb46e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3500
nop