// File: /workspace/github_c_makefile_star2_O2/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 0xa56a2(%rip), %r15     # 0xf98a8
cmpl $-0x1, 0x69c(%r15)
pushq $-0x1
popq %rbx
jne 0x54226
cmpl $-0x1, 0x730(%r15)
jne 0x54226
callq 0x55dc4
testl %eax, %eax
je 0x54236
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x2b88b
movq %rax, %r14
callq 0x26ab0
testl %eax, %eax
je 0x54327
movl %eax, %ebp
callq 0x2b88b
subq %r14, %rax
movq %rax, 0x3c8(%r15)
callq 0x32960
movq %rax, %xmm0
punpckldq 0x5fdb2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5fdba(%rip), %xmm0    # 0xb4030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x5fdb6(%rip), %xmm1    # 0xb4040
movq 0x3c8(%r15), %rax
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
mulsd 0x5a18e(%rip), %xmm1    # 0xae430
movsd %xmm1, 0x3d0(%r15)
movq 0xa18(%r15), %rcx
testq %rcx, %rcx
je 0x542d5
movl $0x3e8, %esi            # imm = 0x3E8
cqto
idivq %rsi
cmpq %rcx, %rax
jl 0x542d5
leaq 0x5ffe1(%rip), %rdi     # 0xb42ae
movq %rax, %rsi
callq 0x71e85
cmpl $-0x1, %ebp
je 0x5436d
leaq 0x62a39(%rip), %rsi     # 0xb6d1e
xorl %ebx, %ebx
pushq $0x2
popq %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2b699
andl $0x0, 0x698(%r15)
xorl %edi, %edi
callq 0x26cd0
movq %rax, 0x6d0(%r15)
movl %ebp, 0x69c(%r15)
callq 0x2bb7f
orl $-0x1, 0x6b4(%r15)
callq 0x3d949
jmp 0x54226
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x2edf6
leaq 0x62950(%rip), %rdi     # 0xb6c87
callq 0x308b2
callq 0x26420
leaq 0x62951(%rip), %rdx     # 0xb6c99
movq %rsp, %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
movq %r14, %rdi
callq 0x55709
testl %eax, %eax
je 0x54397
pushq $0x1
popq %rbp
jmp 0x543bf
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x62967(%rip), %rsi     # 0xb6ce7
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
callq 0x54062
jmp 0x54226
callq 0x32b90
testq %rax, %rax
je 0x543bd
shrq $0x14, %rax
leaq 0x62907(%rip), %rsi     # 0xb6cb3
xorl %ebp, %ebp
pushq $0x2
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x543bf
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x2b8c0
jmp 0x54226