// File: /workspace/github_c_makefile_star2_O3/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       # 0x198ed
movl $0xf, %edi
movq %r14, %rsi
callq 0xd200
movl $0x9, %edi
movq %r14, %rsi
callq 0xd200
movl $0x6, %edi
movq %r14, %rsi
callq 0xd200
movl $0xb, %edi
movq %r14, %rsi
callq 0xd200
movl $0x7, %edi
movq %r14, %rsi
callq 0xd200
movl $0x4, %edi
movq %r14, %rsi
callq 0xd200
callq 0xd410
testl %eax, %eax
js 0x198dc
jne 0x198e6
xorl %edi, %edi
callq 0xd220
callq 0xd1b0
testl %eax, %eax
js 0x198dc
xorl %edi, %edi
callq 0xd1a0
movl $0x1, %edi
callq 0xd1a0
movl $0x2, %edi
callq 0xd1a0
movq %rbx, %rdi
callq 0x195c8
movl %eax, %ebp
callq 0x19969
testl %ebp, %ebp
js 0x198ac
movq %rbx, 0x8(%rsp)
leaq 0x1a7fc(%rip), %rbx     # 0x33ed0
movq 0x18(%rbx), %r8
leaq 0x4e7c(%rip), %rdx      # 0x1e55b
leaq 0x4e9a(%rip), %r9       # 0x1e580
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
cmpb $0x0, 0x2139a(%rip)     # 0x3aa98
jne 0x197f1
leaq 0x2122d(%rip), %r14     # 0x3a938
leaq 0x4fe7(%rip), %r15      # 0x1e6f9
leaq 0x212ff(%rip), %r12     # 0x3aa18
leaq 0x4fe9(%rip), %r13      # 0x1e709
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 0x19722
callq 0x19969
movq 0x18(%rbx), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x4f80(%rip), %rdx      # 0x1e6d9
movq %rax, %rcx
movq %r15, %r9
xorl %eax, %eax
callq 0x199b4
movl $0xb, %esi
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd2d0
movl %eax, %ebp
callq 0x19969
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 0x199b4
xorl %ebp, %ebp
movl 0xe0(%r14,%rbp,8), %edi
cmpl $-0x1, %edi
je 0x197d6
testb $0x1, 0xe6(%r14,%rbp,8)
je 0x197d6
movw $0x0, 0xe6(%r14,%rbp,8)
movq 0x30(%r14,%rbp,8), %rax
testq %rax, %rax
je 0x197d6
movq 0x88(%r14,%rbp,8), %rsi
callq *%rax
incq %rbp
cmpq $0xb, %rbp
jne 0x1979f
cmpb $0x1, 0x212b2(%rip)     # 0x3aa98
movl $0x0, %eax
jne 0x19722
callq 0x19969
movq 0x10(%rbx), %r8
leaq 0x4f40(%rip), %rdx      # 0x1e741
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
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 0x4b32(%rip), %rsi      # 0x1e368
leaq 0x4b36(%rip), %rdx      # 0x1e373
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0xd3d0
leaq 0x4f0b(%rip), %rsi      # 0x1e75e
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xd3d0
movq %r14, %rdi
callq 0xd140
movl %eax, %ebp
callq 0x19969
movq 0x18(%rbx), %r8
movl %ebp, (%rsp)
leaq 0x4eeb(%rip), %rdx      # 0x1e768
leaq 0x4e75(%rip), %r9       # 0x1e6f9
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
callq 0x19bf1
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a61d(%rip), %rcx     # 0x33ed0
movq (%rcx), %r8
leaq 0x4c7f(%rip), %rdx      # 0x1e53c
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 0x199b4
movl $0x1, %edi
callq 0xd3e0
xorl %edi, %edi
callq 0xd3e0