// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/replication.c
// Function: masterTryPartialResynchronization
int masterTryPartialResynchronization(client *c) {
    long long psync_offset, psync_len;
    char *master_runid = c->argv[1]->ptr;
    char buf[128];
    int buflen;

    /* Is the runid of this master the same advertised by the wannabe slave
     * via PSYNC? If runid changed this master is a different instance and
     * there is no way to continue. */
    if (strcasecmp(master_runid, server.runid)) {
        /* Run id "?" is used by slaves that want to force a full resync. */
        if (master_runid[0] != '?') {
            serverLog(LL_NOTICE,"Partial resynchronization not accepted: "
                "Runid mismatch (Client asked for runid '%s', my runid is '%s')",
                master_runid, server.runid);
        } else {
            serverLog(LL_NOTICE,"Full resync requested by slave %s",
                replicationGetSlaveName(c));
        }
        goto need_full_resync;
    }

    /* We still have the data our slave is asking for? */
    if (getLongLongFromObjectOrReply(c,c->argv[2],&psync_offset,NULL) !=
       C_OK) goto need_full_resync;
    if (!server.repl_backlog ||
        psync_offset < server.repl_backlog_off ||
        psync_offset > (server.repl_backlog_off + server.repl_backlog_histlen))
    {
        serverLog(LL_NOTICE,
            "Unable to partial resync with slave %s for lack of backlog (Slave request was: %lld).", replicationGetSlaveName(c), psync_offset);
        if (psync_offset > server.master_repl_offset) {
            serverLog(LL_WARNING,
                "Warning: slave %s tried to PSYNC with an offset that is greater than the master replication offset.", replicationGetSlaveName(c));
        }
        goto need_full_resync;
    }

    /* If we reached this point, we are able to perform a partial resync:
     * 1) Set client state to make it a slave.
     * 2) Inform the client we can continue with +CONTINUE
     * 3) Send the backlog data (from the offset to the end) to the slave. */
    c->flags |= CLIENT_SLAVE;
    c->replstate = SLAVE_STATE_ONLINE;
    c->repl_ack_time = server.unixtime;
    c->repl_put_online_on_ack = 0;
    listAddNodeTail(server.slaves,c);
    /* We can't use the connection buffers since they are used to accumulate
     * new commands at this stage. But we are sure the socket send buffer is
     * empty so this write will never fail actually. */
    buflen = snprintf(buf,sizeof(buf),"+CONTINUE\r\n");
    if (write(c->fd,buf,buflen) != buflen) {
        freeClientAsync(c);
        return C_OK;
    }
    psync_len = addReplyReplicationBacklog(c,psync_offset);
    serverLog(LL_NOTICE,
        "Partial resynchronization request from %s accepted. Sending %lld bytes of backlog starting from offset %lld.",
            replicationGetSlaveName(c),
            psync_len, psync_offset);
    /* Note that we don't need to set the selected DB at server.slaveseldb
     * to -1 to force the master to emit SELECT, since the slave already
     * has this state from the previous connection with the master. */

    refreshGoodSlavesCount();
    return C_OK; /* The caller can return, no full resync needed. */

need_full_resync:
    /* We need a full resync for some reason... Note that we can't
     * reply to PSYNC right now if a full SYNC is needed. The reply
     * must include the master offset at the time the RDB file we transfer
     * is generated, so we need to delay the reply to that moment. */
    return C_ERR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x129bca(%rip), %rsi    # 0x1781d8
addq $0x70, %rsi
callq 0x26300
cmpl $0x0, %eax
je 0x4e670
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3f, %eax
je 0x4e64c
movq -0x28(%rbp), %rdx
movl $0x2, %edi
leaq 0xed69e(%rip), %rsi     # 0x13bcd6
leaq 0x129b99(%rip), %rcx    # 0x1781d8
addq $0x70, %rcx
movb $0x0, %al
callq 0x2fc60
jmp 0x4e66b
movq -0x10(%rbp), %rdi
callq 0x4d700
movq %rax, %rdx
movl $0x2, %edi
leaq 0xed6d9(%rip), %rsi     # 0x13bd3d
movb $0x0, %al
callq 0x2fc60
jmp 0x4e839
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x49ea0
cmpl $0x0, %eax
je 0x4e697
jmp 0x4e839
leaq 0x129b3a(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x7d0(%rax)
je 0x4e6e1
movq -0x18(%rbp), %rax
leaq 0x129b25(%rip), %rcx    # 0x1781d8
cmpq 0x7f0(%rcx), %rax
jl 0x4e6e1
movq -0x18(%rbp), %rax
leaq 0x129b11(%rip), %rcx    # 0x1781d8
movq 0x7f0(%rcx), %rcx
leaq 0x129b03(%rip), %rdx    # 0x1781d8
addq 0x7e0(%rdx), %rcx
cmpq %rcx, %rax
jle 0x4e73c
movq -0x10(%rbp), %rdi
callq 0x4d700
movq %rax, %rdx
movq -0x18(%rbp), %rcx
movl $0x2, %edi
leaq 0xed662(%rip), %rsi     # 0x13bd5f
movb $0x0, %al
callq 0x2fc60
movq -0x18(%rbp), %rax
leaq 0x129ac9(%rip), %rcx    # 0x1781d8
cmpq 0x7c0(%rcx), %rax
jle 0x4e737
movq -0x10(%rbp), %rdi
callq 0x4d700
movq %rax, %rdx
movl $0x3, %edi
leaq 0xed685(%rip), %rsi     # 0x13bdb5
movb $0x0, %al
callq 0x2fc60
jmp 0x4e839
movq -0x10(%rbp), %rax
movl 0x98(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x98(%rax)
movq -0x10(%rbp), %rax
movl $0x9, 0xa0(%rax)
leaq 0x129a74(%rip), %rax    # 0x1781d8
movq 0x978(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xa4(%rax)
leaq 0x129a4d(%rip), %rax    # 0x1781d8
movq 0x1e0(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x27000
leaq -0xb0(%rbp), %rdi
movl $0x80, %esi
leaq 0xed66b(%rip), %rdx     # 0x13be19
movb $0x0, %al
callq 0x26120
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0xb0(%rbp), %rsi
movslq -0xb4(%rbp), %rdx
callq 0x26bc0
movslq -0xb4(%rbp), %rcx
cmpq %rcx, %rax
je 0x4e7f3
movq -0x10(%rbp), %rdi
callq 0x44460
movl $0x0, -0x4(%rbp)
jmp 0x4e840
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4e260
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4d700
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %r8
movl $0x2, %edi
leaq 0xed601(%rip), %rsi     # 0x13be25
movb $0x0, %al
callq 0x2fc60
callq 0x4e850
movl $0x0, -0x4(%rbp)
jmp 0x4e840
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)