// File: /workspace/github_c_makefile_star2_O3/containers[P]conmon/src/ctr_exit.c
// Function: do_exit_command
void do_exit_command()
{
	if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
		_pexit("Failed to reset signal for SIGCHLD");
	}

	/*
	 * Close everything except stdin, stdout and stderr.
	 */
	close_all_fds_ge_than(3);

	/*
	 * We don't want the exit command to be reaped by the parent conmon
	 * as that would prevent double-fork from doing its job.
	 * Unfortunately, that also means that any new subchildren from
	 * still running processes could also get lost
	 */
	if (set_subreaper(false) != 0) {
		nwarn("Failed to disable self subreaper attribute - might wait for indirect children a long time");
	}

	pid_t exit_pid = fork();
	if (exit_pid < 0) {
		_pexit("Failed to fork");
	}

	if (exit_pid) {
		int ret, exit_status = 0;

		/*
		 * Make sure to cleanup any zombie process that the container runtime
		 * could have left around.
		 */
		do {
			int tmp;

			exit_status = 0;
			ret = waitpid(-1, &tmp, 0);
			if (ret == exit_pid)
				exit_status = get_exit_status(tmp);
		} while ((ret < 0 && errno == EINTR) || ret > 0);

		if (exit_status)
			_exit(exit_status);

		return;
	}

	/* Count the additional args, if any.  */
	size_t n_args = 0;
	if (opt_exit_args)
		for (; opt_exit_args[n_args]; n_args++)
			;

	gchar **args = malloc(sizeof(gchar *) * (n_args + 2));
	if (args == NULL)
		_exit(EXIT_FAILURE);

	args[0] = opt_exit_command;
	if (opt_exit_args)
		for (n_args = 0; opt_exit_args[n_args]; n_args++)
			args[n_args + 1] = opt_exit_args[n_args];
	args[n_args + 1] = NULL;

	if (opt_exit_delay) {
		ndebugf("Sleeping for %d seconds before executing exit command", opt_exit_delay);
		sleep(opt_exit_delay);
	}

	reset_oom_adjust();

	execv(opt_exit_command, args);

	/* Should not happen, but better be safe. */
	_exit(EXIT_FAILURE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x11, %edi
xorl %esi, %esi
callq 0x4540
cmpq $-0x1, %rax
je 0xc4e6
movl $0x3, %edi
callq 0xcbbf
xorl %edi, %edi
callq 0x9c6b
leaq 0x904b(%rip), %r14      # 0x15494
testl %eax, %eax
je 0xc457
cmpl $0x0, (%r14)
jne 0xc4dc
callq 0x4760
testl %eax, %eax
js 0xc4eb
je 0xc4f0
movl %eax, %ebx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leaq 0x4(%rsp), %r14
xorl %ebp, %ebp
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %r14, %rsi
xorl %edx, %edx
callq 0x4560
cmpl %ebx, %eax
jne 0xc4b7
movl 0x4(%rsp), %ecx
movl %ecx, %ebp
andl $0x7f, %ebp
je 0xc4b4
movl %ebp, %ecx
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
orl $0x80, %ebp
cmpl $0x2000000, %ecx        # imm = 0x2000000
cmovll %r15d, %ebp
jmp 0xc4b7
movzbl %ch, %ebp
testl %eax, %eax
js 0xc4bf
jne 0xc477
jmp 0xc4c9
callq 0x45b0
cmpl $0x4, (%rax)
je 0xc477
testl %ebp, %ebp
jne 0xc504
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x7d3f
jmp 0xc457
callq 0x7de7
callq 0x7d91
leaq 0x1da91(%rip), %rax     # 0x29f88
movq (%rax), %r12
testq %r12, %r12
jne 0xc50b
xorl %r13d, %r13d
jmp 0xc521
movl %ebp, %edi
callq 0x42a0
movq $-0x1, %rax
leaq 0x1(%rax), %r13
cmpq $0x0, 0x8(%r12,%rax,8)
movq %r13, %rax
jne 0xc512
leaq 0x10(,%r13,8), %rdi
callq 0x4250
testq %rax, %rax
je 0xc5f4
movq %rax, %rbx
leaq 0x1da3f(%rip), %r15     # 0x29f80
movq (%r15), %rax
movq %rax, (%rbx)
testq %r12, %r12
je 0xc572
movq (%r12), %rax
testq %rax, %rax
jne 0xc55a
xorl %r13d, %r13d
jmp 0xc572
xorl %ecx, %ecx
leaq 0x1(%rcx), %r13
movq %rax, 0x8(%rbx,%rcx,8)
movq 0x8(%r12,%rcx,8), %rax
movq %r13, %rcx
testq %rax, %rax
jne 0xc55c
movq $0x0, 0x8(%rbx,%r13,8)
leaq 0x1da0e(%rip), %r12     # 0x29f90
movl (%r12), %ecx
testl %ecx, %ecx
je 0xc5e2
cmpl $0x3, (%r14)
jb 0xc5db
movq 0x8a59(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x41da(%rip), %rsi      # 0x1077b
movl %ecx, %edx
xorl %eax, %eax
callq 0x4820
leaq 0x1d917(%rip), %rax     # 0x29ec8
cmpl $0x0, (%rax)
movl (%r12), %ecx
je 0xc5db
leaq 0x1d8ff(%rip), %rax     # 0x29ec0
movq (%rax), %rdx
leaq 0x41f3(%rip), %rsi      # 0x107be
movl $0x6, %edi
xorl %eax, %eax
callq 0x4120
movl (%r12), %ecx
movl %ecx, %edi
callq 0x4450
xorl %eax, %eax
callq 0xb4c5
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x40a0
movl $0x1, %edi
callq 0x42a0