// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
callq 0x38480
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
leaq 0x11c67c(%rip), %rcx    # 0x18e198
cmpl 0x6a4(%rcx), %eax
je 0x71b82
leaq -0x80(%rbp), %rdi
movl -0xc(%rbp), %ecx
movl $0x40, %esi
leaq 0xe2251(%rip), %rdx     # 0x153d88
movb $0x0, %al
callq 0x26120
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x26500
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq -0x80(%rbp), %rcx
leaq 0xe0c0a(%rip), %rsi     # 0x152771
movb $0x0, %al
callq 0x39540
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %ecx
leaq 0x11c61c(%rip), %rax    # 0x18e198
movl %ecx, 0x6a4(%rax)
movq -0x8(%rbp), %rax
leaq -0x2512d(%rip), %rcx    # 0x4ca60
cmpq %rcx, 0x8(%rax)
je 0x71bb5
movq -0x8(%rbp), %rax
leaq -0x250de(%rip), %rcx    # 0x4cac0
cmpq %rcx, 0x8(%rax)
je 0x71bb5
movq -0x8(%rbp), %rax
leaq -0x2511f(%rip), %rcx    # 0x4ca90
cmpq %rcx, 0x8(%rax)
jne 0x71bdb
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
callq 0x719b0
movq %rax, -0x28(%rbp)
jmp 0x71c82
movq -0x8(%rbp), %rax
leaq -0x1a0a6(%rip), %rcx    # 0x57b40
cmpq %rcx, 0x8(%rax)
je 0x71bfd
movq -0x8(%rbp), %rax
leaq -0x1a037(%rip), %rcx    # 0x57bc0
cmpq %rcx, 0x8(%rax)
jne 0x71c6c
leaq 0xe846c(%rip), %rdi     # 0x15a070
movl $0x3, %esi
callq 0x48630
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movl $0x3, %esi
callq 0x71840
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rdi
callq 0x48f00
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
callq 0x719b0
movq %rax, -0x28(%rbp)
jmp 0x71c80
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x71840
movq %rax, -0x28(%rbp)
jmp 0x71c82
leaq 0x11c50f(%rip), %rax    # 0x18e198
cmpl $0x1, 0x658(%rax)
jne 0x71ce2
leaq 0x11c4ff(%rip), %rax    # 0x18e198
movq 0x698(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rdi
callq 0x716c0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq %rax, %rdx
callq 0x38fd0
movq %rax, %rcx
leaq 0x11c4bd(%rip), %rax    # 0x18e198
movq %rcx, 0x698(%rax)
leaq 0x11c4af(%rip), %rax    # 0x18e198
cmpl $-0x1, 0x68c(%rax)
je 0x71d15
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x716c0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x70620
movq -0x28(%rbp), %rdi
callq 0x385b0
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)