// File: brandoncanaday[P]1730sh/1730sh.cpp
// Function: check_current_jobs()
void check_current_jobs() {
  pid_t wpid;
  int pstatus;
  for(unsigned int i = 0, s = current_jobs.size(); i < s; i++) {
    if(current_jobs[i] != nullptr) {
      pid_t pid = current_jobs[i]->getProcesses().back().PID;
      while((wpid = waitpid(pid, &pstatus, WNOHANG | WUNTRACED | WCONTINUED)) > 0) {
	if(WIFEXITED(pstatus)) {
	  cout << current_jobs[i]->getJID() << " "
	       << "Exited (" << WEXITSTATUS(pstatus) << ")" << " " 
	       << current_jobs[i]->getShellInput() << endl;
	  last_exit_status = WEXITSTATUS(pstatus);
	  delete_from_current_jobs(current_jobs[i]);
	  break;
	} else if(WIFSIGNALED(pstatus)) {
	  cout << current_jobs[i]->getJID() << " "
	       << "Exited (" << strsignal(WTERMSIG(pstatus)) << ")" << " " 
	       << current_jobs[i]->getShellInput() << endl;
	  last_exit_status = WTERMSIG(pstatus);
	  delete_from_current_jobs(current_jobs[i]);
	  break;
	} else if(WIFSTOPPED(pstatus)) {
	  current_jobs[i]->setStatus("Stopped");
	  format_job_info(current_jobs[i],"Stopped");
	  break;
	} else if(WIFCONTINUED(pstatus)) {
	  current_jobs[i]->setStatus("Running");
	  format_job_info(current_jobs[i],"Continued");
	  break;
	} // if/else	
      } // while
    } // if
  } // for
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0xc(%rbp)
leaq 0x169da(%rip), %rdi     # 0x1c360
callq 0xb910
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x5c93
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x169ba(%rip), %rdi     # 0x1c360
callq 0xb930
cmpq $0x0, (%rax)
je 0x5c83
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x1699f(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0xb440
movq %rax, %rdi
callq 0xbac0
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
leaq -0x8(%rbp), %rsi
movl $0xb, %edx
callq 0x3260
movl %eax, -0x4(%rbp)
cmpl $0x0, %eax
jle 0x5c81
movl -0x8(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x5ae5
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x1694d(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0xb500
movl %eax, %esi
movq 0x1659f(%rip), %rdi     # 0x1bfc8
callq 0x3570
movq %rax, %rdi
leaq 0xecea(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, %rdi
leaq 0xe6a9(%rip), %rsi      # 0x140f0
callq 0x32e0
movq %rax, %rdi
movl -0x8(%rbp), %esi
andl $0xff00, %esi           # imm = 0xFF00
sarl $0x8, %esi
callq 0x3570
movq %rax, %rdi
leaq 0xe6b5(%rip), %rsi      # 0x1411f
callq 0x32e0
movq %rax, %rdi
leaq 0xeca9(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x168d2(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0xbaa0
movq -0x20(%rbp), %rdi
movq %rax, %rsi
callq 0x32a0
movq %rax, %rdi
movq 0x164f7(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl -0x8(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movl %eax, 0x1688d(%rip)     # 0x1c354
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x1688d(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0x86b0
jmp 0x5c81
movl -0x8(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x5bdc
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x16858(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0xb500
movl %eax, %esi
movq 0x164aa(%rip), %rdi     # 0x1bfc8
callq 0x3570
movq %rax, %rdi
leaq 0xebf5(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, %rdi
leaq 0xe5b4(%rip), %rsi      # 0x140f0
callq 0x32e0
movq %rax, -0x30(%rbp)
movl -0x8(%rbp), %edi
andl $0x7f, %edi
callq 0x35a0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x32e0
movq %rax, %rdi
leaq 0xe5b9(%rip), %rsi      # 0x1411f
callq 0x32e0
movq %rax, %rdi
leaq 0xebad(%rip), %rsi      # 0x14722
callq 0x32e0
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x167d6(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0xbaa0
movq -0x28(%rbp), %rdi
movq %rax, %rsi
callq 0x32a0
movq %rax, %rdi
movq 0x163fb(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl -0x8(%rbp), %eax
andl $0x7f, %eax
movl %eax, 0x16796(%rip)     # 0x1c354
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x16796(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
callq 0x86b0
jmp 0x5c81
movl -0x8(%rbp), %eax
andl $0xff, %eax
cmpl $0x7f, %eax
jne 0x5c2b
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x1676b(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
leaq 0xe4f5(%rip), %rsi      # 0x140f9
callq 0x11330
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x1674b(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
leaq 0xe4d5(%rip), %rsi      # 0x140f9
callq 0x8350
jmp 0x5c81
cmpl $0xffff, -0x8(%rbp)     # imm = 0xFFFF
jne 0x5c76
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x16720(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
leaq 0xe4b2(%rip), %rsi      # 0x14101
callq 0x11330
movl -0xc(%rbp), %eax
movl %eax, %esi
leaq 0x16700(%rip), %rdi     # 0x1c360
callq 0xb930
movq (%rax), %rdi
leaq 0xe49a(%rip), %rsi      # 0x14109
callq 0x8350
jmp 0x5c81
jmp 0x5c78
jmp 0x5c7a
jmp 0x5c7c
jmp 0x59db
jmp 0x5c83
jmp 0x5c85
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x598e
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)