// File: AndreiBarsan[P]uShell/shell.cc
// Function: microshell::core::Shell::Shell(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
Shell::Shell(const vector<string> &) :
    exit_requested(false),
    home_directory(util::get_current_home()),
    standard_output(cout),
    error_output(cerr),
    name("ush"),
    username(util::get_current_user()),
    waiting_for_child(false) {
  this->load_default_modules();
  cout << "Welcome to microshell, " << username << "!" << endl;
  if(!util::getcwd(&this->working_directory)) {
    eout("Failed to get the current working directory.");
    // TODO(andrei) Display what `~' resolves to between parentheses.  If it
    // can't be resolved, use `/' instead.
    eout("Defaulting to `~'.");
    // TODO(andrei) Use setter and actually resolve $HOME.
    this->working_directory = "~";
  }

  string envpath = getenv("PATH");
  this->path = util::split(envpath, ':');

  this->info("Setting up signal handlers...");
  if(SIG_ERR == signal(SIGINT, handle_sigint)) {
    this->fatal("Could not set up SIGINT handler (C-c terminate support).");
  }
  if(SIG_ERR == signal(SIGTSTP, handle_sigtstp)) {
    this->fatal("Could not set up SIGTSTP handler (C-z suspend support).");
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x148(%rbp)
movb $0x0, (%rax)
addq $0x8, %rax
movq %rax, -0x140(%rbp)
leaq -0x11(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x5470
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0x90ba(%rip), %rsi      # 0x233db
callq 0x5360
jmp 0x1a328
leaq -0x11(%rbp), %rdi
callq 0x52c0
movq -0x148(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0x160(%rbp)
callq 0x1c0c0
movq -0x148(%rbp), %rdi
addq $0x40, %rdi
movq %rdi, -0x158(%rbp)
callq 0x5370
movq -0x148(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x150(%rbp)
callq 0x20940
jmp 0x1a378
movq -0x148(%rbp), %rax
movq 0x1ec42(%rip), %rcx     # 0x38fc8
movq %rcx, 0x80(%rax)
movq 0x1ec5c(%rip), %rcx     # 0x38ff0
movq %rcx, 0x88(%rax)
addq $0x90, %rax
movq %rax, -0x170(%rbp)
leaq -0x25(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x5470
movq -0x170(%rbp), %rdi
movq -0x168(%rbp), %rdx
leaq 0x9016(%rip), %rsi      # 0x233e3
callq 0x5360
jmp 0x1a3d4
leaq -0x25(%rbp), %rdi
callq 0x52c0
movq -0x148(%rbp), %rdi
addq $0xb0, %rdi
movq %rdi, -0x178(%rbp)
callq 0x20a50
jmp 0x1a3f9
movq -0x148(%rbp), %rdi
addq $0xd0, %rdi
movq %rdi, -0x180(%rbp)
callq 0x1c0e0
movq -0x148(%rbp), %rdi
movb $0x0, 0xe8(%rdi)
callq 0x1a990
jmp 0x1a428
movq 0x1eb99(%rip), %rdi     # 0x38fc8
leaq 0x8fb1(%rip), %rsi      # 0x233e7
callq 0x5270
movq %rax, -0x188(%rbp)
jmp 0x1a444
movq -0x188(%rbp), %rdi
movq -0x148(%rbp), %rsi
addq $0xb0, %rsi
callq 0x5220
movq %rax, -0x190(%rbp)
jmp 0x1a467
movq -0x190(%rbp), %rdi
leaq 0x7ba4(%rip), %rsi      # 0x22019
callq 0x5270
movq %rax, -0x198(%rbp)
jmp 0x1a483
movq -0x198(%rbp), %rdi
movq 0x1eb1f(%rip), %rsi     # 0x38fb0
callq 0x52b0
jmp 0x1a498
movq -0x148(%rbp), %rdi
addq $0x40, %rdi
callq 0x20770
movb %al, -0x199(%rbp)
jmp 0x1a4b0
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x1a641
jmp 0x1a4c0
leaq -0x49(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x5470
movq -0x1a8(%rbp), %rdx
leaq 0x8f21(%rip), %rsi      # 0x233ff
leaq -0x48(%rbp), %rdi
callq 0x5360
jmp 0x1a4e9
movq -0x148(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1aa60
jmp 0x1a4fb
leaq -0x48(%rbp), %rdi
callq 0x5190
leaq -0x49(%rbp), %rdi
callq 0x52c0
leaq -0x71(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x5470
movq -0x1b0(%rbp), %rdx
leaq 0x8f01(%rip), %rsi      # 0x2342c
leaq -0x70(%rbp), %rdi
callq 0x5360
jmp 0x1a536
movq -0x148(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1aa60
jmp 0x1a548
leaq -0x70(%rbp), %rdi
callq 0x5190
leaq -0x71(%rbp), %rdi
callq 0x52c0
movq -0x148(%rbp), %rdi
addq $0x40, %rdi
leaq 0x7ba0(%rip), %rsi      # 0x2210c
callq 0x5350
jmp 0x1a573
jmp 0x1a641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x11(%rbp), %rdi
callq 0x52c0
jmp 0x1a97b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a957
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x25(%rbp), %rdi
callq 0x52c0
jmp 0x1a94b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a93f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a927
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5190
leaq -0x49(%rbp), %rdi
callq 0x52c0
jmp 0x1a927
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a633
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x5190
leaq -0x71(%rbp), %rdi
callq 0x52c0
jmp 0x1a927
leaq 0x8df7(%rip), %rdi      # 0x2343f
callq 0x5310
movq %rax, -0x1c0(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x5470
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x5360
jmp 0x1a683
leaq -0x99(%rbp), %rdi
callq 0x52c0
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x3a, %edx
callq 0x203d0
jmp 0x1a6a9
movq -0x148(%rbp), %rdi
addq $0x28, %rdi
leaq -0xb8(%rbp), %rsi
movq %rsi, -0x1d0(%rbp)
callq 0x1c100
movq -0x1d0(%rbp), %rdi
callq 0x8660
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x5470
movq -0x1c8(%rbp), %rdx
leaq 0x8d50(%rip), %rsi      # 0x23444
leaq -0xd8(%rbp), %rdi
callq 0x5360
jmp 0x1a702
movq -0x148(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x19f70
jmp 0x1a717
leaq -0xd8(%rbp), %rdi
callq 0x5190
leaq -0xd9(%rbp), %rdi
callq 0x52c0
movl $0x2, %edi
leaq -0xa7b(%rip), %rsi      # 0x19cc0
callq 0x52f0
movq %rax, %rcx
movq $-0x1, %rax
cmpq %rcx, %rax
jne 0x1a850
leaq -0x101(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x5470
movq -0x1d8(%rbp), %rdx
leaq 0x8cee(%rip), %rsi      # 0x23462
leaq -0x100(%rbp), %rdi
callq 0x5360
jmp 0x1a782
movq -0x148(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x19ee0
jmp 0x1a797
leaq -0x100(%rbp), %rdi
callq 0x5190
leaq -0x101(%rbp), %rdi
callq 0x52c0
jmp 0x1a850
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x52c0
jmp 0x1a927
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a91b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a808
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x5190
leaq -0xd9(%rbp), %rdi
callq 0x52c0
jmp 0x1a91b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a83f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x5190
leaq -0x101(%rbp), %rdi
callq 0x52c0
jmp 0x1a91b
movl $0x14, %edi
leaq -0x78c(%rip), %rsi      # 0x1a0d0
callq 0x52f0
movq %rax, %rcx
movq $-0x1, %rax
cmpq %rcx, %rax
jne 0x1a906
leaq -0x129(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x5470
movq -0x1e0(%rbp), %rdx
leaq 0x8c06(%rip), %rsi      # 0x2349b
leaq -0x128(%rbp), %rdi
callq 0x5360
jmp 0x1a8a3
movq -0x148(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x19ee0
jmp 0x1a8b8
leaq -0x128(%rbp), %rdi
callq 0x5190
leaq -0x129(%rbp), %rdi
callq 0x52c0
jmp 0x1a906
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1a8f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x5190
leaq -0x129(%rbp), %rdi
callq 0x52c0
jmp 0x1a91b
leaq -0x98(%rbp), %rdi
callq 0x5190
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x5190
movq -0x180(%rbp), %rdi
callq 0x1c130
movq -0x178(%rbp), %rdi
callq 0x5190
movq -0x170(%rbp), %rdi
callq 0x5190
movq -0x150(%rbp), %rdi
callq 0x5190
movq -0x158(%rbp), %rdi
callq 0x5190
movq -0x160(%rbp), %rdi
callq 0x8660
movq -0x140(%rbp), %rdi
callq 0x5190
movq -0x20(%rbp), %rdi
callq 0x5460
nopw %cs:(%rax,%rax)