// File: /workspace/github_c_makefile_star2_O2/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, %r14
leaq 0x29f(%rip), %rbx       # 0x19347
pushq $0xf
popq %rdi
movq %rbx, %rsi
callq 0xd210
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0xd210
pushq $0x6
popq %rdi
movq %rbx, %rsi
callq 0xd210
pushq $0xb
popq %rdi
movq %rbx, %rsi
callq 0xd210
pushq $0x7
popq %rdi
movq %rbx, %rsi
callq 0xd210
pushq $0x4
popq %rdi
movq %rbx, %rsi
callq 0xd210
callq 0xd420
testl %eax, %eax
js 0x19338
jne 0x19340
xorl %edi, %edi
callq 0xd230
callq 0xd1c0
testl %eax, %eax
js 0x19338
xorl %edi, %edi
callq 0xd1b0
pushq $0x1
popq %rdi
callq 0xd1b0
pushq $0x2
popq %rdi
callq 0xd1b0
movq %r14, %rdi
callq 0x19051
movl %eax, %ebx
callq 0x193b5
testl %ebx, %ebx
js 0x19308
movq %r14, 0x8(%rsp)
leaq 0x1bd85(%rip), %r13     # 0x34ed0
movq 0x18(%r13), %r8
leaq 0x53b5(%rip), %rdx      # 0x1e50b
leaq 0x53d3(%rip), %r9       # 0x1e530
pushq $0x3
popq %rbp
movl %ebp, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
leaq 0x5534(%rip), %r15      # 0x1e6a9
leaq 0x553d(%rip), %r14      # 0x1e6b9
leaq 0x227b5(%rip), %rbx     # 0x3b938
cmpb $0x0, 0x2290e(%rip)     # 0x3ba98
jne 0x19251
xorl %eax, %eax
cmpq $0x2c, %rax
je 0x191b2
movl (%rax,%rbx), %ecx
movl %ecx, 0xe0(%rbx,%rax,2)
movw $0x1, 0xe4(%rbx,%rax,2)
addq $0x4, %rax
jmp 0x19192
callq 0x193b5
movq 0x18(%r13), %r8
movl %ebp, %edi
xorl %esi, %esi
leaq 0x54c3(%rip), %rdx      # 0x1e689
movq %rax, %rcx
movq %r15, %r9
xorl %eax, %eax
callq 0x19400
leaq 0x2283e(%rip), %rdi     # 0x3ba18
pushq $0xb
popq %rsi
pushq $-0x1
popq %rdx
callq 0xd2e0
movl %eax, %r12d
callq 0x193b5
movq 0x18(%r13), %r8
movl %r12d, (%rsp)
movl %ebp, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %rax, %rcx
movq %r15, %r9
xorl %eax, %eax
callq 0x19400
xorl %r12d, %r12d
cmpq $0xb, %r12
je 0x19183
movl 0xe0(%rbx,%r12,8), %edi
cmpl $-0x1, %edi
je 0x1924c
testb $0x1, 0xe6(%rbx,%r12,8)
je 0x1924c
andw $0x0, 0xe6(%rbx,%r12,8)
movq 0x30(%rbx,%r12,8), %rax
testq %rax, %rax
je 0x1924c
movq 0x88(%rbx,%r12,8), %rsi
callq *%rax
incq %r12
jmp 0x1920c
callq 0x193b5
movq 0x10(%r13), %r8
leaq 0x5490(%rip), %rdx      # 0x1e6f1
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
leaq 0x50(%rsp), %rbx
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd190
movq 0x8(%rsp), %rcx
addq $0x20, %rcx
leaq 0x5084(%rip), %rsi      # 0x1e318
leaq 0x5088(%rip), %rdx      # 0x1e323
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0xd3e0
leaq 0x545d(%rip), %rsi      # 0x1e70e
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xd3e0
movq %rbx, %rdi
callq 0xd140
movl %eax, %ebx
callq 0x193b5
movq 0x18(%r13), %r8
movl %ebx, (%rsp)
leaq 0x543d(%rip), %rdx      # 0x1e718
leaq 0x53c7(%rip), %r9       # 0x1e6a9
pushq $0x3
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19400
callq 0x19638
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bbc1(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x51d3(%rip), %rdx      # 0x1e4ec
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 0x19400
pushq $0x1
popq %rdi
callq 0xd3f0
xorl %edi, %edi
callq 0xd3f0