// File: /workspace/github_c_makefile_star2_O1/sharpyfox[P]citrusleaf-client/src/cf_service.c
// Function: cf_process_daemonize
void
cf_process_daemonize(const char *redirect_file, int *fd_ignore_list, int list_size)
{
    int FD, j;
    char cfile[128];
    pid_t p;
 
    /* Fork ourselves, then let the parent expire */
    if (-1 == (p = fork())){
    	cf_error("Couldn't fork: %s", strerror(errno));
//      cf_crash(CF_MISC, CF_GLOBAL, CF_CRITICAL, "couldn't fork: %s", cf_strerror(errno));
        exit(-1);
    }
    if (0 != p)
        exit(0);

    /* Get a new session */
    if (-1 == setsid()){
    	cf_error("Couldn't set session: %s", strerror(errno));
        exit(-2);
//      cf_crash(CF_MISC, CF_GLOBAL, CF_CRITICAL, "couldn't set session: %s", cf_strerror(errno));
    }

    /* Drop all the file descriptors except the ones in fd_ignore_list*/
    for (int i = getdtablesize(); i > 2; i--) {
	for (j = 0; j < list_size; j++) {
	    if (fd_ignore_list[j] == i) {
		break;
	    }
	}
	if(j ==  list_size) {
	    close(i);
	}
    }


    /* Open a temporary file for console message redirection */
    if (redirect_file == NULL){ 
        snprintf(cfile, 128, "/tmp/aerospike-console.%d", getpid());
    }else{
        snprintf(cfile, 128, redirect_file);
    }
    if (-1 == (FD = open(cfile, O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR))){
        cf_error("Couldn't open console redirection file: %s", strerror(errno));
//        cf_crash(CF_MISC, CF_GLOBAL, CF_CRITICAL, "couldn't open console redirection file: %s", cf_strerror(errno));
        exit(-3);
    }
    if (-1 == chmod(cfile, (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))){
    	cf_error("Couldn't set mode on console redirection file: %s", strerror(errno));
//        cf_crash(CF_MISC, CF_GLOBAL, CF_CRITICAL, "couldn't set mode on console redirection file: %s", cf_strerror(errno));
        exit(-4);
    }

    /* Redirect stdout, stderr, and stdin to the console file */
    for (int i = 0; i < 3; i++) {
        if (-1 == dup2(FD, i)){
        	cf_error("Couldn't duplicate FD: %s", strerror(errno));
//            cf_crash(CF_MISC, CF_GLOBAL, CF_CRITICAL, "couldn't duplicate FD: %s", cf_strerror(errno));
            exit(-5);
        }
    }

     return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x6ba0
testl %eax, %eax
jne 0x1137c
callq 0x6470
cmpl $-0x1, %eax
je 0x113c4
callq 0x6bb0
cmpl $0x3, %eax
jl 0x112ae
movl %eax, %r15d
movl %ebp, %r12d
testl %ebp, %ebp
movl $0x0, %eax
jle 0x11295
xorl %eax, %eax
cmpl %r15d, (%r14,%rax,4)
je 0x11295
incq %rax
cmpq %rax, %r12
jne 0x11284
movl %r12d, %eax
cmpl %ebp, %eax
jne 0x112a1
movl %r15d, %edi
callq 0x6430
cmpl $0x3, %r15d
leal -0x1(%r15), %eax
movl %eax, %r15d
jg 0x11279
testq %rbx, %rbx
je 0x112c7
movq %rsp, %rdi
movl $0x80, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6330
jmp 0x112e4
callq 0x61e0
leaq 0x419d(%rip), %rdx      # 0x15470
movq %rsp, %rdi
movl $0x80, %esi
movl %eax, %ecx
xorl %eax, %eax
callq 0x6330
movq %rsp, %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x6890
cmpl $-0x1, %eax
je 0x11400
movl %eax, %ebx
movq %rsp, %rdi
movl $0x1a4, %esi            # imm = 0x1A4
callq 0x6870
cmpl $-0x1, %eax
je 0x1143c
xorl %ebp, %ebp
movl %ebx, %edi
movl %ebp, %esi
callq 0x62d0
cmpl $-0x1, %eax
je 0x11340
incl %ebp
cmpl $0x3, %ebp
jne 0x1131b
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x9c81(%rip), %rax      # 0x1afc8
cmpl $0x0, (%rax)
js 0x11372
movq 0x9c4d(%rip), %rax      # 0x1afa0
movq (%rax), %rbx
callq 0x60a0
movl (%rax), %edi
callq 0x6b20
leaq 0x417e(%rip), %rsi      # 0x154e7
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq *%rbx
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0x6a40
cmpl $-0x1, %eax
jne 0x113bd
movq 0x9c40(%rip), %rax      # 0x1afc8
cmpl $0x0, (%rax)
js 0x113b3
movq 0x9c0c(%rip), %rax      # 0x1afa0
movq (%rax), %rbx
callq 0x60a0
movl (%rax), %edi
callq 0x6b20
leaq 0x409b(%rip), %rsi      # 0x15445
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq *%rbx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x6a40
xorl %edi, %edi
callq 0x6a40
movq 0x9bfd(%rip), %rax      # 0x1afc8
cmpl $0x0, (%rax)
js 0x113f6
movq 0x9bc9(%rip), %rax      # 0x1afa0
movq (%rax), %rbx
callq 0x60a0
movl (%rax), %edi
callq 0x6b20
leaq 0x406a(%rip), %rsi      # 0x15457
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq *%rbx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x6a40
movq 0x9bc1(%rip), %rax      # 0x1afc8
cmpl $0x0, (%rax)
js 0x11432
movq 0x9b8d(%rip), %rax      # 0x1afa0
movq (%rax), %rbx
callq 0x60a0
movl (%rax), %edi
callq 0x6b20
leaq 0x4061(%rip), %rsi      # 0x1548a
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq *%rbx
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
callq 0x6a40
movq 0x9b85(%rip), %rax      # 0x1afc8
cmpl $0x0, (%rax)
js 0x1146e
movq 0x9b51(%rip), %rax      # 0x1afa0
movq (%rax), %rbx
callq 0x60a0
movl (%rax), %edi
callq 0x6b20
leaq 0x4050(%rip), %rsi      # 0x154b5
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq *%rbx
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0x6a40