// File: /workspace/github_cpp_makefile_star2_O2/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 0x22ed(%rip), %rsi      # 0x504b
leaq -0x238(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x32e6
leaq 0x54d3(%rip), %rdi      # 0x8248
leaq -0x238(%rbp), %rsi
callq 0x338c
leaq 0x1408(%rip), %rcx      # 0x4190
movq %rcx, (%rax)
leaq -0x238(%rbp), %rdi
callq 0x20f0
leaq 0x22a5(%rip), %rsi      # 0x5043
leaq -0x238(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x32e6
leaq 0x5493(%rip), %rdi      # 0x8248
leaq -0x238(%rbp), %rsi
callq 0x338c
leaq 0x160f(%rip), %rcx      # 0x43d7
movq %rcx, (%rax)
leaq -0x238(%rbp), %rbx
movq %rbx, %rdi
callq 0x20f0
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movb $0x27, (%rbx)
leaq 0x5484(%rip), %rdi      # 0x8278
leaq -0x238(%rbp), %rsi
callq 0x3e50
leaq -0x238(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5467(%rip), %rdi      # 0x8278
callq 0x3e50
leaq -0x238(%rbp), %rsi
movb $0x5c, (%rsi)
leaq 0x5481(%rip), %rdi      # 0x82a8
callq 0x3e50
leaq -0x238(%rbp), %rsi
movb $0x27, (%rsi)
leaq 0x546b(%rip), %rdi      # 0x82a8
callq 0x3e50
leaq -0x238(%rbp), %rsi
movb $0x22, (%rsi)
leaq 0x5455(%rip), %rdi      # 0x82a8
callq 0x3e50
leaq -0xa0(%rbp), %r12
leaq -0x48(%rbp), %r13
leaq -0x278(%rbp), %r15
leaq -0x298(%rbp), %r14
cmpb $0x1, 0x53a0(%rip)      # 0x8218
jne 0x30b9
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5456(%rip), %rbx      # 0x82e0
movq %rbx, %rdi
callq 0x2120
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
andq $0x0, -0x70(%rbp)
movq 0x5123(%rip), %rdi      # 0x7fc8
movq %rbx, %rsi
callq 0x21e0
movq %rax, %rdi
leaq 0x2197(%rip), %rsi      # 0x504e
callq 0x21e0
movq 0x511d(%rip), %rdi      # 0x7fe0
leaq -0x68(%rbp), %rsi
callq 0x2080
movq 0x510d(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x20(%rcx,%rax)
je 0x2ee8
movb $0x0, 0x5330(%rip)      # 0x8218
leaq -0x238(%rbp), %rdi
leaq -0x68(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x2390
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
andq $0x0, -0x98(%rbp)
movb $0x0, -0x90(%rbp)
leaq -0x238(%rbp), %rdi
movq %r12, %rsi
callq 0x2290
movq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x2bff
movl %eax, %ebx
testb %bl, %bl
je 0x3019
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x218(%rbp,%rax)
je 0x2fa3
movq 0x506d(%rip), %rdi      # 0x7fc8
leaq 0x20ec(%rip), %rsi      # 0x504e
callq 0x21e0
movq 0x5072(%rip), %rdi      # 0x7fe0
leaq -0x68(%rbp), %rsi
callq 0x2080
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x238(%rbp), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x23a0
leaq -0x228(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2320
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
leaq -0x238(%rbp), %rdi
movq %r13, %rsi
callq 0x2290
movq -0x48(%rbp), %rdi
movsbl %bl, %esi
callq 0x2bff
movl %eax, %ebx
movq %r15, %rdi
movq %r12, %rsi
leaq 0x2071(%rip), %rdx      # 0x504f
callq 0x341e
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x33f5
movq %r12, %rdi
movq %r14, %rsi
callq 0x2270
movq %r14, %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
jmp 0x2f37
leaq -0x258(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x22c0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2c7f
movq %rbx, %rdi
callq 0x20f0
cmpq $0x0, -0x40(%rbp)
je 0x3051
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
callq 0x3456
movq %r13, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x218(%rbp,%rax)
leaq -0xb8(%rbp), %rbx
je 0x2efb
movq %rbx, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3210
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26ec
movq %rbx, %rdi
callq 0x3264
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x80(%rbp), %rdi
callq 0x3264
jmp 0x2e71
leaq -0x68(%rbp), %rdi
callq 0x20f0
xorl %eax, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x30de
jmp 0x30de
jmp 0x30de
jmp 0x30de
movq %rax, %rbx
jmp 0x3171
jmp 0x30ea
jmp 0x30f6
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
jmp 0x3175
movq %rax, %rbx
jmp 0x317a
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3264
jmp 0x315c
movq %rax, %rbx
jmp 0x315c
jmp 0x3113
movq %rax, %rbx
jmp 0x3168
jmp 0x313f
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
jmp 0x3146
jmp 0x314d
jmp 0x314d
jmp 0x314d
jmp 0x313f
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x20f0
jmp 0x3142
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20f0
jmp 0x3150
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x20f0
leaq -0x238(%rbp), %rdi
callq 0x2100
leaq -0x80(%rbp), %rdi
callq 0x3264
leaq -0x68(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x23b0