// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x11
popq %rdi
xorl %esi, %esi
callq 0x4550
cmpq $-0x1, %rax
je 0xb7f0
pushq $0x3
popq %rdi
callq 0xbfe7
xorl %edi, %edi
callq 0x7771
leaq 0x8d2c(%rip), %r14      # 0x144a4
testl %eax, %eax
je 0xb786
cmpl $0x0, (%r14)
jne 0xb83c
callq 0x4770
testl %eax, %eax
js 0xb892
je 0xb8e7
movl %eax, %ebx
pushq $-0x1
popq %rbp
leaq 0x4(%rsp), %r14
xorl %r15d, %r15d
movl %ebp, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4570
movl %eax, %r12d
cmpl %ebx, %eax
jne 0xb7c5
movl 0x4(%rsp), %edi
callq 0xb5c5
movl %eax, %r15d
testl %r12d, %r12d
js 0xb7ce
jne 0xb7a3
jmp 0xb7d8
callq 0x45c0
cmpl $0x4, (%rax)
je 0xb7a3
testl %r15d, %r15d
jne 0xb8fb
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x87f9(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x1812(%rip), %rsi      # 0xd013
leaq 0x4ee7(%rip), %rdx      # 0x106ef
xorl %eax, %eax
callq 0x4830
leaq 0x1d6c2(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xb8df
leaq 0x1d6aa(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x180d(%rip), %rsi      # 0xd03d
leaq 0x4eb8(%rip), %rcx      # 0x106ef
jmp 0xb8d5
movq 0x87ad(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x194a(%rip), %rsi      # 0xd197
leaq 0x4ebe(%rip), %rdx      # 0x10712
xorl %eax, %eax
callq 0x4830
leaq 0x1d676(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xb786
leaq 0x1d65e(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x1956(%rip), %rsi      # 0xd1d2
leaq 0x4e8f(%rip), %rcx      # 0x10712
pushq $0x6
popq %rdi
xorl %eax, %eax
callq 0x4120
jmp 0xb786
movq 0x8757(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x1770(%rip), %rsi      # 0xd013
leaq 0x4ec2(%rip), %rdx      # 0x1076c
xorl %eax, %eax
callq 0x4830
leaq 0x1d620(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xb8df
leaq 0x1d60c(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x176f(%rip), %rsi      # 0xd03d
leaq 0x4e97(%rip), %rcx      # 0x1076c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x4120
pushq $0x1
popq %rdi
callq 0x42a0
leaq 0x1d6aa(%rip), %rax     # 0x28f98
movq (%rax), %r12
testq %r12, %r12
jne 0xb903
xorl %r13d, %r13d
jmp 0xb915
movl %r15d, %edi
callq 0x42a0
pushq $-0x1
popq %rax
leaq 0x1(%rax), %r13
cmpq $0x0, 0x8(%r12,%rax,8)
movq %r13, %rax
jne 0xb906
leaq 0x10(,%r13,8), %rdi
callq 0x4250
testq %rax, %rax
je 0xb8df
movq %rax, %rbx
leaq 0x1d65f(%rip), %r15     # 0x28f90
movq (%r15), %rax
movq %rax, (%rbx)
testq %r12, %r12
jne 0xb9c2
andq $0x0, 0x8(%rbx,%r13,8)
leaq 0x1d653(%rip), %r12     # 0x28fa0
movl (%r12), %ecx
testl %ecx, %ecx
je 0xb9ab
cmpl $0x3, (%r14)
jb 0xb9a4
movq 0x868e(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4e0f(%rip), %rsi      # 0x1077b
movl %ecx, %edx
xorl %eax, %eax
callq 0x4830
leaq 0x1d55c(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
movl (%r12), %ecx
je 0xb9a4
leaq 0x1d544(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x4e28(%rip), %rsi      # 0x107be
pushq $0x6
popq %rdi
xorl %eax, %eax
callq 0x4120
movl (%r12), %ecx
movl %ecx, %edi
callq 0x4450
xorl %eax, %eax
callq 0x9fec
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x40a0
jmp 0xb8df
xorl %r13d, %r13d
movq (%r12,%r13,8), %rax
testq %rax, %rax
je 0xb940
movq %rax, 0x8(%rbx,%r13,8)
incq %r13
jmp 0xb9c5