// File: /workspace/github_cpp_makefile_star2_O1/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 -0x34(%rbp), %rsi
movl $0x1f, (%rsi)
leaq -0x38(%rbp), %r14
movl $0x20, (%r14)
leaq -0x2c(%rbp), %r15
movl $0x27, (%r15)
movq 0x5572(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
callq 0x32f8
movq %rax, %r12
leaq 0x2615(%rip), %rsi      # 0x5085
movl $0x15, %edx
movq %rax, %rdi
callq 0x21f0
movq %r12, %rdi
movq %r15, %rsi
callq 0x32f8
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x25e2(%rip), %rsi      # 0x509b
movl $0x14, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x25bc(%rip), %rsi      # 0x50b0
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21f0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32f8
movq %rax, %r15
leaq 0x25a3(%rip), %rdi      # 0x50b9
callq 0x2210
testq %rax, %rax
je 0x2b3b
movq %rax, %r14
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x2b55
movq (%r15), %rax
movq -0x18(%rax), %rax
movq %r15, %rdi
addq %rax, %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x22b0
leaq -0x2c(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x32f8
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x2529(%rip), %rsi      # 0x50be
movl $0x29, %edx
movq 0x542f(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq -0x34(%rbp), %rsi
movq %rbx, %rdi
callq 0x32f8
movq %rax, %r14
leaq 0x249f(%rip), %rsi      # 0x5085
movl $0x15, %edx
movq %rax, %rdi
callq 0x21f0
movq %r14, %rdi
movq %r12, %rsi
callq 0x32f8
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq -0x108(%rbp), %rdi
callq 0x24ac
leaq -0x88(%rbp), %r12
leaq -0xb8(%rbp), %r13
movq %r12, %rbx
movq %r12, -0x98(%rbp)
movq $0x0, -0x90(%rbp)
movb $0x0, -0x88(%rbp)
movq 0x536b(%rip), %rdi      # 0x7fd0
leaq -0x38(%rbp), %rsi
callq 0x32f8
movq %rax, %r12
leaq 0x2441(%rip), %rdi      # 0x50b9
callq 0x2210
testq %rax, %rax
je 0x2c9d
movq %rax, %r14
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x2cb8
movq (%r12), %rax
movq -0x18(%rax), %rax
movq %r12, %rdi
addq %rax, %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x22b0
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x32f8
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2415(%rip), %rsi      # 0x50e8
callq 0x21f0
movq 0x52f1(%rip), %rdi      # 0x7fd0
leaq -0x34(%rbp), %rsi
callq 0x32f8
movq %rax, %r12
leaq -0x60(%rbp), %r14
movq %r14, %rdi
callq 0x2280
movq %r12, %rdi
movq %r14, %rsi
callq 0x333f
movq %rax, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x32f8
movq %r14, %rdi
callq 0x33c8
movl $0x3, %edx
movq 0x52ae(%rip), %rdi      # 0x7fd0
leaq 0x23c1(%rip), %rsi      # 0x50ea
callq 0x21f0
movq 0x52ab(%rip), %rcx      # 0x7fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %edx
movq 0x528d(%rip), %rdi      # 0x7fe0
leaq -0x98(%rbp), %rsi
callq 0x2300
movq -0x90(%rbp), %r14
testq %r14, %r14
je 0x2dcc
leaq -0xc8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rsi
leaq (%rsi,%r14), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x38f4
movq -0xd0(%rbp), %rax
testq %rax, %rax
sete %r12b
je 0x2dcf
movq -0xd8(%rbp), %rcx
cmpb $0x20, (%rcx)
jne 0x2dcf
movl $0x1, %esi
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x2dc3
leaq 0x1(%rdx), %rsi
cmpb $0x20, (%rcx,%rdx)
je 0x2db1
cmpq %rdx, %rax
setbe %r12b
jmp 0x2dcf
movb $0x1, %r12b
testq %r14, %r14
je 0x2df6
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x2df6
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r12b, %r12b
je 0x2e03
xorl %r14d, %r14d
jmp 0x2f5c
leaq -0x50(%rbp), %r14
movq %r14, -0x60(%rbp)
leaq -0x60(%rbp), %r15
movq %r15, %rdi
leaq 0x229e(%rip), %rsi      # 0x50b7
leaq 0x2298(%rip), %rdx      # 0x50b8
callq 0x398e
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movq %r15, %rdx
callq 0x293a
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x2e4d
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x70(%rbp), %rsi
subq -0x78(%rbp), %rsi
sarq $0x5, %rsi
incq %rsi
leaq -0x60(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
callq 0x3410
leaq -0x138(%rbp), %r14
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rsi
subq %rax, %rsi
je 0x2eb1
movl $0x1, %ecx
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x5, %rsi
movq (%rax,%rsi), %rax
movq -0x60(%rbp), %rsi
movq %rax, (%rsi,%rdx,8)
movl %ecx, %edx
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rsi
subq %rax, %rsi
sarq $0x5, %rsi
incl %ecx
cmpq %rdx, %rsi
ja 0x2e84
jmp 0x2eb5
sarq $0x5, %rsi
movq -0x60(%rbp), %rax
movq $0x0, (%rax,%rsi,8)
movq -0x60(%rbp), %r12
movq %r14, %rdi
leaq -0x108(%rbp), %rsi
callq 0x361e
movq -0x78(%rbp), %rax
leaq -0xa8(%rbp), %rcx
movq %rcx, -0xb8(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r13, %r15
movq %r13, %rdi
callq 0x38f4
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x27ea
movl %eax, %r12d
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2f2e
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x3568
cmpl $-0x1, %r12d
sete %r14b
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x2f53
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x21c0
leaq -0x78(%rbp), %rdi
callq 0x328e
movq %rbx, %r12
movq -0x98(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2f7a
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x21c0
testb %r14b, %r14b
je 0x2c42
leaq -0x108(%rbp), %rdi
callq 0x3568
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3035
movq %rax, %r14
jmp 0x301a
movq %rax, %r14
jmp 0x2ff9
movq %r14, %rcx
movq %rax, %r14
movq -0x60(%rbp), %rdi
cmpq %rcx, %rdi
je 0x3038
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3038
movq %rax, %r14
jmp 0x3005
movq %rax, %r14
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2ff9
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x138(%rbp), %rdi
callq 0x3568
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x301a
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x21c0
leaq -0x78(%rbp), %rdi
callq 0x328e
jmp 0x3038
jmp 0x3035
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x33c8
jmp 0x3038
movq %rax, %r14
movq -0x98(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3053
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x108(%rbp), %rdi
callq 0x3568
movq %r14, %rdi
callq 0x22e0
nop