// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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, %r12
movq %rdi, %rbx
leaq 0xa5fb6(%rip), %rax     # 0xf98a8
movq 0x6a0(%rax), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x53908
movq 0x10(%rax), %r15
jmp 0x5390b
xorl %r15d, %r15d
leaq 0x10(%r15), %r14
movq %r12, %rbp
testq %rbp, %rbp
je 0x539dc
testq %r15, %r15
je 0x5395a
movq 0x8(%r15), %r13
testq %r13, %r13
je 0x5395a
cmpq %rbp, %r13
cmovaeq %rbp, %r13
movq (%r15), %rdi
addq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x26c50
addq %r13, (%r15)
subq %r13, 0x8(%r15)
addq %r13, %rbx
movq %rbp, %r12
movl $0x0, %ebp
subq %r13, %r12
je 0x53912
jmp 0x5395d
movq %rbp, %r12
movl $0xa00010, %edi         # imm = 0xA00010
callq 0x327b9
movq %rax, %r15
movq $0xa00000, 0x8(%rax)    # imm = 0xA00000
andq $0x0, (%rax)
leaq 0xa5f2b(%rip), %r14     # 0xf98a8
movq 0x6a0(%r14), %rdi
movq %rax, %rsi
callq 0x26ecc
movq 0x6a0(%r14), %rax
movl 0x28(%rax), %ecx
incl %ecx
movl %ecx, %eax
cltd
pushq $0xa
popq %rsi
idivl %esi
testl %edx, %edx
jne 0x5390b
movl %ecx, %eax
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl $0x1, %edx
movl $0x0, %ebp
adcl $0x2, %ebp
callq 0x537ca
shrq $0x14, %rax
movl %ebp, %edi
leaq 0x6285b(%rip), %rsi     # 0xb6228
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x5390b
leaq 0xa5ec5(%rip), %rbx     # 0xf98a8
movq 0x40(%rbx), %rdi
movl 0x6f8(%rbx), %esi
callq 0x28c68
testl %eax, %eax
je 0x53a05
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rbx), %rdi
movl 0x6f8(%rbx), %esi
leaq -0x206(%rip), %rcx      # 0x53810
pushq $0x2
popq %rdx
xorl %r8d, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28ae8