// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/replication.c
// Function: addReplyReplicationBacklog
long long addReplyReplicationBacklog(client *c, long long offset) {
    long long j, skip, len;

    serverLog(LL_DEBUG, "[PSYNC] Slave request offset: %lld", offset);

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

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

    /* Compute the amount of bytes we need to discard. */
    skip = offset - server.repl_backlog_off;
    serverLog(LL_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;
    serverLog(LL_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;
    serverLog(LL_DEBUG, "[PSYNC] Reply total length: %lld", len);
    while(len) {
        long long thislen =
            ((server.repl_backlog_size - j) < len) ?
            (server.repl_backlog_size - j) : len;

        serverLog(LL_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 0x756bf(%rip), %rsi     # 0xb2a25
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2b699
leaq 0xbc52f(%rip), %rbx     # 0xf98a8
cmpq $0x0, 0x7e0(%rbx)
je 0x3d4be
movq 0x7d8(%rbx), %rdx
leaq 0x756d7(%rip), %rsi     # 0xb2a6c
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
movq 0x7f0(%rbx), %rdx
leaq 0x756db(%rip), %rsi     # 0xb2a87
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
movq 0x7e0(%rbx), %rdx
leaq 0x756dd(%rip), %rsi     # 0xb2aa0
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
movq 0x7e8(%rbx), %rdx
leaq 0x756e0(%rip), %rsi     # 0xb2aba
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
subq 0x7f0(%rbx), %r13
leaq 0x756e5(%rip), %rsi     # 0xb2ad6
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2b699
movq 0x7d8(%rbx), %rcx
movq 0x7e8(%rbx), %rax
addq %rcx, %rax
subq 0x7e0(%rbx), %rax
cqto
idivq %rcx
movq %rdx, %r15
leaq 0x756c9(%rip), %rsi     # 0xb2aed
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
addq %r13, %r15
movq %r15, %rax
cqto
idivq 0x7d8(%rbx)
movq %rdx, %r12
movq 0x7e0(%rbx), %r15
movq %r13, (%rsp)
subq %r13, %r15
leaq 0x756bb(%rip), %rsi     # 0xb2b0f
xorl %edi, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2b699
leaq 0x756c9(%rip), %r13     # 0xb2b30
testq %r15, %r15
je 0x3d4b1
movq 0x7d8(%rbx), %rbp
subq %r12, %rbp
cmpq %r15, %rbp
cmovgeq %r15, %rbp
xorl %edi, %edi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2b699
addq 0x7d0(%rbx), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x31018
movq %r14, %rdi
movq %rax, %rsi
callq 0x36a9d
subq %rbp, %r15
xorl %r12d, %r12d
jmp 0x3d467
movq 0x7e0(%rbx), %r14
subq (%rsp), %r14
jmp 0x3d4d1
leaq 0x75583(%rip), %rsi     # 0xb2a48
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq