// File: /workspace/github_c_makefile_star2_O3/containers[P]conmon/src/ctr_exit.c
// Function: check_child_processes
static void check_child_processes(GHashTable *pid_to_handler, GHashTable *cache)
{
	for (;;) {
		int status;
		pid_t pid = waitpid(-1, &status, WNOHANG);
		if (pid < 0 && errno == EINTR)
			continue;

		if (pid < 0 && errno == ECHILD) {
			/* Before quitting, check if container_pid is still alive.
			 * In some systemd configurations, the container process may not be
			 * a direct child, so we won't receive SIGCHLD when it exits.
			 * Use kill(pid, 0) to check if the process still exists. */
			if (container_pid > 0) {
				if (kill(container_pid, 0) == 0) {
					/* Container process is still alive but not our child.
					 * Don't quit the main loop yet. */
					ninfof("Container process %d is still alive but not a direct child", container_pid);
					return;
				} else if (errno == ESRCH) {
					/* Container process has exited */
					ninfof("Container process %d has exited (detected via kill probe)", container_pid);
					/* Simulate container exit callback */
					container_status = 0; /* We can't get the real exit status */
					container_pid = -1;
					/* Fall through to quit the main loop */
				}
			}
			g_main_loop_quit(main_loop);
			return;
		}
		if (pid < 0)
			pexit("Failed to read child process status");

		if (pid == 0)
			return;

		/* If we got here, pid > 0, so we have a valid pid to check.  */
		void (*cb)(GPid, int, gpointer) = g_hash_table_lookup(pid_to_handler, &pid);
		if (cb) {
			cb(pid, status, 0);
		} else if (cache) {
			pid_t *k = g_malloc(sizeof(pid_t));
			int *v = g_malloc(sizeof(int));
			if (k == NULL || v == NULL)
				pexit("Failed to allocate memory");
			*k = pid;
			*v = status;
			g_hash_table_insert(cache, k, v);
		}
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %r15
leaq 0x8(%rsp), %r12
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %r15, %rsi
movl $0x1, %edx
callq 0x4560
movl %eax, 0x8(%rsp)
testl %eax, %eax
js 0xc14c
je 0xc212
movq %r14, %rdi
movq %r12, %rsi
callq 0x4660
testq %rax, %rax
je 0xc15d
movl 0x8(%rsp), %edi
movl 0xc(%rsp), %esi
xorl %edx, %edx
callq *%rax
jmp 0xc10e
callq 0x45b0
movq %rax, %r13
movl (%rax), %eax
cmpl $0x4, %eax
je 0xc10e
jmp 0xc1ac
testq %rbx, %rbx
je 0xc10e
movl $0x4, %edi
callq 0x42c0
movq %rax, %r13
movl $0x4, %edi
callq 0x42c0
testq %r13, %r13
je 0xc233
testq %rax, %rax
je 0xc233
movl 0x8(%rsp), %ecx
movl %ecx, (%r13)
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x4220
jmp 0xc10e
cmpl $0xa, %eax
jne 0xc22e
cmpl $0x0, 0x19c9c(%rip)     # 0x25e54
jle 0xc1f5
movl 0x19c94(%rip), %edi     # 0x25e54
xorl %esi, %esi
callq 0x4490
testl %eax, %eax
je 0xc206
cmpl $0x3, (%r13)
jne 0xc1f5
leaq 0x92bb(%rip), %rax      # 0x15494
cmpl $0x2, (%rax)
jae 0xc227
leaq 0x9b4f(%rip), %rax      # 0x15d34
movl $0x0, (%rax)
movl $0xffffffff, 0x19c5f(%rip) # imm = 0xFFFFFFFF
leaq 0x1dde4(%rip), %rax     # 0x29fe0
movq (%rax), %rdi
callq 0x4160
jmp 0xc212
leaq 0x9287(%rip), %rax      # 0x15494
cmpl $0x2, (%rax)
jae 0xc220
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x7c02
jmp 0xc212
callq 0x7bb4
jmp 0xc1de
callq 0x7c50
callq 0x7b5e