// File: 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
subq $0x200, %rsp            # imm = 0x200
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x14(%rbp), %rdi
movl $0x1f, %esi
callq 0x48d0
leaq -0x18(%rbp), %rdi
movl $0x20, %esi
callq 0x48d0
leaq -0x1c(%rbp), %rdi
movl $0x27, %esi
callq 0x48d0
movq 0xa246(%rip), %rdi      # 0xdfd0
leaq -0x14(%rbp), %rsi
callq 0x48f0
movq %rax, %rdi
leaq 0x52cc(%rip), %rsi      # 0x9069
callq 0x3210
movq %rax, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x48f0
movq %rax, %rdi
movq 0xa200(%rip), %rsi      # 0xdfb8
callq 0x3270
movq 0xa20c(%rip), %rdi      # 0xdfd0
leaq 0x52b4(%rip), %rsi      # 0x907f
callq 0x3210
movq %rax, %rdi
movq 0xa1de(%rip), %rsi      # 0xdfb8
callq 0x3270
movq 0xa1ea(%rip), %rdi      # 0xdfd0
leaq 0x52a7(%rip), %rsi      # 0x9094
callq 0x3210
movq %rax, %rdi
leaq -0x18(%rbp), %rsi
callq 0x48f0
movq %rax, -0x198(%rbp)
leaq 0x5291(%rip), %rdi      # 0x909d
callq 0x32f0
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x3210
movq %rax, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x48f0
movq %rax, %rdi
movq 0xa182(%rip), %rsi      # 0xdfb8
callq 0x3270
movq 0xa18e(%rip), %rdi      # 0xdfd0
leaq 0x5259(%rip), %rsi      # 0x90a2
callq 0x3210
movq %rax, %rdi
movq 0xa160(%rip), %rsi      # 0xdfb8
callq 0x3270
movq 0xa16c(%rip), %rdi      # 0xdfd0
leaq -0x14(%rbp), %rsi
callq 0x48f0
movq %rax, %rdi
leaq 0x51f2(%rip), %rsi      # 0x9069
callq 0x3210
movq %rax, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x48f0
movq %rax, %rdi
movq 0xa126(%rip), %rsi      # 0xdfb8
callq 0x3270
leaq -0x50(%rbp), %rdi
callq 0x3570
jmp 0x3ea2
leaq -0x78(%rbp), %rdi
callq 0x3330
movq 0xa11e(%rip), %rdi      # 0xdfd0
leaq -0x18(%rbp), %rsi
callq 0x48f0
movq %rax, -0x1a0(%rbp)
jmp 0x3ec4
leaq 0x51d2(%rip), %rdi      # 0x909d
callq 0x32f0
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0x3210
movq %rax, -0x1a8(%rbp)
jmp 0x3ee8
movq -0x1a8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x48f0
movq %rax, -0x1b0(%rbp)
jmp 0x3f01
movq -0x1b0(%rbp), %rdi
leaq 0x51bd(%rip), %rsi      # 0x90cc
callq 0x3210
jmp 0x3f16
movq 0xa0b3(%rip), %rdi      # 0xdfd0
leaq -0x14(%rbp), %rsi
callq 0x48f0
movq %rax, -0x1b8(%rbp)
jmp 0x3f2f
leaq -0xb0(%rbp), %rdi
callq 0x3390
jmp 0x3f3d
movq -0x1b8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4940
movq %rax, -0x1c0(%rbp)
jmp 0x3f59
movq -0x1c0(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x48f0
jmp 0x3f6b
leaq -0xb0(%rbp), %rdi
callq 0x4a30
movq 0xa052(%rip), %rdi      # 0xdfd0
leaq 0x5149(%rip), %rsi      # 0x90ce
callq 0x3210
jmp 0x3f8c
movq 0xa04d(%rip), %rdi      # 0xdfe0
leaq -0x78(%rbp), %rsi
callq 0x3060
jmp 0x3f9e
leaq -0x78(%rbp), %rdi
callq 0x33b0
movb %al, %cl
movb $0x0, -0xd1(%rbp)
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x1c1(%rbp)
jne 0x3fee
leaq -0xd0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x30f0
jmp 0x3fcf
movb $0x1, -0xd1(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3b40
cmpl $0x0, %eax
setne %al
movb %al, -0x1c1(%rbp)
movb -0x1c1(%rbp), %al
movb %al, -0x1c2(%rbp)
testb $0x1, -0xd1(%rbp)
jne 0x4005
jmp 0x4011
leaq -0xd0(%rbp), %rdi
callq 0x3150
movb -0x1c2(%rbp), %al
testb $0x1, %al
jne 0x401d
jmp 0x4060
movl $0x2, -0xd8(%rbp)
jmp 0x432a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x4375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4a30
jmp 0x4375
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x33e0
movq -0x1d0(%rbp), %rdx
leaq 0x501a(%rip), %rsi      # 0x909b
leaq -0x110(%rbp), %rdi
callq 0x4a60
jmp 0x408f
leaq -0xf0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x3bc0
jmp 0x40a8
leaq -0x110(%rbp), %rdi
callq 0x3150
leaq -0x111(%rbp), %rdi
callq 0x3290
leaq -0xf0(%rbp), %rdi
callq 0x4b10
incq %rax
movq %rax, -0x1e0(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x4b30
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x4b50
jmp 0x4105
leaq -0x131(%rbp), %rdi
callq 0x4bc0
movl $0x0, -0x138(%rbp)
movl -0x138(%rbp), %eax
movq %rax, -0x1e8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4b10
movq %rax, %rcx
movq -0x1e8(%rbp), %rax
cmpq %rcx, %rax
jae 0x41f6
movl -0x138(%rbp), %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdi
callq 0x4be0
movq %rax, %rdi
callq 0x3130
movq %rax, -0x1f0(%rbp)
movl -0x138(%rbp), %eax
movl %eax, %esi
leaq -0x130(%rbp), %rdi
callq 0x4c00
movq -0x1f0(%rbp), %rcx
movq %rcx, (%rax)
movl -0x138(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x138(%rbp)
jmp 0x411b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x41c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3150
leaq -0x111(%rbp), %rdi
callq 0x3290
jmp 0x4375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x131(%rbp), %rdi
callq 0x4bc0
jmp 0x4369
leaq -0xf0(%rbp), %rdi
callq 0x4b10
movq %rax, %rsi
leaq -0x130(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x4c00
movq -0x1f8(%rbp), %rdi
movq $0x0, (%rax)
callq 0x4c20
movq %rax, -0x140(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4c40
jmp 0x4244
xorl %eax, %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdi
callq 0x4be0
movq %rax, %rsi
leaq -0x190(%rbp), %rdi
callq 0x30f0
jmp 0x4265
movq -0x140(%rbp), %rdx
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x3a00
movl %eax, -0x1fc(%rbp)
jmp 0x4287
movl -0x1fc(%rbp), %eax
movl %eax, -0x54(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3150
leaq -0x170(%rbp), %rdi
callq 0x4c70
cmpl $-0x1, -0x54(%rbp)
jne 0x4308
movl $0x3, -0xd8(%rbp)
jmp 0x4312
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x435d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x42fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3150
leaq -0x170(%rbp), %rdi
callq 0x4c70
jmp 0x435d
movl $0x0, -0xd8(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x4c90
leaq -0xf0(%rbp), %rdi
callq 0x4870
leaq -0x78(%rbp), %rdi
callq 0x3150
movl -0xd8(%rbp), %eax
movl %eax, -0x200(%rbp)
testl %eax, %eax
je 0x4358
jmp 0x4345
movl -0x200(%rbp), %eax
subl $0x2, %eax
je 0x3ea0
jmp 0x4356
jmp 0x4389
jmp 0x3ea0
leaq -0x130(%rbp), %rdi
callq 0x4c90
leaq -0xf0(%rbp), %rdi
callq 0x4870
leaq -0x78(%rbp), %rdi
callq 0x3150
leaq -0x50(%rbp), %rdi
callq 0x4c70
jmp 0x43af
movl $0x0, -0x4(%rbp)
movl $0x1, -0xd8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4c70
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x33d0
nopl (%rax,%rax)