// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/aof.c
// Function: aofRewriteBufferAppend
void aofRewriteBufferAppend(unsigned char *s, unsigned long len) {
    listNode *ln = listLast(server.aof_rewrite_buf_blocks);
    aofrwblock *block = ln ? ln->value : NULL;

    while(len) {
        /* If we already got at least an allocated block, try appending
         * at least some piece into it. */
        if (block) {
            unsigned long thislen = (block->free < len) ? block->free : len;
            if (thislen) {  /* The current block is not already full. */
                memcpy(block->buf+block->used, s, thislen);
                block->used += thislen;
                block->free -= thislen;
                s += thislen;
                len -= thislen;
            }
        }

        if (len) { /* First block to allocate, or need another block. */
            int numblocks;

            block = zmalloc(sizeof(*block));
            block->free = AOF_RW_BUF_BLOCK_SIZE;
            block->used = 0;
            listAddNodeTail(server.aof_rewrite_buf_blocks,block);

            /* Log every time we cross more 10 or 100 blocks, respectively
             * as a notice or warning. */
            numblocks = listLength(server.aof_rewrite_buf_blocks);
            if (((numblocks+1) % 10) == 0) {
                int level = ((numblocks+1) % 100) == 0 ? LL_WARNING :
                                                         LL_NOTICE;
                serverLog(level,"Background AOF buffer size: %lu MB",
                    aofRewriteBufferSize()/(1024*1024));
            }
        }
    }

    /* Install a file event to send data to the rewrite child if there is
     * not one already. */
    if (aeGetFileEvents(server.el,server.aof_pipe_write_data_to_child) == 0) {
        aeCreateFileEvent(server.el, server.aof_pipe_write_data_to_child,
            AE_WRITABLE, aofChildWriteDiffData, NULL);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xa5df1(%rip), %r12     # 0x106858
movq 0x690(%r12), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x60a81
movq 0x10(%rax), %r15
jmp 0x60b50
xorl %r15d, %r15d
jmp 0x60b50
testq %r15, %r15
je 0x60ac1
movq 0x8(%r15), %r13
testq %r13, %r13
je 0x60ac1
cmpq %rbx, %r13
cmovaeq %rbx, %r13
movq (%r15), %rax
leaq (%r15,%rax), %rdi
addq $0x10, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x26c60
addq %r13, (%r15)
subq %r13, 0x8(%r15)
addq %r13, %r14
subq %r13, %rbx
testq %rbx, %rbx
je 0x60b50
movl $0xa00010, %edi         # imm = 0xA00010
callq 0x3b29d
movq %rax, %r15
movq $0xa00000, 0x8(%rax)    # imm = 0xA00000
movq $0x0, (%rax)
movq 0x690(%r12), %rdi
movq %rax, %rsi
callq 0x2e40f
movq 0x690(%r12), %rax
movl 0x28(%rax), %eax
imull $0xcccccccd, %eax, %ecx # imm = 0xCCCCCCCD
addl $0xe6666665, %ecx       # imm = 0xE6666665
rorl %ecx
cmpl $0x19999998, %ecx       # imm = 0x19999998
ja 0x60b50
incl %eax
imull $0xc28f5c29, %eax, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c29, %eax        # imm = 0x28F5C29
movl $0x0, %ebp
adcl $0x2, %ebp
callq 0x60942
shrq $0x14, %rax
movl %ebp, %edi
leaq 0x6738a(%rip), %rsi     # 0xc7ed0
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
testq %rbx, %rbx
jne 0x60a89
movq 0x40(%r12), %rdi
movl 0x6e8(%r12), %esi
callq 0x30078
testl %eax, %eax
je 0x60b7e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%r12), %rdi
movl 0x6e8(%r12), %esi
leaq -0x1fb(%rip), %rcx      # 0x60997
movl $0x2, %edx
xorl %r8d, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2fee7