// File: AndreiBarsan[P]uShell/command.cc
// Function: microshell::core::DiskCommand::invoke(microshell::core::Shell*)
int DiskCommand::invoke(Shell *shell) {
  string comma_args =
    util::merge_with(argv.begin() + 1, argv.end(), ", ");
  shell->out("Invoking program [" + argv[0] + "] with args [" +
              comma_args + "]");
  //signal(SIGCHLD, handle_sigchld);
  pid_t child_pid = fork();
  if(-1 == child_pid) {
    // TODO(andrei) Shell::perror().
    shell->eout("Could not crete a child to run the command. "
                "OS says [" + string(strerror(errno)) + "]. errno = " +
                to_string(errno));
    return -1;
  }
  else if(0 == child_pid) {
    this->handle_child(shell);
    // No return, the child will just 'exec' or 'exit' (on error).
  }

  return this->handle_parent(shell, child_pid);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
addq $0x8, %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x6910
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x6940
movq -0x1d0(%rbp), %rdi
movq %rax, -0x40(%rbp)
callq 0x6980
movq %rax, -0x50(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x5470
movq -0x1c8(%rbp), %rdx
leaq 0x1d60a(%rip), %rsi     # 0x233fc
leaq -0x70(%rbp), %rdi
callq 0x5360
jmp 0x5dfd
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x20550
jmp 0x5e14
leaq -0x70(%rbp), %rdi
callq 0x5190
leaq -0x71(%rbp), %rdi
callq 0x52c0
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x1e0(%rbp)
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6b60
movq %rax, %rdx
leaq 0x1c1cc(%rip), %rsi     # 0x2201b
leaq -0x108(%rbp), %rdi
callq 0x6a50
jmp 0x5e5d
leaq 0x1c1ca(%rip), %rdx     # 0x2202e
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x69b0
jmp 0x5e79
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x6a00
jmp 0x5e92
leaq 0x1c1a3(%rip), %rdx     # 0x2203c
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x69b0
jmp 0x5eae
movq -0x1e0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x1b460
jmp 0x5ec3
leaq -0xa8(%rbp), %rdi
callq 0x5190
leaq -0xc8(%rbp), %rdi
callq 0x5190
leaq -0xe8(%rbp), %rdi
callq 0x5190
leaq -0x108(%rbp), %rdi
callq 0x5190
callq 0x50b0
movl %eax, -0x10c(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x10c(%rbp), %eax
jne 0x61ab
movq -0x18(%rbp), %rax
movq %rax, -0x1f8(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x50d0
movq %rax, -0x1f0(%rbp)
leaq -0x191(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x5470
movq -0x1f0(%rbp), %rsi
movq -0x1e8(%rbp), %rdx
leaq -0x190(%rbp), %rdi
callq 0x5360
jmp 0x5f5c
leaq 0x1c0db(%rip), %rsi     # 0x2203e
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rdx
callq 0x6c50
jmp 0x5f78
leaq 0x1c0f5(%rip), %rdx     # 0x22074
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x69b0
jmp 0x5f94
callq 0x5070
movl (%rax), %esi
leaq -0x1b8(%rbp), %rdi
callq 0x6ca0
jmp 0x5fa9
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x1b8(%rbp), %rdx
callq 0x6b80
jmp 0x5fc5
movq -0x1f8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x1aa60
jmp 0x5fda
leaq -0x130(%rbp), %rdi
callq 0x5190
leaq -0x1b8(%rbp), %rdi
callq 0x5190
leaq -0x150(%rbp), %rdi
callq 0x5190
leaq -0x170(%rbp), %rdi
callq 0x5190
leaq -0x190(%rbp), %rdi
callq 0x5190
leaq -0x191(%rbp), %rdi
callq 0x52c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x1bc(%rbp)
jmp 0x61fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6061
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x5190
leaq -0x71(%rbp), %rdi
callq 0x52c0
jmp 0x621a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6211
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x60e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x60dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x60d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5190
leaq -0xc8(%rbp), %rdi
callq 0x5190
leaq -0xe8(%rbp), %rdi
callq 0x5190
leaq -0x108(%rbp), %rdi
callq 0x5190
jmp 0x6211
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x619d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6191
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6185
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6179
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x616d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5190
leaq -0x1b8(%rbp), %rdi
callq 0x5190
leaq -0x150(%rbp), %rdi
callq 0x5190
leaq -0x170(%rbp), %rdi
callq 0x5190
leaq -0x190(%rbp), %rdi
callq 0x5190
leaq -0x191(%rbp), %rdi
callq 0x52c0
jmp 0x6211
xorl %eax, %eax
cmpl -0x10c(%rbp), %eax
jne 0x61c9
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6230
jmp 0x61c7
jmp 0x61c9
jmp 0x61cb
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x10c(%rbp), %edx
callq 0x64e0
movl %eax, -0x1fc(%rbp)
jmp 0x61e9
movl -0x1fc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x1bc(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5190
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x5190
movq -0x80(%rbp), %rdi
callq 0x5460
nopw %cs:(%rax,%rax)