// File: /workspace/github_cpp_makefile_star2_O3/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:
testq %rdi, %rdi
je 0x7393
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movl -0x28(%rax), %edi
leaq -0x1c(%rbp), %rsi
movl $0x2, %edx
callq 0x3220
testl %eax, %eax
jle 0x7389
movl -0x1c(%rbp), %eax
movl %eax, %ecx
andl $0x7f, %ecx
je 0x71f3
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x72ad
movl (%rbx), %esi
movq 0xae3f(%rip), %rdi      # 0x11fd0
callq 0x3510
movq %rax, %r14
leaq 0x6582(%rip), %rsi      # 0xd722
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
leaq 0x5f3c(%rip), %rsi      # 0xd0f0
movl $0x8, %edx
movq %r14, %rdi
callq 0x3300
movl -0x1c(%rbp), %edi
andl $0x7f, %edi
callq 0x3540
testq %rax, %rax
je 0x72f9
movq %rax, %r15
movq %rax, %rdi
callq 0x3130
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3300
jmp 0x7313
movl (%rbx), %esi
movq 0xadd4(%rip), %rdi      # 0x11fd0
callq 0x3510
movq %rax, %r15
leaq 0x6517(%rip), %r14      # 0xd722
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x3300
leaq 0x5ece(%rip), %rsi      # 0xd0f0
movl $0x8, %edx
movq %r15, %rdi
callq 0x3300
movzbl -0x1b(%rbp), %esi
movq %r15, %rdi
callq 0x3510
movq %rax, %r15
leaq 0x5eda(%rip), %rsi      # 0xd11f
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x3300
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %r15, %rdi
callq 0x3300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
movq %rbx, %rdi
callq 0x7394
movzbl -0x1b(%rbp), %eax
jmp 0x7383
cmpb $0x7f, %al
jne 0x72cb
leaq 0x5e41(%rip), %r14      # 0xd0f9
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb93e
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x72ef
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x7389
leaq 0x5e24(%rip), %rsi      # 0xd101
movq %rbx, %rdi
callq 0xb93e
leaq 0x5e1d(%rip), %rsi      # 0xd109
movq %rbx, %rdi
callq 0x7030
jmp 0x7389
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x3500
leaq 0x5e05(%rip), %rsi      # 0xd11f
movl $0x1, %edx
movq %r14, %rdi
callq 0x3300
leaq 0x63f4(%rip), %rsi      # 0xd722
movl $0x1, %edx
movq %r14, %rdi
callq 0x3300
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
movq %rbx, %rdi
callq 0x7394
movl -0x1c(%rbp), %eax
andl $0x7f, %eax
movl %eax, 0xaf7b(%rip)      # 0x12304
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq