// File: /workspace/github_cpp_makefile_star2_O3/isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::Wait()
void Wait() {
            PCB* cpu_process = all_processes[CPU];

            // If the process has no children, nothing to wait for
            if (cpu_process->HasChildren()) {
                // If the process already has at least one zombie child, child disappears and parent keeps using CPU
                int PID_of_zombie_child = cpu_process->ProcessHasZombieChild();
                if (PID_of_zombie_child > 0) {  ///////////???
                    cpu_process->SetWaitingState(0);

                    // Delete the zombie child's children
                    DeleteChildren(all_processes[PID_of_zombie_child]);
                    
                    // Delete the zombie child
                    PCB* zombie = all_processes[PID_of_zombie_child];
                    PCB* parent = all_processes[zombie->GetParent()];

                    parent->RemoveChild(zombie);
                    all_processes.erase(PID_of_zombie_child);
                    delete zombie;
                    zombie = nullptr;
                }

                // If the process has no zombie children, remove the process from the ready queue and send process at front of ready queue to CPU
                else {
                    // Set process using CPU to waiting
                    cpu_process->SetWaitingState(1);
                    CPU = ready_queue.front();
                    ready_queue.pop_front();
                    // The waiting parent process will be added back to the end of the ready queue when one of its children exits.
                }
            }
        }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
leaq 0x50(%rdi), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x37e0
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
cmpq %rdx, %rcx
je 0x3387
movq (%rcx), %rsi
cmpb $0x1, 0x24(%rsi)
je 0x329f
addq $0x8, %rcx
cmpq %rdx, %rcx
jne 0x328b
jmp 0x3317
movl (%rsi), %ecx
movl %ecx, 0x8(%rsp)
testl %ecx, %ecx
jle 0x3317
movb $0x0, 0x25(%rax)
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x37e0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3f68
movq %rbx, %rdi
movq %r15, %rsi
callq 0x37e0
movq (%rax), %r14
movl 0x20(%r14), %eax
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x3cda
movq (%rax), %r15
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rax
cmpq %rax, %rdi
je 0x3355
movq %rax, %rdx
subq %rdi, %rdx
addq $-0x8, %rdx
cmpq %r14, (%rdi)
je 0x333b
addq $0x8, %rdi
addq $-0x8, %rdx
cmpq %rax, %rdi
jne 0x3303
jmp 0x3355
movb $0x1, 0x25(%rax)
movq 0x20(%r14), %rbx
movl 0x10(%rbx), %eax
movl %eax, (%r14)
decq 0x30(%r14)
movq %rbx, %rdi
callq 0x2240
movl $0x18, %esi
movq %rbx, %rdi
jmp 0x3382
leaq 0x8(%rdi), %rsi
cmpq %rax, %rsi
je 0x334d
callq 0x2230
movq 0x10(%r15), %rax
addq $-0x8, %rax
movq %rax, 0x10(%r15)
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x42ce
movq %rbx, %rdi
movq %rax, %rsi
callq 0x434c
testq %r14, %r14
je 0x337a
movq %r14, %rdi
callq 0x4104
movl $0x28, %esi
movq %r14, %rdi
callq 0x21a0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop