// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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;

#ifdef AOF_NO_COW
    if(server.aof_no_cow.enable)
        return rewriteAppendOnlyFileNoCow();
#endif

    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));
            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 0xa537f(%rip), %r15     # 0x106858
cmpl $-0x1, 0x68c(%r15)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jne 0x614fb
cmpl $-0x1, 0x720(%r15)
jne 0x614fb
callq 0x63433
testl %eax, %eax
je 0x6150b
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x330a5
movq %rax, %r14
callq 0x26ac0
testl %eax, %eax
je 0x61618
movl %eax, %ebp
callq 0x330a5
subq %r14, %rax
movq %rax, 0x3b8(%r15)
callq 0x3b446
movq %rax, %xmm0
punpckldq 0x6439d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x643a5(%rip), %xmm0    # 0xc58f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x643a1(%rip), %xmm1    # 0xc5900
movq 0x3b8(%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
mulsd 0x5df76(%rip), %xmm1    # 0xbf4f0
movsd %xmm1, 0x3c0(%r15)
movq 0xa08(%r15), %rcx
testq %rcx, %rcx
je 0x615be
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
cmpq %rcx, %rdx
jl 0x615be
leaq 0x645b8(%rip), %rdi     # 0xc5b6e
movq %rdx, %rsi
callq 0x825dd
cmpl $-0x1, %ebp
je 0x61686
leaq 0x673e3(%rip), %rsi     # 0xc89b1
xorl %ebx, %ebx
movl $0x2, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x32ea6
movl $0x0, 0x688(%r15)
xorl %edi, %edi
callq 0x26ce0
movq %rax, 0x6c0(%r15)
movl %ebp, 0x68c(%r15)
callq 0x3351d
movl $0xffffffff, 0x6a4(%r15) # imm = 0xFFFFFFFF
callq 0x47e38
jmp 0x614fb
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x36c98
leaq 0x672f2(%rip), %rdi     # 0xc891a
callq 0x38932
callq 0x26430
leaq 0x672f3(%rip), %rdx     # 0xc892c
movq %rsp, %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
movq %r14, %rdi
callq 0x62b71
movl $0x1, %ebp
testl %eax, %eax
jne 0x616af
callq 0x3b67c
testq %rax, %rax
je 0x616ad
shrq $0x14, %rax
leaq 0x672d3(%rip), %rsi     # 0xc8946
xorl %ebp, %ebp
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
jmp 0x616af
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x672e1(%rip), %rsi     # 0xc897a
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
jmp 0x614fb
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x33106
jmp 0x614fb