// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movl %edx, 0xd4(%rsp)
callq 0x6c60
movl %eax, %ecx
movl %ecx, 0x3c(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x18ddb
movq 0xa22f(%rip), %rax      # 0x22fc8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x18dd1
movq 0xa1f8(%rip), %rax      # 0x22fa0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x60a0
movl (%rax), %edi
callq 0x6be0
movq 0x28(%rsp), %rcx
movq %rax, %rdx
xorl %edi, %edi
leaq 0x5698(%rip), %rsi      # 0x1e465
movb $0x0, %al
callq *%rcx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x6ae0
xorl %eax, %eax
cmpl 0x3c(%rsp), %eax
je 0x18dea
xorl %edi, %edi
callq 0x6ae0
callq 0x64b0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x18e43
movq 0xa1c7(%rip), %rax      # 0x22fc8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x18e39
movq 0xa190(%rip), %rax      # 0x22fa0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x60a0
movl (%rax), %edi
callq 0x6be0
movq 0x20(%rsp), %rcx
movq %rax, %rdx
xorl %edi, %edi
leaq 0x5642(%rip), %rsi      # 0x1e477
movb $0x0, %al
callq *%rcx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x6ae0
callq 0x6c70
movl %eax, 0x38(%rsp)
cmpl $0x2, 0x38(%rsp)
jle 0x18ec6
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jge 0x18e9e
movq 0xd8(%rsp), %rax
movslq 0xcc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x38(%rsp), %eax
jne 0x18e89
jmp 0x18e9e
jmp 0x18e8b
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x18e5e
movl 0xcc(%rsp), %eax
cmpl 0xd4(%rsp), %eax
jne 0x18eb7
movl 0x38(%rsp), %edi
callq 0x6470
jmp 0x18eb9
movl 0x38(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x18e4c
cmpq $0x0, 0xe0(%rsp)
jne 0x18efc
leaq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x61e0
movq 0x18(%rsp), %rdi
movl %eax, %ecx
movl $0x80, %esi
leaq 0x559d(%rip), %rdx      # 0x1e490
movb $0x0, %al
callq 0x6360
jmp 0x18f15
leaq 0x40(%rsp), %rdi
movq 0xe0(%rsp), %rdx
movl $0x80, %esi
movb $0x0, %al
callq 0x6360
leaq 0x40(%rsp), %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x6900
movl %eax, %ecx
movl %ecx, 0xd0(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x18f86
movq 0xa084(%rip), %rax      # 0x22fc8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x18f7c
movq 0xa04d(%rip), %rax      # 0x22fa0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x60a0
movl (%rax), %edi
callq 0x6be0
movq 0x10(%rsp), %rcx
movq %rax, %rdx
xorl %edi, %edi
leaq 0x5532(%rip), %rsi      # 0x1e4aa
movb $0x0, %al
callq *%rcx
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
callq 0x6ae0
leaq 0x40(%rsp), %rdi
movl $0x1a4, %esi            # imm = 0x1A4
callq 0x68e0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x18fe9
movq 0xa021(%rip), %rax      # 0x22fc8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x18fdf
movq 0x9fea(%rip), %rax      # 0x22fa0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x60a0
movl (%rax), %edi
callq 0x6be0
movq 0x8(%rsp), %rcx
movq %rax, %rdx
xorl %edi, %edi
leaq 0x54fa(%rip), %rsi      # 0x1e4d5
movb $0x0, %al
callq *%rcx
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0x6ae0
movl $0x0, 0x34(%rsp)
cmpl $0x3, 0x34(%rsp)
jge 0x19069
movl 0xd0(%rsp), %edi
movl 0x34(%rsp), %esi
callq 0x6300
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x1905a
movq 0x9fae(%rip), %rax      # 0x22fc8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x19050
movq 0x9f77(%rip), %rax      # 0x22fa0
movq (%rax), %rax
movq %rax, (%rsp)
callq 0x60a0
movl (%rax), %edi
callq 0x6be0
movq (%rsp), %rcx
movq %rax, %rdx
xorl %edi, %edi
leaq 0x54bb(%rip), %rsi      # 0x1e507
movb $0x0, %al
callq *%rcx
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0x6ae0
jmp 0x1905c
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x18ff1
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)