// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/replication.c
// Function: slaveTryPartialResynchronization
int slaveTryPartialResynchronization(int fd, int read_reply) {
    char *psync_runid;
    char psync_offset[32];
    sds reply;

    /* Writing half */
    if (!read_reply) {
        /* Initially set repl_master_initial_offset to -1 to mark the current
         * master run_id and offset as not valid. Later if we'll be able to do
         * a FULL resync using the PSYNC command we'll set the offset at the
         * right value, so that this information will be propagated to the
         * client structure representing the master into server.master. */
        server.repl_master_initial_offset = -1;

        if (server.cached_master) {
            psync_runid = server.cached_master->replrunid;
            snprintf(psync_offset,sizeof(psync_offset),"%lld", server.cached_master->reploff+1);
            serverLog(LL_NOTICE,"Trying a partial resynchronization (request %s:%s).", psync_runid, psync_offset);
        } else {
            serverLog(LL_NOTICE,"Partial resynchronization not possible (no cached master)");
            psync_runid = "?";
            memcpy(psync_offset,"-1",3);
        }

        /* Issue the PSYNC command */
        reply = sendSynchronousCommand(SYNC_CMD_WRITE,fd,"PSYNC",psync_runid,psync_offset,NULL);
        if (reply != NULL) {
            serverLog(LL_WARNING,"Unable to send PSYNC to master: %s",reply);
            sdsfree(reply);
            aeDeleteFileEvent(server.el,fd,AE_READABLE);
            return PSYNC_WRITE_ERROR;
        }
        return PSYNC_WAIT_REPLY;
    }

    /* Reading half */
    reply = sendSynchronousCommand(SYNC_CMD_READ,fd,NULL);
    if (sdslen(reply) == 0) {
        /* The master may send empty newlines after it receives PSYNC
         * and before to reply, just to keep the connection alive. */
        sdsfree(reply);
        return PSYNC_WAIT_REPLY;
    }

    aeDeleteFileEvent(server.el,fd,AE_READABLE);

    if (!strncmp(reply,"+FULLRESYNC",11)) {
        char *runid = NULL, *offset = NULL;

        /* FULL RESYNC, parse the reply in order to extract the run id
         * and the replication offset. */
        runid = strchr(reply,' ');
        if (runid) {
            runid++;
            offset = strchr(runid,' ');
            if (offset) offset++;
        }
        if (!runid || !offset || (offset-runid-1) != CONFIG_RUN_ID_SIZE) {
            serverLog(LL_WARNING,
                "Master replied with wrong +FULLRESYNC syntax.");
            /* This is an unexpected condition, actually the +FULLRESYNC
             * reply means that the master supports PSYNC, but the reply
             * format seems wrong. To stay safe we blank the master
             * runid to make sure next PSYNCs will fail. */
            memset(server.repl_master_runid,0,CONFIG_RUN_ID_SIZE+1);
        } else {
            memcpy(server.repl_master_runid, runid, offset-runid-1);
            server.repl_master_runid[CONFIG_RUN_ID_SIZE] = '\0';
            server.repl_master_initial_offset = strtoll(offset,NULL,10);
            serverLog(LL_NOTICE,"Full resync from master: %s:%lld",
                server.repl_master_runid,
                server.repl_master_initial_offset);
        }
        /* We are going to full resync, discard the cached master structure. */
        replicationDiscardCachedMaster();
        sdsfree(reply);
        return PSYNC_FULLRESYNC;
    }

    if (!strncmp(reply,"+CONTINUE",9)) {
        /* Partial resync was accepted, set the replication state accordingly */
        serverLog(LL_NOTICE,
            "Successful partial resynchronization with master.");
        sdsfree(reply);
        replicationResurrectCachedMaster(fd);
        return PSYNC_CONTINUE;
    }

    /* If we reach this point we received either an error since the master does
     * not understand PSYNC, or an unexpected reply from the master.
     * Return PSYNC_NOT_SUPPORTED to the caller in both cases. */

    if (strncmp(reply,"-ERR",4)) {
        /* If it's not an error, log the unexpected event. */
        serverLog(LL_WARNING,
            "Unexpected reply to PSYNC from master: %s", reply);
    } else {
        serverLog(LL_NOTICE,
            "Master does not support PSYNC or is in "
            "error state (reply: %s)", reply);
    }
    sdsfree(reply);
    replicationDiscardCachedMaster();
    return PSYNC_NOT_SUPPORTED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x506d0
leaq 0x127c39(%rip), %rax    # 0x1781d8
movq $-0x1, 0x8d8(%rax)
leaq 0x127c27(%rip), %rax    # 0x1781d8
cmpq $0x0, 0x840(%rax)
je 0x50620
leaq 0x127c16(%rip), %rax    # 0x1781d8
movq 0x840(%rax), %rax
addq $0xe8, %rax
movq %rax, -0x18(%rbp)
leaq -0x40(%rbp), %rdi
leaq 0x127bfa(%rip), %rax    # 0x1781d8
movq 0x840(%rax), %rax
movq 0xc8(%rax), %rcx
addq $0x1, %rcx
movl $0x20, %esi
leaq 0xf288d(%rip), %rdx     # 0x142e89
movb $0x0, %al
callq 0x26120
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rcx
movl $0x2, %edi
leaq 0xec134(%rip), %rsi     # 0x13c74b
movb $0x0, %al
callq 0x2fc60
jmp 0x50652
movl $0x2, %edi
leaq 0xec153(%rip), %rsi     # 0x13c77f
movb $0x0, %al
callq 0x2fc60
leaq 0xfaa5c(%rip), %rax     # 0x14b096
movq %rax, -0x18(%rbp)
movw 0xecbee(%rip), %ax      # 0x13d233
movw %ax, -0x40(%rbp)
movb 0xecbe6(%rip), %al      # 0x13d235
movb %al, -0x3e(%rbp)
movl -0x8(%rbp), %esi
movq -0x18(%rbp), %rcx
leaq -0x40(%rbp), %r8
movl $0x2, %edi
leaq 0xec150(%rip), %rdx     # 0x13c7b9
xorl %eax, %eax
movl %eax, %r9d
movb $0x0, %al
callq 0x502c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x506c4
movq -0x48(%rbp), %rdx
movl $0x3, %edi
leaq 0xec12f(%rip), %rsi     # 0x13c7bf
movb $0x0, %al
callq 0x2fc60
movq -0x48(%rbp), %rdi
callq 0x38620
leaq 0x127b31(%rip), %rax    # 0x1781d8
movq 0x40(%rax), %rdi
movl -0x8(%rbp), %esi
movl $0x1, %edx
callq 0x2aab0
movl $0x0, -0x4(%rbp)
jmp 0x50938
movl $0x1, -0x4(%rbp)
jmp 0x50938
movl -0x8(%rbp), %esi
movl $0x1, %edi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x502c0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x4dc30
cmpq $0x0, %rax
jne 0x5070b
movq -0x48(%rbp), %rdi
callq 0x38620
movl $0x1, -0x4(%rbp)
jmp 0x50938
leaq 0x127ac6(%rip), %rax    # 0x1781d8
movq 0x40(%rax), %rdi
movl -0x8(%rbp), %esi
movl $0x1, %edx
callq 0x2aab0
movq -0x48(%rbp), %rdi
leaq 0xec0b4(%rip), %rsi     # 0x13c7e2
movl $0xb, %edx
callq 0x26350
cmpl $0x0, %eax
jne 0x50892
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movl $0x20, %esi
callq 0x267f0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x5079d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl $0x20, %esi
callq 0x267f0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x5079b
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5079d
cmpq $0x0, -0x50(%rbp)
je 0x507c0
cmpq $0x0, -0x58(%rbp)
je 0x507c0
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
cmpq $0x28, %rax
je 0x507f2
movl $0x3, %edi
leaq 0xec022(%rip), %rsi     # 0x13c7ee
movb $0x0, %al
callq 0x2fc60
leaq 0x1279fe(%rip), %rdi    # 0x1781d8
addq $0x8a8, %rdi            # imm = 0x8A8
xorl %esi, %esi
movl $0x29, %edx
callq 0x26110
jmp 0x50878
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rax
subq %rax, %rdx
subq $0x1, %rdx
leaq 0x1279cc(%rip), %rdi    # 0x1781d8
addq $0x8a8, %rdi            # imm = 0x8A8
callq 0x26c60
leaq 0x1279b9(%rip), %rax    # 0x1781d8
movb $0x0, 0x8d0(%rax)
movq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x26af0
movq %rax, %rcx
leaq 0x127996(%rip), %rax    # 0x1781d8
movq %rcx, 0x8d8(%rax)
leaq 0x127988(%rip), %rax    # 0x1781d8
movq 0x8d8(%rax), %rcx
movl $0x2, %edi
leaq 0xebfb9(%rip), %rsi     # 0x13c81c
leaq 0x12796e(%rip), %rdx    # 0x1781d8
addq $0x8a8, %rdx            # imm = 0x8A8
movb $0x0, %al
callq 0x2fc60
callq 0x50950
movq -0x48(%rbp), %rdi
callq 0x38620
movl $0x3, -0x4(%rbp)
jmp 0x50938
movq -0x48(%rbp), %rdi
leaq 0xebfa0(%rip), %rsi     # 0x13c83d
movl $0x9, %edx
callq 0x26350
cmpl $0x0, %eax
jne 0x508d9
movl $0x2, %edi
leaq 0xebf8f(%rip), %rsi     # 0x13c847
movb $0x0, %al
callq 0x2fc60
movq -0x48(%rbp), %rdi
callq 0x38620
movl -0x8(%rbp), %edi
callq 0x509c0
movl $0x2, -0x4(%rbp)
jmp 0x50938
movq -0x48(%rbp), %rdi
leaq 0xebf95(%rip), %rsi     # 0x13c879
movl $0x4, %edx
callq 0x26350
cmpl $0x0, %eax
je 0x5090c
movq -0x48(%rbp), %rdx
movl $0x3, %edi
leaq 0xebf7b(%rip), %rsi     # 0x13c87e
movb $0x0, %al
callq 0x2fc60
jmp 0x50923
movq -0x48(%rbp), %rdx
movl $0x2, %edi
leaq 0xebf8c(%rip), %rsi     # 0x13c8a8
movb $0x0, %al
callq 0x2fc60
movq -0x48(%rbp), %rdi
callq 0x38620
callq 0x50950
movl $0x4, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)