// File: /workspace/github_cpp_makefile_star2_O1/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 0x7379
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 0x736f
movl -0x1c(%rbp), %eax
movl %eax, %ecx
andl $0x7f, %ecx
je 0x71d9
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x7293
movl (%rbx), %esi
movq 0xae59(%rip), %rdi      # 0x11fd0
callq 0x3510
movq %rax, %r14
leaq 0x659c(%rip), %rsi      # 0xd722
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
leaq 0x5f56(%rip), %rsi      # 0xd0f0
movl $0x8, %edx
movq %r14, %rdi
callq 0x3300
movl -0x1c(%rbp), %edi
andl $0x7f, %edi
callq 0x3540
testq %rax, %rax
je 0x72df
movq %rax, %r15
movq %rax, %rdi
callq 0x3130
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3300
jmp 0x72f9
movl (%rbx), %esi
movq 0xadee(%rip), %rdi      # 0x11fd0
callq 0x3510
movq %rax, %r15
leaq 0x6531(%rip), %r14      # 0xd722
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x3300
leaq 0x5ee8(%rip), %rsi      # 0xd0f0
movl $0x8, %edx
movq %r15, %rdi
callq 0x3300
movzbl -0x1b(%rbp), %esi
movq %r15, %rdi
callq 0x3510
movq %rax, %r15
leaq 0x5ef4(%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 0x737a
movzbl -0x1b(%rbp), %eax
jmp 0x7369
cmpb $0x7f, %al
jne 0x72b1
leaq 0x5e5b(%rip), %r14      # 0xd0f9
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb9b6
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x72d5
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x736f
leaq 0x5e3e(%rip), %rsi      # 0xd101
movq %rbx, %rdi
callq 0xb9b6
leaq 0x5e37(%rip), %rsi      # 0xd109
movq %rbx, %rdi
callq 0x7016
jmp 0x736f
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x3500
leaq 0x5e1f(%rip), %rsi      # 0xd11f
movl $0x1, %edx
movq %r14, %rdi
callq 0x3300
leaq 0x640e(%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 0x737a
movl -0x1c(%rbp), %eax
andl $0x7f, %eax
movl %eax, 0xaf95(%rip)      # 0x12304
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq