// File: /workspace/github_cpp_makefile_star2_O2/yaansz[P]just-a-terminal/terminal.cpp
// Function: main
int main(int argc, char **argv) {
    Color::Modifier red(Color::FG_RED);
    Color::Modifier green(Color::FG_GREEN);
    Color::Modifier def(Color::FG_DEFAULT);

    cout << red << "*********************" << def << endl;
    cout << "Terminal initialized" << endl;
    cout << "Welcome " << green << getenv("USER") << def << endl;
    cout << "Type 'help' to know more about this shell" << endl;
    cout << red << "*********************" << def << endl;

    BuiltInCommands bic;
    int exec_return;

    while(1) {
        string command;

        // Input
        cout << green << getenv("USER") << def << ":";
        cout << red << std::filesystem::current_path() << def; 
        cout << ">>>";

        getline(cin, command);
        
        if(command.empty() || blank(command)) continue;

        // Filter
        vector<string> raw_text = split(command, " ");
        vector<char*> pointerVec(raw_text.size() + 1);
        for(unsigned i = 0; i < raw_text.size(); ++i) {
            pointerVec[i] = raw_text[i].data();
        }
        pointerVec[raw_text.size()] = NULL;
        char** args = pointerVec.data();

        exec_return = execute(bic, raw_text[0], args);

        if(exec_return == -1) break;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
leaq -0x38(%rbp), %r15
movl $0x1f, (%r15)
leaq -0x34(%rbp), %r14
movl $0x20, (%r14)
leaq -0x30(%rbp), %r13
movl $0x27, (%r13)
movq 0x4777(%rip), %r12      # 0x6fd0
movq %r12, %rdi
movq %r15, %rsi
callq 0x2d55
leaq 0x17fe(%rip), %rbx      # 0x4069
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x2d55
movq %rax, %rdi
callq 0x20f0
leaq 0x17ef(%rip), %rsi      # 0x407f
movq %r12, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x20f0
leaq 0x17ed(%rip), %rsi      # 0x4094
movq %r12, %rdi
callq 0x2190
movq %rax, %rdi
movq %r14, %rsi
callq 0x2d55
movq %rax, %r14
leaq 0x17d9(%rip), %rdi      # 0x409d
callq 0x2200
movq %r14, %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x2d55
movq %rax, %rdi
callq 0x20f0
leaq 0x17b4(%rip), %rsi      # 0x40a2
movq %r12, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x20f0
movq %r12, %rdi
movq %r15, %rsi
callq 0x2d55
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x2d55
movq %rax, %rdi
callq 0x20f0
leaq -0xc8(%rbp), %rdi
callq 0x243c
leaq -0x98(%rbp), %rbx
leaq -0x70(%rbp), %r13
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
andq $0x0, -0x68(%rbp)
movb $0x0, -0x60(%rbp)
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x2d55
movq %rax, %r15
leaq 0x1738(%rip), %rdi      # 0x409d
callq 0x2200
movq %r15, %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d55
movq %rax, %rdi
leaq 0x1741(%rip), %rsi      # 0x40cc
callq 0x2190
movq %r12, %rdi
leaq -0x38(%rbp), %rsi
callq 0x2d55
movq %rax, %r15
movq %rbx, %rdi
callq 0x2290
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2d89
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d55
movq %rbx, %rdi
callq 0x2de6
movq %r12, %rdi
leaq 0x16fe(%rip), %rsi      # 0x40ce
callq 0x2190
movq 0x4604(%rip), %rdi      # 0x6fe0
movq %r13, %rsi
callq 0x2050
cmpq $0x0, -0x68(%rbp)
je 0x2a19
leaq -0x138(%rbp), %rdi
movq %r13, %rsi
callq 0x2240
leaq -0x138(%rbp), %r14
movq %r14, %rdi
callq 0x2732
movl %eax, %r15d
movq %r14, %rdi
callq 0x20e0
testl %r15d, %r15d
je 0x2a26
movq %r13, %rdi
callq 0x20e0
jmp 0x293e
movq %rbx, %rdi
leaq 0x166b(%rip), %rsi      # 0x409b
leaq -0x29(%rbp), %r14
movq %r14, %rdx
callq 0x2e06
leaq -0x50(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x275b
movq %rbx, %rdi
callq 0x20e0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x5, %rsi
incq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2e42
xorl %eax, %eax
leaq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %r14
movl %eax, %eax
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
cmpq %rax, %rdx
jbe 0x2aad
movq %rax, %rdx
shlq $0x5, %rdx
movq (%rcx,%rdx), %rcx
movq -0x98(%rbp), %rdx
movq %rcx, (%rdx,%rax,8)
incl %eax
jmp 0x2a7d
movq -0x98(%rbp), %rax
andq $0x0, (%rax,%rdx,8)
movq -0x98(%rbp), %r15
leaq -0xc8(%rbp), %rsi
callq 0x3106
movq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x2240
movq %r14, %r12
leaq -0x118(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x264f
movl %eax, %r15d
movq %r12, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x3046
movq %rbx, %rdi
callq 0x3b52
leaq -0x50(%rbp), %rdi
callq 0x2d2a
movq %r13, %rdi
callq 0x20e0
cmpl $-0x1, %r15d
movq 0x44a9(%rip), %r12      # 0x6fd0
jne 0x293e
leaq -0xc8(%rbp), %rdi
callq 0x3046
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bb4
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x20e0
jmp 0x2bb7
movq %rax, %rbx
jmp 0x2b96
movq %rax, %rbx
jmp 0x2b8a
movq %rax, %rbx
jmp 0x2b7e
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x20e0
leaq -0x118(%rbp), %rdi
callq 0x3046
leaq -0x98(%rbp), %rdi
callq 0x3b52
leaq -0x50(%rbp), %rdi
callq 0x2d2a
jmp 0x2bb7
jmp 0x2bb4
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x2de6
jmp 0x2bb7
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20e0
leaq -0xc8(%rbp), %rdi
callq 0x3046
movq %rbx, %rdi
callq 0x22d0