// File: /workspace/github_c_makefile_star2_O1/intel[P]pf-bb-config/daemon.c
// Function: daemonize
void
daemonize(hw_device *dev)
{
	pid_t pid, sid;

	(void) signal(SIGTERM, sig_fun);
	(void) signal(SIGKILL, sig_fun);
	(void) signal(SIGABRT, sig_fun);
	(void) signal(SIGSEGV, sig_fun);
	(void) signal(SIGBUS, sig_fun);
	(void) signal(SIGILL, sig_fun);

	pid = fork();
	if (pid < 0)
		exit(EXIT_FAILURE);

	/* exit the parent */
	if (pid > 0)
		exit(EXIT_SUCCESS);

	umask(0);

	/* do not let the child to become orphan */
	sid = setsid();
	if (sid < 0)
		exit(EXIT_FAILURE);

	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);

	if (cli_channel_init(dev) < 0) {
		LOG(ERR, "cli channel init failed");
		return;
	}

	LOG(DEBUG, "Event processor started");

	/* blocks on events */
	event_processor(dev);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdi, %rbx
leaq 0x2cc(%rip), %r14       # 0x19bea
movl $0xf, %edi
movq %r14, %rsi
callq 0xd210
movl $0x9, %edi
movq %r14, %rsi
callq 0xd210
movl $0x6, %edi
movq %r14, %rsi
callq 0xd210
movl $0xb, %edi
movq %r14, %rsi
callq 0xd210
movl $0x7, %edi
movq %r14, %rsi
callq 0xd210
movl $0x4, %edi
movq %r14, %rsi
callq 0xd210
callq 0xd420
testl %eax, %eax
js 0x19bd9
jne 0x19be3
xorl %edi, %edi
callq 0xd230
callq 0xd1b0
testl %eax, %eax
js 0x19bd9
xorl %edi, %edi
callq 0xd1a0
movl $0x1, %edi
callq 0xd1a0
movl $0x2, %edi
callq 0xd1a0
movq %rbx, %rdi
callq 0x198c5
movl %eax, %ebp
callq 0x19c5d
testl %ebp, %ebp
js 0x19ba9
movq %rbx, 0x8(%rsp)
leaq 0x1a4ff(%rip), %rbx     # 0x33ed0
movq 0x18(%rbx), %r8
leaq 0x4b1f(%rip), %rdx      # 0x1e4fb
leaq 0x4b3d(%rip), %r9       # 0x1e520
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
cmpb $0x0, 0x2109d(%rip)     # 0x3aa98
jne 0x19aee
leaq 0x20f30(%rip), %r14     # 0x3a938
leaq 0x4c8a(%rip), %r15      # 0x1e699
leaq 0x21002(%rip), %r12     # 0x3aa18
leaq 0x4c8c(%rip), %r13      # 0x1e6a9
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
movl %ecx, 0xe0(%r14,%rax,8)
movw $0x1, 0xe4(%r14,%rax,8)
incq %rax
cmpq $0xb, %rax
jne 0x19a1f
callq 0x19c5d
movq 0x18(%rbx), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x4c23(%rip), %rdx      # 0x1e679
movq %rax, %rcx
movq %r15, %r9
xorl %eax, %eax
callq 0x19ca8
movl $0xb, %esi
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd2e0
movl %eax, %ebp
callq 0x19c5d
movq 0x18(%rbx), %r8
movl %ebp, (%rsp)
movl $0x3, %edi
xorl %esi, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %r15, %r9
xorl %eax, %eax
callq 0x19ca8
xorl %ebp, %ebp
movl 0xe0(%r14,%rbp,8), %edi
cmpl $-0x1, %edi
je 0x19ad3
testb $0x1, 0xe6(%r14,%rbp,8)
je 0x19ad3
movw $0x0, 0xe6(%r14,%rbp,8)
movq 0x30(%r14,%rbp,8), %rax
testq %rax, %rax
je 0x19ad3
movq 0x88(%r14,%rbp,8), %rsi
callq *%rax
incq %rbp
cmpq $0xb, %rbp
jne 0x19a9c
cmpb $0x1, 0x20fb5(%rip)     # 0x3aa98
movl $0x0, %eax
jne 0x19a1f
callq 0x19c5d
movq 0x10(%rbx), %r8
leaq 0x4be3(%rip), %rdx      # 0x1e6e1
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
leaq 0x50(%rsp), %r14
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0xd180
movq 0x8(%rsp), %rcx
addq $0x20, %rcx
leaq 0x47d5(%rip), %rsi      # 0x1e308
leaq 0x47d9(%rip), %rdx      # 0x1e313
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0xd3e0
leaq 0x4bae(%rip), %rsi      # 0x1e6fe
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xd3e0
movq %r14, %rdi
callq 0xd140
movl %eax, %ebp
callq 0x19c5d
movq 0x18(%rbx), %r8
movl %ebp, (%rsp)
leaq 0x4b8e(%rip), %rdx      # 0x1e708
leaq 0x4b18(%rip), %r9       # 0x1e699
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
callq 0x19ee5
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a320(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x4922(%rip), %rdx      # 0x1e4dc
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x19ca8
movl $0x1, %edi
callq 0xd3f0
xorl %edi, %edi
callq 0xd3f0