// File: /workspace/github_c_makefile_star2_O1/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 0x39222
movq %rax, %r15
leaq 0xa4ee8(%rip), %rbp     # 0x106858
cmpl %r12d, 0x6a4(%rbp)
je 0x619cb
leaq 0x680d4(%rip), %rdx     # 0xc9a54
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 0x66992(%rip), %rsi     # 0xc8339
movq %r15, %rdi
movq %rax, %rdx
movq %r13, %rcx
movl %ebp, %r13d
leaq 0xa4e9e(%rip), %rbp     # 0x106858
xorl %eax, %eax
callq 0x39eb7
movq %rax, %r15
movl %r12d, 0x6a4(%rbp)
movq 0x8(%r14), %rax
cmpq 0xa05fa(%rip), %rax     # 0x101fd0
je 0x61a44
cmpq 0xa0549(%rip), %rax     # 0x101f28
je 0x61a44
cmpq 0xa05c8(%rip), %rax     # 0x101fb0
je 0x61a44
cmpq 0xa05ef(%rip), %rax     # 0x101fe0
setne %cl
cmpq 0xa058d(%rip), %rax     # 0x101f88
setne %al
testb %al, %cl
jne 0x61a59
leaq 0x6e8ab(%rip), %rdi     # 0xd02b4
movl $0x3, %esi
callq 0x43ba8
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 0x616f3
movq %rax, %r15
movq %r12, %rdi
callq 0x440f3
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x61852
jmp 0x61a67
movq %r15, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x616f3
movq %rax, %rbx
cmpl $0x1, 0x658(%rbp)
jne 0x61ac5
movq 0x698(%rbp), %rdi
movzbl -0x1(%rbx), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x61ab4
leaq 0x663f1(%rip), %rcx     # 0xc7e80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x61ab6
movq -0x11(%rbx), %rdx
jmp 0x61ab6
movzwl -0x5(%rbx), %edx
jmp 0x61ab6
movl -0x9(%rbx), %edx
jmp 0x61ab6
movzbl -0x3(%rbx), %edx
jmp 0x61ab6
xorl %edx, %edx
movq %rbx, %rsi
callq 0x39a56
movq %rax, 0x698(%rbp)
cmpl $-0x1, 0x68c(%rbp)
je 0x61b12
movzbl -0x1(%rbx), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x61b08
leaq 0x663b1(%rip), %rcx     # 0xc7e94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x61b0a
movq -0x11(%rbx), %rsi
jmp 0x61b0a
movzwl -0x5(%rbx), %esi
jmp 0x61b0a
movl -0x9(%rbx), %esi
jmp 0x61b0a
movzbl -0x3(%rbx), %esi
jmp 0x61b0a
xorl %esi, %esi
movq %rbx, %rdi
callq 0x60a4f
movq %rbx, %rdi
callq 0x392b6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq