// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/aof.c
// Function: rewriteAppendOnlyFileBackground
int rewriteAppendOnlyFileBackground(void) {
    pid_t childpid;
    long long start;

    if (server.aof_child_pid != -1 || server.rdb_child_pid != -1) return C_ERR;
    if (aofCreatePipes() != C_OK) return C_ERR;
    start = ustime();
    if ((childpid = fork()) == 0) {
        char tmpfile[256];

        /* Child */
        closeListeningSockets(0);
        redisSetProcTitle("redis-aof-rewrite");
        snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
        if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
            size_t private_dirty = zmalloc_get_private_dirty();

            if (private_dirty) {
                serverLog(LL_NOTICE,
                    "AOF rewrite: %zu MB of memory used by copy-on-write",
                    private_dirty/(1024*1024));
            }
            exitFromChild(0);
        } else {
            exitFromChild(1);
        }
    } else {
        /* Parent */
        server.stat_fork_time = ustime()-start;
        server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
        latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
        if (childpid == -1) {
            serverLog(LL_WARNING,
                "Can't rewrite append only file in background: fork: %s",
                strerror(errno));
            aofClosePipes();
            return C_ERR;
        }
        serverLog(LL_NOTICE,
            "Background append only file rewriting started by pid %d",childpid);
        server.aof_rewrite_scheduled = 0;
        server.aof_rewrite_time_start = time(NULL);
        server.aof_child_pid = childpid;
        updateDictResizePolicy();
        /* We set appendseldb to -1 in order to force the next call to the
         * feedAppendOnlyFile() to issue a SELECT command, so the differences
         * accumulated by the parent into server.aof_rewrite_buf will start
         * with a SELECT statement and it will be safe to merge. */
        server.aof_selected_db = -1;
        replicationScriptCacheFlush();
        return C_OK;
    }
    return C_OK; /* unreached */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
leaq 0xa3fe3(%rip), %r15     # 0x1018a8
cmpl $-0x1, 0x69c(%r15)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jne 0x5d8e7
cmpl $-0x1, 0x730(%r15)
jne 0x5d8e7
callq 0x5f85a
testl %eax, %eax
je 0x5d8f7
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x2ffab
movq %rax, %r14
callq 0x26ab0
testl %eax, %eax
je 0x5da04
movl %eax, %ebp
callq 0x2ffab
subq %r14, %rax
movq %rax, 0x3c8(%r15)
callq 0x3847a
movq %rax, %xmm0
punpckldq 0x65031(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x65039(%rip), %xmm0    # 0xc2970
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x65035(%rip), %xmm1    # 0xc2980
movq 0x3c8(%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
mulsd 0x5ebda(%rip), %xmm1    # 0xbc540
movsd %xmm1, 0x3d0(%r15)
movq 0xa18(%r15), %rcx
testq %rcx, %rcx
je 0x5d9aa
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
cmpq %rcx, %rdx
jl 0x5d9aa
leaq 0x6524c(%rip), %rdi     # 0xc2bee
movq %rdx, %rsi
callq 0x7eb75
cmpl $-0x1, %ebp
je 0x5da72
leaq 0x68078(%rip), %rsi     # 0xc5a32
xorl %ebx, %ebx
movl $0x2, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2fdad
movl $0x0, 0x698(%r15)
xorl %edi, %edi
callq 0x26cd0
movq %rax, 0x6d0(%r15)
movl %ebp, 0x69c(%r15)
callq 0x30423
movl $0xffffffff, 0x6b4(%r15) # imm = 0xFFFFFFFF
callq 0x44c36
jmp 0x5d8e7
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x33c2a
leaq 0x67f87(%rip), %rdi     # 0xc599b
callq 0x3598c
callq 0x26420
leaq 0x67f88(%rip), %rdx     # 0xc59ad
movq %rsp, %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
movq %r14, %rdi
callq 0x5f033
movl $0x1, %ebp
testl %eax, %eax
jne 0x5daa0
callq 0x386a8
testq %rax, %rax
je 0x5da9e
shrq $0x14, %rax
leaq 0x67f68(%rip), %rsi     # 0xc59c7
xorl %ebp, %ebp
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
jmp 0x5daa0
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x67f76(%rip), %rsi     # 0xc59fb
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
callq 0x5d713
jmp 0x5d8e7
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x3000c
jmp 0x5d8e7