// File: /workspace/github_c_makefile_star2_O3/zhou-yuxin[P]redis-aof-no-cow/src/aof.c
// Function: feedAppendOnlyFile
void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int argc) {
#ifdef AOF_NO_COW
    sds select_buf = NULL;
#endif
    sds buf = sdsempty();
    robj *tmpargv[3];

    /* The DB this command was targeting is not the same as the last command
     * we appended. To issue a SELECT command is needed. */
    if (dictid != server.aof_selected_db) {
        char seldb[64];

        snprintf(seldb,sizeof(seldb),"%d",dictid);
        buf = sdscatprintf(buf,"*2\r\n$6\r\nSELECT\r\n$%lu\r\n%s\r\n",
            (unsigned long)strlen(seldb),seldb);
        server.aof_selected_db = dictid;
#ifdef AOF_NO_COW
        if(server.aof_child_pid != -1 && server.aof_no_cow.enable)
        {
            select_buf = buf;
            buf = sdsempty();
        }
#endif
    }

    if (cmd->proc == expireCommand || cmd->proc == pexpireCommand ||
        cmd->proc == expireatCommand) {
        /* Translate EXPIRE/PEXPIRE/EXPIREAT into PEXPIREAT */
        buf = catAppendOnlyExpireAtCommand(buf,cmd,argv[1],argv[2]);
    } else if (cmd->proc == setexCommand || cmd->proc == psetexCommand) {
        /* Translate SETEX/PSETEX to SET and PEXPIREAT */
        tmpargv[0] = createStringObject("SET",3);
        tmpargv[1] = argv[1];
        tmpargv[2] = argv[3];
        buf = catAppendOnlyGenericCommand(buf,3,tmpargv);
        decrRefCount(tmpargv[0]);
        buf = catAppendOnlyExpireAtCommand(buf,cmd,argv[1],argv[2]);
    } else {
        /* All the other commands don't need translation or need the
         * same translation already operated in the command vector
         * for the replication itself. */
        buf = catAppendOnlyGenericCommand(buf,argc,argv);
    }

    /* Append to the AOF buffer. This will be flushed on disk just before
     * of re-entering the event loop, so before the client will get a
     * positive reply about the operation performed. */
    if (server.aof_state == AOF_ON)
#ifndef AOF_NO_COW
        server.aof_buf = sdscatlen(server.aof_buf,buf,sdslen(buf));
#else
    {
        if(select_buf)
            server.aof_buf = sdscatlen(server.aof_buf, select_buf, sdslen(select_buf));
        server.aof_buf = sdscatlen(server.aof_buf, buf, sdslen(buf));
    }
#endif

    /* If a background append only file rewriting is in progress we want to
     * accumulate the differences between the child DB and the current one
     * in a buffer, so that when the child process will do its work we
     * can append the differences to the new append only file. */
    if (server.aof_child_pid != -1)
#ifndef AOF_NO_COW
        aofRewriteBufferAppend((unsigned char*)buf,sdslen(buf));
#else
    {
        if(server.aof_no_cow.enable)
        {
            if(!aofNoCowSelectDB(dictid))
                goto werr;
            int ret;
            PROTECTED_BY_SPINLOCK(ret, server.aof_no_cow.lock,
                rioWrite(&(server.aof_no_cow.pipe), buf, sdslen(buf)));
            if(!ret)
                goto werr;
        }
        else
        {
            if(select_buf)
                aofRewriteBufferAppend((unsigned char*)select_buf, sdslen(select_buf));
            aofRewriteBufferAppend((unsigned char*)buf, sdslen(buf));
        }
    }
#endif
    sdsfree(buf);

#ifdef AOF_NO_COW
    if(select_buf)
        sdsfree(select_buf);
    return;

werr:
    serverLog(LL_WARNING, "Error writing pipe in feedAppendOnlyFile()");
    server.aof_no_cow.error = 1;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %r13d
movq %rdx, %rbx
movl %esi, %r12d
movq %rdi, %r14
callq 0x394a5
movq %rax, %r15
leaq 0xa59d8(%rip), %rbp     # 0x106858
cmpl %r12d, 0x6a4(%rbp)
je 0x60edb
leaq 0x68be0(%rip), %rdx     # 0xc9a70
movl %r13d, %ebp
movq %rsp, %r13
movl $0x40, %esi
movq %r13, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x26120
movq %r13, %rdi
callq 0x26510
leaq 0x674be(%rip), %rsi     # 0xc8375
movq %r15, %rdi
movq %rax, %rdx
movq %r13, %rcx
movl %ebp, %r13d
leaq 0xa598e(%rip), %rbp     # 0x106858
xorl %eax, %eax
callq 0x3a145
movq %rax, %r15
movl %r12d, 0x6a4(%rbp)
movq 0x8(%r14), %rax
cmpq 0xa10ea(%rip), %rax     # 0x101fd0
je 0x60f54
cmpq 0xa1039(%rip), %rax     # 0x101f28
je 0x60f54
cmpq 0xa10b8(%rip), %rax     # 0x101fb0
je 0x60f54
cmpq 0xa10df(%rip), %rax     # 0x101fe0
setne %cl
cmpq 0xa107d(%rip), %rax     # 0x101f88
setne %al
testb %al, %cl
jne 0x60f69
leaq 0x6f42b(%rip), %rdi     # 0xd0344
movl $0x3, %esi
callq 0x43944
movq %rax, %r12
movq %rsp, %rdx
movq %rax, (%rdx)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rdx)
movq 0x18(%rbx), %rax
movq %rax, 0x10(%rdx)
movq %r15, %rdi
movl $0x3, %esi
callq 0x60c03
movq %rax, %r15
movq %r12, %rdi
callq 0x43e8f
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x60d62
jmp 0x60f77
movq %r15, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x60c03
movq %rax, %rbx
cmpl $0x1, 0x658(%rbp)
jne 0x60fd5
movq 0x698(%rbp), %rdi
movzbl -0x1(%rbx), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x60fc4
leaq 0x66f1d(%rip), %rcx     # 0xc7ebc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x60fc6
movq -0x11(%rbx), %rdx
jmp 0x60fc6
movzwl -0x5(%rbx), %edx
jmp 0x60fc6
movl -0x9(%rbx), %edx
jmp 0x60fc6
movzbl -0x3(%rbx), %edx
jmp 0x60fc6
xorl %edx, %edx
movq %rbx, %rsi
callq 0x39ce9
movq %rax, 0x698(%rbp)
cmpl $-0x1, 0x68c(%rbp)
je 0x61022
movzbl -0x1(%rbx), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x61018
leaq 0x66edd(%rip), %rcx     # 0xc7ed0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x6101a
movq -0x11(%rbx), %rsi
jmp 0x6101a
movzwl -0x5(%rbx), %esi
jmp 0x6101a
movl -0x9(%rbx), %esi
jmp 0x6101a
movzbl -0x3(%rbx), %esi
jmp 0x6101a
xorl %esi, %esi
movq %rbx, %rdi
callq 0x5ff63
movq %rbx, %rdi
callq 0x39548
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq