// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x11, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x4550
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0xe1fd
jmp 0xe1a4
movq 0x7e45(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0xe5e(%rip), %rsi       # 0xf013
leaq 0x486e(%rip), %rdx      # 0x12a2a
movb $0x0, %al
callq 0x4830
leaq 0x1cd7e(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xe1f3
leaq 0x1cd6a(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x3, %edi
leaq 0xe58(%rip), %rsi       # 0xf03d
leaq 0x483e(%rip), %rcx      # 0x12a2a
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x42a0
movl $0x3, %edi
callq 0xee50
xorl %edi, %edi
callq 0x8d40
cmpl $0x0, %eax
je 0xe276
leaq 0x828a(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xe274
jmp 0xe221
movq 0x7dc8(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0xf65(%rip), %rsi       # 0xf197
leaq 0x4814(%rip), %rdx      # 0x12a4d
movb $0x0, %al
callq 0x4830
leaq 0x1cd01(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xe270
leaq 0x1cced(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0xf70(%rip), %rsi       # 0xf1d2
leaq 0x47e4(%rip), %rcx      # 0x12a4d
movb $0x0, %al
callq 0x4120
jmp 0xe272
jmp 0xe274
jmp 0xe276
callq 0x4780
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jge 0xe2df
jmp 0xe286
movq 0x7d63(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0xd7c(%rip), %rsi       # 0xf013
leaq 0x4809(%rip), %rdx      # 0x12aa7
movb $0x0, %al
callq 0x4830
leaq 0x1cc9c(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xe2d5
leaq 0x1cc88(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x3, %edi
leaq 0xd76(%rip), %rsi       # 0xf03d
leaq 0x47d9(%rip), %rcx      # 0x12aa7
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x42a0
cmpl $0x0, -0x4(%rbp)
je 0xe358
movl $0x0, -0xc(%rbp)
movl $0x0, -0xc(%rbp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x4570
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x4(%rbp), %eax
jne 0xe319
movl -0x10(%rbp), %edi
callq 0xdf80
movl %eax, -0xc(%rbp)
jmp 0xe31b
cmpl $0x0, -0x8(%rbp)
jge 0xe333
callq 0x45c0
movq %rax, %rcx
movb $0x1, %al
cmpl $0x4, (%rcx)
movb %al, -0x21(%rbp)
je 0xe33d
cmpl $0x0, -0x8(%rbp)
setg %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0xe2ec
cmpl $0x0, -0xc(%rbp)
je 0xe352
movl -0xc(%rbp), %edi
callq 0x42a0
addq $0x30, %rsp
popq %rbp
retq
movq $0x0, -0x18(%rbp)
leaq 0x1cca1(%rip), %rax     # 0x2b008
cmpq $0x0, (%rax)
je 0xe396
jmp 0xe36f
leaq 0x1cc92(%rip), %rax     # 0x2b008
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xe394
jmp 0xe386
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xe36f
jmp 0xe396
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
shlq $0x3, %rdi
callq 0x4250
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xe3bc
movl $0x1, %edi
callq 0x42a0
leaq 0x1cc3d(%rip), %rax     # 0x2b000
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
leaq 0x1cc34(%rip), %rax     # 0x2b008
cmpq $0x0, (%rax)
je 0xe426
movq $0x0, -0x18(%rbp)
leaq 0x1cc1f(%rip), %rax     # 0x2b008
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xe424
leaq 0x1cc0a(%rip), %rax     # 0x2b008
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xe3e2
jmp 0xe426
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq $0x0, 0x8(%rax,%rcx,8)
leaq 0x1cbd2(%rip), %rax     # 0x2b010
cmpl $0x0, (%rax)
je 0xe4b6
leaq 0x805a(%rip), %rax      # 0x164a4
cmpl $0x3, (%rax)
jb 0xe4a8
jmp 0xe451
movq 0x7b98(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x1cbae(%rip), %rax     # 0x2b010
movl (%rax), %edx
leaq 0x464b(%rip), %rsi      # 0x12ab6
movb $0x0, %al
callq 0x4830
leaq 0x1cacf(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xe4a4
leaq 0x1cabb(%rip), %rax     # 0x2af40
movq (%rax), %rdx
leaq 0x1cb81(%rip), %rax     # 0x2b010
movl (%rax), %ecx
movl $0x6, %edi
leaq 0x465c(%rip), %rsi      # 0x12af9
movb $0x0, %al
callq 0x4120
jmp 0xe4a6
jmp 0xe4a8
leaq 0x1cb61(%rip), %rax     # 0x2b010
movl (%rax), %edi
callq 0x4460
movb $0x0, %al
callq 0xc3e0
leaq 0x1cb3c(%rip), %rax     # 0x2b000
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x40a0
movl $0x1, %edi
callq 0x42a0
nopw (%rax,%rax)