// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: addReplyReplicationBacklog
long long addReplyReplicationBacklog(redisClient *c, long long offset) {
    long long j, skip, len;

    redisLog(REDIS_DEBUG, "[PSYNC] Slave request offset: %lld", offset);

    if (server.repl_backlog_histlen == 0) {
        redisLog(REDIS_DEBUG, "[PSYNC] Backlog history len is zero");
        return 0;
    }

    redisLog(REDIS_DEBUG, "[PSYNC] Backlog size: %lld",
             server.repl_backlog_size);
    redisLog(REDIS_DEBUG, "[PSYNC] First byte: %lld",
             server.repl_backlog_off);
    redisLog(REDIS_DEBUG, "[PSYNC] History len: %lld",
             server.repl_backlog_histlen);
    redisLog(REDIS_DEBUG, "[PSYNC] Current index: %lld",
             server.repl_backlog_idx);

    /* Compute the amount of bytes we need to discard. */
    skip = offset - server.repl_backlog_off;
    redisLog(REDIS_DEBUG, "[PSYNC] Skipping: %lld", skip);

    /* Point j to the oldest byte, that is actaully our
     * server.repl_backlog_off byte. */
    j = (server.repl_backlog_idx +
        (server.repl_backlog_size-server.repl_backlog_histlen)) %
        server.repl_backlog_size;
    redisLog(REDIS_DEBUG, "[PSYNC] Index of first byte: %lld", j);

    /* Discard the amount of data to seek to the specified 'offset'. */
    j = (j + skip) % server.repl_backlog_size;

    /* Feed slave with data. Since it is a circular buffer we have to
     * split the reply in two parts if we are cross-boundary. */
    len = server.repl_backlog_histlen - skip;
    redisLog(REDIS_DEBUG, "[PSYNC] Reply total length: %lld", len);
    while(len) {
        long long thislen =
            ((server.repl_backlog_size - j) < len) ?
            (server.repl_backlog_size - j) : len;

        redisLog(REDIS_DEBUG, "[PSYNC] addReply() length: %lld", thislen);
        addReplySds(c,sdsnewlen(server.repl_backlog + j, thislen));
        len -= thislen;
        j = 0;
    }
    return server.repl_backlog_histlen - skip;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r13
movq %rdi, %r14
leaq 0x6409d(%rip), %rsi     # 0x977b5
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x23064
leaq 0x9687d(%rip), %rbp     # 0xc9fa8
cmpq $0x0, 0x610(%rbp)
je 0x33877
movq 0x608(%rbp), %rdx
leaq 0x640b5(%rip), %rsi     # 0x977fc
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq 0x620(%rbp), %rdx
leaq 0x640b9(%rip), %rsi     # 0x97817
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq 0x610(%rbp), %rdx
leaq 0x640bb(%rip), %rsi     # 0x97830
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq 0x618(%rbp), %rdx
leaq 0x640be(%rip), %rsi     # 0x9784a
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
subq 0x620(%rbp), %r13
leaq 0x640c3(%rip), %rsi     # 0x97866
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x23064
movq 0x608(%rbp), %rcx
movq 0x618(%rbp), %rax
addq %rcx, %rax
subq 0x610(%rbp), %rax
cqto
idivq %rcx
movq %rdx, %r15
leaq 0x640a7(%rip), %rsi     # 0x9787d
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq 0x608(%rbp), %r12
movq 0x610(%rbp), %rbx
leaq 0x640ab(%rip), %rsi     # 0x9789f
movq %rbx, %rdx
subq %r13, %rdx
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq %r13, (%rsp)
subq %r13, %rbx
je 0x3386a
addq (%rsp), %r15
movq %r15, %rax
cqto
idivq %r12
movq %rdx, %r12
leaq 0x6409e(%rip), %r15     # 0x978c0
movq 0x608(%rbp), %r13
subq %r12, %r13
cmpq %rbx, %r13
cmovgeq %rbx, %r13
xorl %edi, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x23064
addq 0x600(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x28148
movq %r14, %rdi
movq %rax, %rsi
callq 0x2d894
movl $0x0, %r12d
subq %r13, %rbx
jne 0x33822
movq 0x610(%rbp), %r14
subq (%rsp), %r14
jmp 0x3388a
leaq 0x63f5a(%rip), %rsi     # 0x977d8
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
callq 0x23064
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq