// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xbb44(%rip), %rax      # 0x102f0
subq 0xbb35(%rip), %rax      # 0x102e8
shrq $0x3, %rax
movl %eax, %r15d
xorl %r12d, %r12d
leaq -0x2c(%rbp), %rbx
pushq $0xb
popq %r14
cmpq %r15, %r12
je 0x49c4
movq 0xbb13(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rax
testq %rax, %rax
je 0x49bc
movq 0x38(%rax), %rax
movl -0x28(%rax), %r13d
movl %r13d, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x3210
testl %eax, %eax
jle 0x49bc
movl -0x2c(%rbp), %eax
movl %eax, %ecx
andl $0x7f, %ecx
je 0x485c
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jge 0x48e4
cmpb $0x7f, %al
je 0x498f
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x47ea
movq 0xbab3(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rdi
leaq 0x58c1(%rip), %rsi      # 0xa101
callq 0x927c
movq 0xba9c(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rdi
leaq 0x58b2(%rip), %rsi      # 0xa109
jmp 0x49b7
movq 0xba85(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rax
movl (%rax), %esi
movq 0xb758(%rip), %rdi      # 0xffc8
callq 0x34a0
movq %rax, %rdi
leaq 0x5ea3(%rip), %r13      # 0xa722
movq %r13, %rsi
callq 0x3280
movq %rax, %rdi
leaq 0x585f(%rip), %rsi      # 0xa0f0
callq 0x3280
movzbl -0x2b(%rbp), %esi
movq %rax, %rdi
callq 0x34a0
movq %rax, %rdi
leaq 0x5873(%rip), %rsi      # 0xa11f
callq 0x3280
movq %rax, %rdi
movq %r13, %rsi
callq 0x3280
movq 0xba25(%rip), %rcx      # 0x102e8
movq (%rcx,%r12,8), %rsi
addq $0x10, %rsi
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movzbl -0x2b(%rbp), %eax
jmp 0x4977
movq 0xb9fd(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rax
movl (%rax), %esi
movq 0xb6d0(%rip), %rdi      # 0xffc8
callq 0x34a0
movq %rax, %rdi
leaq 0x5e1b(%rip), %rsi      # 0xa722
callq 0x3280
movq %rax, %rdi
leaq 0x57da(%rip), %rsi      # 0xa0f0
callq 0x3280
movq %rax, %r13
movl -0x2c(%rbp), %edi
andl $0x7f, %edi
callq 0x34c0
movq %r13, %rdi
movq %rax, %rsi
callq 0x3280
movq %rax, %rdi
leaq 0x57e1(%rip), %rsi      # 0xa11f
callq 0x3280
movq %rax, %rdi
leaq 0x5dd5(%rip), %rsi      # 0xa722
callq 0x3280
movq 0xb98f(%rip), %rcx      # 0x102e8
movq (%rcx,%r12,8), %rsi
addq $0x10, %rsi
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movl -0x2c(%rbp), %eax
andl $0x7f, %eax
movl %eax, 0xb95f(%rip)      # 0x102dc
movq 0xb964(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rdi
callq 0x5efb
jmp 0x49bc
movq 0xb952(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rdi
leaq 0x5758(%rip), %r13      # 0xa0f9
movq %r13, %rsi
callq 0x927c
movq 0xb938(%rip), %rax      # 0x102e8
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
callq 0x5cae
incq %r12
jmp 0x47c5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq