// File: /workspace/github_cpp_makefile_star2_O1/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), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x2224(%rip), %rsi      # 0x504b
leaq 0x221f(%rip), %rdx      # 0x504d
leaq -0x298(%rbp), %rdi
callq 0x3f3a
leaq 0x5407(%rip), %rdi      # 0x8248
leaq -0x298(%rbp), %rsi
callq 0x3736
leaq 0x15cc(%rip), %rcx      # 0x4420
movq %rcx, (%rax)
movq -0x298(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2e72
movq -0x288(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x298(%rbp), %rdi
movq %rbx, (%rdi)
leaq 0x21c0(%rip), %rsi      # 0x5043
leaq 0x21bb(%rip), %rdx      # 0x5045
callq 0x3f3a
leaq 0x53b2(%rip), %rdi      # 0x8248
leaq -0x298(%rbp), %rsi
callq 0x3736
leaq 0x1839(%rip), %rcx      # 0x46e2
movq %rcx, (%rax)
movq -0x298(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2ec7
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 0x538d(%rip), %rdi      # 0x8278
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5377(%rip), %rdi      # 0x8278
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x5c, (%rsi)
leaq 0x5391(%rip), %rdi      # 0x82a8
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x27, (%rsi)
leaq 0x537b(%rip), %rdi      # 0x82a8
callq 0x40c6
leaq -0x298(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5365(%rip), %rdi      # 0x82a8
callq 0x40c6
cmpb $0x1, 0x52c9(%rip)      # 0x8218
jne 0x3330
leaq -0x98(%rbp), %rbx
leaq -0xd0(%rbp), %r14
leaq -0x48(%rbp), %r12
leaq -0xa8(%rbp), %r15
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5366(%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 0x5022(%rip), %rdi      # 0x7fc8
movq %r13, %rsi
movq %rax, %rdx
callq 0x2230
movl $0x2, %edx
movq 0x500b(%rip), %rdi      # 0x7fc8
leaq 0x208a(%rip), %rsi      # 0x504e
callq 0x2230
movq 0x5010(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %edx
movq 0x4ff2(%rip), %rdi      # 0x7fe0
leaq -0x88(%rbp), %rsi
callq 0x23c0
movq 0x4fdf(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
je 0x3016
movb $0x0, 0x5202(%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 0x2c81
movl %eax, %r13d
testb %r13b, %r13b
je 0x3214
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x278(%rbp,%rax)
je 0x30f6
movl $0x2, %edx
movq 0x4f3e(%rip), %rdi      # 0x7fc8
leaq 0x1fbd(%rip), %rsi      # 0x504e
callq 0x2230
movq 0x4f43(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %edx
movq 0x4f25(%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 0x2c81
movl %eax, %r13d
movq %rbx, -0xa8(%rbp)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x38fe
movq %r15, %rdi
leaq 0x1f02(%rip), %rsi      # 0x504f
callq 0x23e0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r15, %rdi
callq 0x20b0
movq %r14, -0xe0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x318b
movq %rdx, -0xe0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xd0(%rbp)
jmp 0x3192
movups (%rcx), %xmm0
movups %xmm0, (%r14)
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 %r14, %rdi
je 0x31d7
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x31f2
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3060
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x3060
movq %r12, %rbx
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 0x38fe
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2d06
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
je 0x3265
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2200
cmpq $0x0, -0x40(%rbp)
movq %rbx, %r12
leaq -0x118(%rbp), %r13
je 0x3285
leaq -0xc0(%rbp), %rdi
movq %r12, %rsi
callq 0x37b6
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x329e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
leaq -0x98(%rbp), %rbx
je 0x32be
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x298(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x278(%rbp,%rax)
je 0x302e
movq %r13, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3522
movq %r13, %rdi
xorl %esi, %esi
callq 0x279c
movq %r13, %rdi
callq 0x35b6
leaq -0x298(%rbp), %rdi
movq 0x4cba(%rip), %rsi      # 0x7fc0
callq 0x22d0
leaq -0x220(%rbp), %rdi
callq 0x20c0
leaq -0xc0(%rbp), %rdi
callq 0x35b6
cmpb $0x0, 0x4eee(%rip)      # 0x8218
jne 0x2f6e
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x334c
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 0x3368
jmp 0x3368
jmp 0x3368
jmp 0x3368
movq %rax, %r15
jmp 0x346a
jmp 0x3374
jmp 0x3393
movq %rax, %r15
movq -0x298(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3486
movq -0x288(%rbp), %rsi
jmp 0x347e
movq %rax, %r15
jmp 0x3486
movq %rax, %r15
leaq -0x118(%rbp), %rdi
callq 0x35b6
jmp 0x343f
movq %rax, %r15
jmp 0x343f
jmp 0x33b9
movq %rax, %r15
jmp 0x345e
jmp 0x3405
movq %rax, %r15
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
je 0x3426
movq -0xf0(%rbp), %rsi
jmp 0x3419
jmp 0x3423
jmp 0x3423
jmp 0x3423
jmp 0x33e3
movq %rax, %r15
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3408
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x3408
jmp 0x3405
movq %rax, %r15
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3426
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x3426
movq %rax, %r15
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x343f
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq 0x4b7a(%rip), %rsi      # 0x7fc0
leaq -0x298(%rbp), %rdi
callq 0x22d0
leaq -0x220(%rbp), %rdi
callq 0x20c0
leaq -0xc0(%rbp), %rdi
callq 0x35b6
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3486
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq %r15, %rdi
callq 0x23a0