// File: brandoncanaday[P]1730sh/1730sh.cpp
// Function: wait_for_job(Input*)
void wait_for_job(Input * job) { 
  if(job != nullptr) {
    int wpid, pstatus;
    if((wpid = waitpid(job->getProcesses().back().PID, &pstatus, WUNTRACED)) > 0) {
      if(WIFEXITED(pstatus)) {
	cout << job->getJID() << " " 
	     << "Exited (" << WEXITSTATUS(pstatus) << ")" << " " 
	     << job->getShellInput() << endl;
	delete_from_current_jobs(job);	
	last_exit_status = WEXITSTATUS(pstatus);
      } else if(WIFSIGNALED(pstatus)) {
	cout << job->getJID() << " " 
	     << "Exited (" << strsignal(WTERMSIG(pstatus)) << ")" << " " 
	     << job->getShellInput() << endl;
	delete_from_current_jobs(job);
	last_exit_status = WTERMSIG(pstatus);
      } else if(WIFSTOPPED(pstatus)) {
	job->setStatus("Stopped");
	format_job_info(job,"Stopped");
      } else if(WIFCONTINUED(pstatus)) {
	job->setStatus("Running");
	format_job_info(job,"Continued");
      } // if/else
    } // if
  } // if
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x86a7
movq -0x8(%rbp), %rdi
callq 0xb440
movq %rax, %rdi
callq 0xbac0
movl (%rax), %edi
leaq -0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x3260
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
jle 0x86a5
movl -0x10(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x8581
movq -0x8(%rbp), %rdi
callq 0xb500
movl %eax, %esi
movq 0x13ae3(%rip), %rdi     # 0x1bfc8
callq 0x3570
movq %rax, %rdi
leaq 0xc22e(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, %rdi
leaq 0xbbed(%rip), %rsi      # 0x140f0
callq 0x32e0
movq %rax, %rdi
movl -0x10(%rbp), %esi
andl $0xff00, %esi           # imm = 0xFF00
sarl $0x8, %esi
callq 0x3570
movq %rax, %rdi
leaq 0xbbf9(%rip), %rsi      # 0x1411f
callq 0x32e0
movq %rax, %rdi
leaq 0xc1ed(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xbaa0
movq -0x18(%rbp), %rdi
movq %rax, %rsi
callq 0x32a0
movq %rax, %rdi
movq 0x13a4b(%rip), %rsi     # 0x1bfa8
callq 0x3330
movq -0x8(%rbp), %rdi
callq 0x86b0
movl -0x10(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movl %eax, 0x13dd8(%rip)     # 0x1c354
jmp 0x86a3
movl -0x10(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x8645
movq -0x8(%rbp), %rdi
callq 0xb500
movl %eax, %esi
movq 0x13a1e(%rip), %rdi     # 0x1bfc8
callq 0x3570
movq %rax, %rdi
leaq 0xc169(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, %rdi
leaq 0xbb28(%rip), %rsi      # 0x140f0
callq 0x32e0
movq %rax, -0x28(%rbp)
movl -0x10(%rbp), %edi
andl $0x7f, %edi
callq 0x35a0
movq -0x28(%rbp), %rdi
movq %rax, %rsi
callq 0x32e0
movq %rax, %rdi
leaq 0xbb2d(%rip), %rsi      # 0x1411f
callq 0x32e0
movq %rax, %rdi
leaq 0xc121(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0xbaa0
movq -0x20(%rbp), %rdi
movq %rax, %rsi
callq 0x32a0
movq %rax, %rdi
movq 0x1397f(%rip), %rsi     # 0x1bfa8
callq 0x3330
movq -0x8(%rbp), %rdi
callq 0x86b0
movl -0x10(%rbp), %eax
andl $0x7f, %eax
movl %eax, 0x13d11(%rip)     # 0x1c354
jmp 0x86a1
movl -0x10(%rbp), %eax
andl $0xff, %eax
cmpl $0x7f, %eax
jne 0x8674
movq -0x8(%rbp), %rdi
leaq 0xba9c(%rip), %rsi      # 0x140f9
callq 0x11330
movq -0x8(%rbp), %rdi
leaq 0xba8c(%rip), %rsi      # 0x140f9
callq 0x8350
jmp 0x869f
cmpl $0xffff, -0x10(%rbp)    # imm = 0xFFFF
jne 0x869d
movq -0x8(%rbp), %rdi
leaq 0xba79(%rip), %rsi      # 0x14101
callq 0x11330
movq -0x8(%rbp), %rdi
leaq 0xba71(%rip), %rsi      # 0x14109
callq 0x8350
jmp 0x869f
jmp 0x86a1
jmp 0x86a3
jmp 0x86a5
jmp 0x86a7
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)