// File: /workspace/github_c_makefile_star2_O0/alexgirao[P]aimant/chargenx.c
// Function: daemonize
static int daemonize(int close_all_descriptors, int preserve_stderr)
{
	int pid;

	if ((pid = fork()) == 0) {
		/* child
		 */

		int fd, i;

		/* obtain a new process group
		 */
		setsid();

		if (close_all_descriptors) {
			for (i = getdtablesize(); i >= 0; i--) {
				if (preserve_stderr && i == STDERR_FILENO) continue;
				close(i);
			}
		}

		/* redirect descriptors to /dev/null
		 */

		if ((fd = open("/dev/null", O_RDWR)) < 0) {
			int save_errno = errno;
			assert(fd == -1);
			DEBUG("open(\"/dev/null\", O_RDWR), errno=%i", save_errno);
			errno = save_errno;
			perror("/dev/null");
			return -1;
		}

		assert(dup2(fd, STDIN_FILENO) == STDIN_FILENO);
		assert(dup2(fd, STDOUT_FILENO) == STDOUT_FILENO);
		if (preserve_stderr == 0) {
			assert(dup2(fd, STDERR_FILENO) == STDERR_FILENO);
		}
		if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) {
			assert(close(fd) == 0);
			fd = -1;
		}

		umask(027);

		/* first instance continues
		 */
		signal(SIGCHLD, SIG_IGN); /* ignore child */
		signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
		signal(SIGTTOU, SIG_IGN);
		signal(SIGTTIN, SIG_IGN);
		signal(SIGHUP, signal_SIGHUP); /* catch hangup signal */
		signal(SIGTERM, signal_SIGTERM); /* catch kill signal */

		return 0;
	} else if (pid < 0) {
		perror("fork()");
		return -1;
	}

	/* parent exits
	 */
	exit(0);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
callq 0x2250
movl %eax, -0x10(%rbp)
cmpl $0x0, %eax
jne 0x3d94
callq 0x2190
cmpl $0x0, -0x8(%rbp)
je 0x3bab
callq 0x2260
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x3ba9
cmpl $0x0, -0xc(%rbp)
je 0x3b96
cmpl $0x2, -0x18(%rbp)
jne 0x3b96
jmp 0x3b9e
movl -0x18(%rbp), %edi
callq 0x2180
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3b82
jmp 0x3bab
leaq 0x48bf(%rip), %rdi      # 0x8471
movl $0x2, %esi
movb $0x0, %al
callq 0x2210
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jge 0x3c3e
callq 0x2060
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x3bd8
jmp 0x3bf7
leaq 0x4c7c(%rip), %rdi      # 0x885b
leaq 0x4676(%rip), %rsi      # 0x825c
movl $0x23e, %edx            # imm = 0x23E
leaq 0x4e10(%rip), %rcx      # 0x8a02
callq 0x2140
jmp 0x3bf9
movl -0x1c(%rbp), %ecx
leaq 0x4659(%rip), %rdi      # 0x825c
movl $0x23f, %esi            # imm = 0x23F
leaq 0x4e0b(%rip), %rdx      # 0x8a1a
movb $0x0, %al
callq 0x7000
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
callq 0x2060
movl -0x20(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x4844(%rip), %rdi      # 0x8471
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3db8
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x20f0
cmpl $0x0, %eax
jne 0x3c4f
jmp 0x3c6e
leaq 0x4de8(%rip), %rdi      # 0x8a3e
leaq 0x45ff(%rip), %rsi      # 0x825c
movl $0x245, %edx            # imm = 0x245
leaq 0x4d99(%rip), %rcx      # 0x8a02
callq 0x2140
movl -0x14(%rbp), %edi
movl $0x1, %esi
callq 0x20f0
cmpl $0x1, %eax
jne 0x3c82
jmp 0x3ca1
leaq 0x4c0f(%rip), %rdi      # 0x8898
leaq 0x45cc(%rip), %rsi      # 0x825c
movl $0x246, %edx            # imm = 0x246
leaq 0x4d66(%rip), %rcx      # 0x8a02
callq 0x2140
cmpl $0x0, -0xc(%rbp)
jne 0x3cdc
movl -0x14(%rbp), %edi
movl $0x2, %esi
callq 0x20f0
cmpl $0x2, %eax
jne 0x3cbb
jmp 0x3cda
leaq 0x4d17(%rip), %rdi      # 0x89d9
leaq 0x4593(%rip), %rsi      # 0x825c
movl $0x248, %edx            # imm = 0x248
leaq 0x4d2d(%rip), %rcx      # 0x8a02
callq 0x2140
jmp 0x3cdc
cmpl $0x0, -0x14(%rbp)
je 0x3d23
cmpl $0x1, -0x14(%rbp)
je 0x3d23
cmpl $0x2, -0x14(%rbp)
je 0x3d23
movl -0x14(%rbp), %edi
callq 0x2180
cmpl $0x0, %eax
jne 0x3cfd
jmp 0x3d1c
leaq 0x4bbd(%rip), %rdi      # 0x88c1
leaq 0x4551(%rip), %rsi      # 0x825c
movl $0x24b, %edx            # imm = 0x24B
leaq 0x4ceb(%rip), %rcx      # 0x8a02
callq 0x2140
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl $0x17, %edi
callq 0x21d0
movl $0x11, %edi
movl $0x1, %esi
callq 0x21b0
movl $0x14, %edi
movl $0x1, %esi
callq 0x21b0
movl $0x16, %edi
movl $0x1, %esi
callq 0x21b0
movl $0x15, %edi
movl $0x1, %esi
callq 0x21b0
movl $0x1, %edi
leaq 0x7b(%rip), %rsi        # 0x3df0
callq 0x21b0
movl $0xf, %edi
leaq 0x8a(%rip), %rsi        # 0x3e10
callq 0x21b0
movl $0x0, -0x4(%rbp)
jmp 0x3db8
cmpl $0x0, -0x10(%rbp)
jge 0x3daf
leaq 0x4cc4(%rip), %rdi      # 0x8a65
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3db8
jmp 0x3db1
xorl %edi, %edi
callq 0x2240
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)