// File: /workspace/github_c_makefile_star2_O3/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 0x7ccdc(%rip), %rsi     # 0xc12d5
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2fdad
leaq 0xbd29c(%rip), %rbp     # 0x1018a8
cmpq $0x0, 0x7e0(%rbp)
je 0x44758
movq 0x7d8(%rbp), %rdx
leaq 0x7ccf4(%rip), %rsi     # 0xc131c
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x7f0(%rbp), %rdx
leaq 0x7ccf8(%rip), %rsi     # 0xc1337
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x7e0(%rbp), %rdx
leaq 0x7ccfa(%rip), %rsi     # 0xc1350
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x7e8(%rbp), %rdx
leaq 0x7ccfd(%rip), %rsi     # 0xc136a
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
subq 0x7f0(%rbp), %r13
leaq 0x7cd02(%rip), %rsi     # 0xc1386
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2fdad
movq 0x7d8(%rbp), %rcx
movq 0x7e8(%rbp), %rax
addq %rcx, %rax
subq 0x7e0(%rbp), %rax
cqto
idivq %rcx
movq %rdx, %r15
leaq 0x7cce6(%rip), %rsi     # 0xc139d
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x7d8(%rbp), %r12
movq 0x7e0(%rbp), %rbx
leaq 0x7ccea(%rip), %rsi     # 0xc13bf
movq %rbx, %rdx
subq %r13, %rdx
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq %r13, (%rsp)
subq %r13, %rbx
je 0x4474b
addq (%rsp), %r15
movq %r15, %rax
cqto
idivq %r12
movq %rdx, %r12
leaq 0x7ccdd(%rip), %r15     # 0xc13e0
movq 0x7d8(%rbp), %r13
subq %r12, %r13
cmpq %rbx, %r13
cmovgeq %rbx, %r13
xorl %edi, %edi
movq %r15, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2fdad
addq 0x7d0(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x36178
movq %r14, %rdi
movq %rax, %rsi
callq 0x3ca86
movl $0x0, %r12d
subq %r13, %rbx
jne 0x44703
movq 0x7e0(%rbp), %r14
subq (%rsp), %r14
jmp 0x4476b
leaq 0x7cb99(%rip), %rsi     # 0xc12f8
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq