// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rcx, -0x88(%rbp)
movq %rdi, -0x80(%rbp)
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edi
callq 0x4030
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x11731
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %eax
movq %rax, -0x90(%rbp)
callq 0x4270
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x1170a
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x46e0
movsbl (%rax), %eax
movl %eax, -0x94(%rbp)
jmp 0x11714
xorl %eax, %eax
movl %eax, -0x94(%rbp)
jmp 0x11714
movl -0x94(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x116c1
movq -0x88(%rbp), %rdi
callq 0x4270
movl %eax, -0x30(%rbp)
movl $0x1, %edi
callq 0x42d0
movb $0x1, -0x35(%rbp)
testb $0x1, -0x35(%rbp)
je 0x118b3
movq -0x10(%rbp), %rdi
callq 0x11ad0
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x4690
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x85c0
jmp 0x117a0
movq -0xb0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x11cf0
jmp 0x117b2
leaq -0x58(%rbp), %rdi
callq 0x4738
leaq -0x59(%rbp), %rdi
callq 0x43d0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x11d90
movq -0x10(%rbp), %rdi
callq 0x11b00
movq 0x67d9(%rip), %rax      # 0x17fc0
movq (%rax), %rdi
callq 0x4170
movl %eax, -0x34(%rbp)
movl %eax, %ecx
movl %ecx, -0xb4(%rbp)
subl $0xa, %eax
je 0x1186a
jmp 0x11801
movl -0xb4(%rbp), %eax
subl $0x1b, %eax
je 0x1184e
jmp 0x1180e
movl -0xb4(%rbp), %eax
subl $0x107, %eax            # imm = 0x107
je 0x11870
jmp 0x1188c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x11840
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4738
leaq -0x59(%rbp), %rdi
callq 0x43d0
jmp 0x11953
xorl %edi, %edi
callq 0x42d0
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x4230
jmp 0x11946
movb $0x0, -0x35(%rbp)
jmp 0x118ae
cmpl $0x0, -0x30(%rbp)
je 0x1187f
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x118ae
movl -0x34(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x118ac
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x118ae
jmp 0x1174e
xorl %edi, %edi
callq 0x42d0
movb $0x0, -0x6d(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x6e(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x4690
movq -0x80(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0x85c0
jmp 0x118f2
leaq -0x6e(%rbp), %rdi
callq 0x43d0
movq -0x28(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x11918
movq -0xd0(%rbp), %rdi
callq 0x44d0
movb $0x1, -0x6d(%rbp)
testb $0x1, -0x6d(%rbp)
jne 0x11944
jmp 0x1193b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x6e(%rbp), %rdi
callq 0x43d0
jmp 0x11953
movq -0x80(%rbp), %rdi
callq 0x4738
jmp 0x11946
movq -0x78(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x4680
nopl (%rax)