// File: /workspace/github_cpp_makefile_star2_O3/clementino1971[P]ICC065-protoTerminal/protoTerminal.cpp
// Function: main
int main(int argc, char *argv[]){

    //Define Functions here	
    mapa["ls"] = &ls;
    mapa["cd"] = &cd;

    //Strings
    string currCommand;

    //Defining delimiters
    possible_delimiters.insert('\'');
    possible_delimiters.insert('"');

    //Defining escapable special characters
    special_characters.insert('\\');
    special_characters.insert('\'');
    special_characters.insert('"');


    while(TERMINAL){

        //Get current dir
        getcwd(dir,sizeof(dir));

        //Vector to store the words in a command
        vector<string> command;

        //A print because is nice
        cout << dir << "> ";

        // Readind the command and put the words in vector
        getline(cin, currCommand);
        if(cin.eof()) TERMINAL=false;
        istringstream ss(currCommand);

        do {
            string word;
            ss >> word;
            char delimiter=balance(word.c_str());
            while(delimiter) {
                if(!ss) {
                    cout << "> ";
                    getline(cin,currCommand);
                    ss.clear();
                    ss.str(currCommand);
                } 
                string next_word;
                ss >> next_word;
                delimiter=balance(next_word.c_str(),delimiter);
                word=word+" "+next_word;
            }
            string new_word = clean_backwards(word);
            if(!new_word.empty())command.push_back(new_word);
        } while(ss);

        //Call the function that treat the string and run the command
        recursive_run(command);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
leaq -0x288(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x2222(%rip), %rsi      # 0x504b
leaq 0x221d(%rip), %rdx      # 0x504d
leaq -0x298(%rbp), %rdi
callq 0x3f36
leaq 0x5405(%rip), %rdi      # 0x8248
leaq -0x298(%rbp), %rsi
callq 0x3738
leaq 0x1596(%rip), %rcx      # 0x43ec
movq %rcx, (%rax)
movq -0x298(%rbp), %rdi
cmpq %r14, %rdi
je 0x2e74
movq -0x288(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x298(%rbp), %rdi
movq %r14, (%rdi)
leaq 0x21be(%rip), %rsi      # 0x5043
leaq 0x21b9(%rip), %rdx      # 0x5045
callq 0x3f36
leaq 0x53b0(%rip), %rdi      # 0x8248
leaq -0x298(%rbp), %rsi
callq 0x3738
leaq 0x17fa(%rip), %rcx      # 0x46a5
movq %rcx, (%rax)
movq -0x298(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ec9
movq -0x288(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x298(%rbp), %rsi
movb $0x27, (%rsi)
leaq 0x538b(%rip), %rdi      # 0x8278
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5375(%rip), %rdi      # 0x8278
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x5c, (%rsi)
leaq 0x538f(%rip), %rdi      # 0x82a8
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x27, (%rsi)
leaq 0x5379(%rip), %rdi      # 0x82a8
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5363(%rip), %rdi      # 0x82a8
callq 0x40c6
cmpb $0x1, 0x52c7(%rip)      # 0x8218
jne 0x3332
leaq -0x98(%rbp), %r14
leaq -0xd0(%rbp), %r15
leaq -0x48(%rbp), %r12
leaq -0xa8(%rbp), %rbx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5364(%rip), %r13      # 0x82e0
movq %r13, %rdi
callq 0x2110
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movq $0x0, -0xb0(%rbp)
movq %r13, %rdi
callq 0x20f0
movq 0x5020(%rip), %rdi      # 0x7fc8
movq %r13, %rsi
movq %rax, %rdx
callq 0x2230
movl $0x2, %edx
movq 0x5009(%rip), %rdi      # 0x7fc8
leaq 0x2088(%rip), %rsi      # 0x504e
callq 0x2230
movq 0x500e(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %edx
movq 0x4ff0(%rip), %rdi      # 0x7fe0
leaq -0x88(%rbp), %rsi
callq 0x23c0
movq 0x4fdd(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
je 0x3018
movb $0x0, 0x5200(%rip)      # 0x8218
leaq -0x298(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x8, %edx
callq 0x2380
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2290
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x2c86
movl %eax, %r13d
testb %r13b, %r13b
je 0x3216
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x278(%rbp,%rax)
je 0x30f8
movl $0x2, %edx
movq 0x4f3c(%rip), %rdi      # 0x7fc8
leaq 0x1fbb(%rip), %rsi      # 0x504e
callq 0x2230
movq 0x4f41(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %edx
movq 0x4f23(%rip), %rdi      # 0x7fe0
leaq -0x88(%rbp), %rsi
callq 0x23c0
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x298(%rbp), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x2390
leaq -0x288(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2310
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
leaq -0x298(%rbp), %rdi
movq %r12, %rsi
callq 0x2290
movq -0x48(%rbp), %rdi
movsbl %r13b, %esi
callq 0x2c86
movl %eax, %r13d
movq %r14, -0xa8(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3900
movq %rbx, %rdi
leaq 0x1f00(%rip), %rsi      # 0x504f
callq 0x23e0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x20b0
movq %r15, -0xe0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x318d
movq %rdx, -0xe0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xd0(%rbp)
jmp 0x3194
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, -0xd8(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x68(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2270
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x31d9
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x31f4
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3062
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x3062
movq %r12, %r14
leaq -0xf0(%rbp), %r13
movq %r13, -0x100(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %r12
movq %r12, %rdi
callq 0x3900
movq %r14, %rdi
movq %r12, %rsi
callq 0x2d0b
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
je 0x3267
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2200
cmpq $0x0, -0x40(%rbp)
movq %r14, %r12
leaq -0x118(%rbp), %r13
je 0x3287
leaq -0xc0(%rbp), %rdi
movq %r12, %rsi
callq 0x37b8
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x32a0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
leaq -0x98(%rbp), %r14
je 0x32c0
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x278(%rbp,%rax)
je 0x3030
movq %r13, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3524
movq %r13, %rdi
xorl %esi, %esi
callq 0x279c
movq %r13, %rdi
callq 0x35b8
leaq -0x298(%rbp), %rdi
movq 0x4cb8(%rip), %rsi      # 0x7fc0
callq 0x22d0
leaq -0x220(%rbp), %rdi
callq 0x20c0
leaq -0xc0(%rbp), %rdi
callq 0x35b8
cmpb $0x0, 0x4eec(%rip)      # 0x8218
jne 0x2f70
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x334e
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x336a
jmp 0x336a
jmp 0x336a
jmp 0x336a
movq %rax, %rbx
jmp 0x346c
jmp 0x3376
jmp 0x3395
movq %rax, %rbx
movq -0x298(%rbp), %rdi
cmpq %r14, %rdi
je 0x3488
movq -0x288(%rbp), %rsi
jmp 0x3480
movq %rax, %rbx
jmp 0x3488
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x35b8
jmp 0x3441
movq %rax, %rbx
jmp 0x3441
jmp 0x33bb
movq %rax, %rbx
jmp 0x3460
jmp 0x3407
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
je 0x3428
movq -0xf0(%rbp), %rsi
jmp 0x341b
jmp 0x3425
jmp 0x3425
jmp 0x3425
jmp 0x33e5
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x340a
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x340a
jmp 0x3407
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3428
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x3428
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3441
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq 0x4b78(%rip), %rsi      # 0x7fc0
leaq -0x298(%rbp), %rdi
callq 0x22d0
leaq -0x220(%rbp), %rdi
callq 0x20c0
leaq -0xc0(%rbp), %rdi
callq 0x35b8
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3488
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x23a0