// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdx
xorl %edi, %edi
leaq 0xed918(%rip), %rsi     # 0x13bb95
movb $0x0, %al
callq 0x2fc60
leaq 0x129f4d(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x7e0(%rax)
jne 0x4e2b2
xorl %edi, %edi
leaq 0xed91a(%rip), %rsi     # 0x13bbb8
movb $0x0, %al
callq 0x2fc60
movq $0x0, -0x8(%rbp)
jmp 0x4e4af
leaq 0x129f1f(%rip), %rax    # 0x1781d8
movq 0x7d8(%rax), %rdx
xorl %edi, %edi
leaq 0xed913(%rip), %rsi     # 0x13bbdc
movb $0x0, %al
callq 0x2fc60
leaq 0x129f01(%rip), %rax    # 0x1781d8
movq 0x7f0(%rax), %rdx
xorl %edi, %edi
leaq 0xed910(%rip), %rsi     # 0x13bbf7
movb $0x0, %al
callq 0x2fc60
leaq 0x129ee3(%rip), %rax    # 0x1781d8
movq 0x7e0(%rax), %rdx
xorl %edi, %edi
leaq 0xed90b(%rip), %rsi     # 0x13bc10
movb $0x0, %al
callq 0x2fc60
leaq 0x129ec5(%rip), %rax    # 0x1781d8
movq 0x7e8(%rax), %rdx
xorl %edi, %edi
leaq 0xed907(%rip), %rsi     # 0x13bc2a
movb $0x0, %al
callq 0x2fc60
movq -0x18(%rbp), %rax
leaq 0x129ea3(%rip), %rcx    # 0x1781d8
subq 0x7f0(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdx
xorl %edi, %edi
leaq 0xed8f9(%rip), %rsi     # 0x13bc46
movb $0x0, %al
callq 0x2fc60
leaq 0x129e7d(%rip), %rax    # 0x1781d8
movq 0x7e8(%rax), %rax
leaq 0x129e6f(%rip), %rcx    # 0x1781d8
movq 0x7d8(%rcx), %rcx
leaq 0x129e61(%rip), %rdx    # 0x1781d8
subq 0x7e0(%rdx), %rcx
addq %rcx, %rax
leaq 0x129e50(%rip), %rcx    # 0x1781d8
cqto
idivq 0x7d8(%rcx)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rdx
xorl %edi, %edi
leaq 0xed8bb(%rip), %rsi     # 0x13bc5d
movb $0x0, %al
callq 0x2fc60
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
leaq 0x129e20(%rip), %rcx    # 0x1781d8
cqto
idivq 0x7d8(%rcx)
movq %rdx, -0x20(%rbp)
leaq 0x129e0c(%rip), %rax    # 0x1781d8
movq 0x7e0(%rax), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdx
xorl %edi, %edi
leaq 0xed897(%rip), %rsi     # 0x13bc7f
movb $0x0, %al
callq 0x2fc60
cmpq $0x0, -0x30(%rbp)
je 0x4e499
leaq 0x129dd7(%rip), %rax    # 0x1781d8
movq 0x7d8(%rax), %rax
subq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x4e42a
leaq 0x129dbf(%rip), %rax    # 0x1781d8
movq 0x7d8(%rax), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x4e432
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdx
xorl %edi, %edi
leaq 0xed859(%rip), %rsi     # 0x13bca0
movb $0x0, %al
callq 0x2fc60
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0x129d7b(%rip), %rax    # 0x1781d8
movq 0x7d0(%rax), %rdi
addq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x38230
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x42e50
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
jmp 0x4e3ef
leaq 0x129d38(%rip), %rax    # 0x1781d8
movq 0x7e0(%rax), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)