// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebp
testl %esi, %esi
je 0x4925f
xorl %r14d, %r14d
movl $0x1, %edi
movl %ebp, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x48f8d
movq %rax, %rbx
movzbl -0x1(%rax), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x4935f
leaq 0x7af05(%rip), %rdx     # 0xc4150
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
movq %rax, %r14
jmp 0x4935f
leaq 0xbd5f2(%rip), %r15     # 0x106858
movq $-0x1, 0x8c8(%r15)
movq 0x830(%r15), %rbx
testq %rbx, %rbx
je 0x492c2
movq 0xc8(%rbx), %rcx
addq $0xe8, %rbx
incq %rcx
leaq 0x82aeb(%rip), %rdx     # 0xcbd80
movq %rsp, %r14
movl $0x20, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x26120
leaq 0x7bb3d(%rip), %rsi     # 0xc4deb
movl $0x2, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x32ea6
jmp 0x492e7
leaq 0x7bb56(%rip), %rsi     # 0xc4e1f
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movb $0x0, 0x2(%rsp)
movw $0x312d, (%rsp)         # imm = 0x312D
leaq 0x8ae9f(%rip), %rbx     # 0xd4186
leaq 0x7bb6b(%rip), %rdx     # 0xc4e59
xorl %r14d, %r14d
movq %rsp, %r8
movl $0x2, %edi
movl %ebp, %esi
movq %rbx, %rcx
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x48f8d
testq %rax, %rax
je 0x493dd
movq %rax, %rbx
leaq 0x7bb44(%rip), %rsi     # 0xc4e5f
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
movq %rbx, %rdi
callq 0x392b6
movq 0x40(%r15), %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x2ffb6
jmp 0x49532
movq -0x11(%rbx), %r14
jmp 0x4935f
movzwl -0x5(%rbx), %r14d
jmp 0x4935f
movl -0x9(%rbx), %r14d
jmp 0x4935f
movzbl -0x3(%rbx), %r14d
testq %r14, %r14
je 0x493d5
leaq 0xbd4ed(%rip), %r15     # 0x106858
movq 0x40(%r15), %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x2ffb6
leaq 0x7bb00(%rip), %rsi     # 0xc4e82
movl $0xb, %edx
movq %rbx, %rdi
callq 0x26360
testl %eax, %eax
je 0x493e8
leaq 0x7bb43(%rip), %rsi     # 0xc4edd
movl $0x9, %edx
movq %rbx, %rdi
callq 0x26360
testl %eax, %eax
je 0x4941a
leaq 0x7bb67(%rip), %rsi     # 0xc4f19
movl $0x4, %edx
movq %rbx, %rdi
callq 0x26360
testl %eax, %eax
je 0x49447
leaq 0x7bb50(%rip), %rsi     # 0xc4f1e
movl $0x3, %edi
jmp 0x49453
movq %rbx, %rdi
callq 0x392b6
movl $0x1, %r14d
jmp 0x49532
movq %rbx, %rdi
movl $0x20, %esi
callq 0x26800
testq %rax, %rax
je 0x49475
movq %rax, %r14
incq %r14
movq %r14, %rdi
movl $0x20, %esi
callq 0x26800
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %rax, %rdi
jmp 0x4947a
leaq 0x7bac6(%rip), %rsi     # 0xc4ee7
movl $0x2, %r14d
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
movq %rbx, %rdi
callq 0x392b6
movl %ebp, %edi
callq 0x49585
jmp 0x49532
leaq 0x7bafa(%rip), %rsi     # 0xc4f48
movl $0x2, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x32ea6
movq %rbx, %rdi
callq 0x392b6
callq 0x49540
movl $0x4, %r14d
jmp 0x49532
xorl %r14d, %r14d
xorl %edi, %edi
testq %r14, %r14
je 0x494f1
testq %rdi, %rdi
je 0x494f1
movq %r14, %rax
subq %rdi, %rax
cmpq $-0x29, %rax
jne 0x494f1
movq 0x20(%r14), %rax
movq %rax, 0x8b8(%r15)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x8a8(%r15)
movups %xmm0, 0x898(%r15)
leaq 0x898(%r15), %r14
movb $0x0, 0x8c0(%r15)
xorl %esi, %esi
movl $0xa, %edx
callq 0x26b00
movq %rax, 0x8c8(%r15)
leaq 0x7b9df(%rip), %rsi     # 0xc4ebc
movl $0x2, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x32ea6
jmp 0x4951f
leaq 0x7b996(%rip), %rsi     # 0xc4e8e
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
xorps %xmm0, %xmm0
movups %xmm0, 0x8b1(%r15)
movups %xmm0, 0x8a8(%r15)
movups %xmm0, 0x898(%r15)
callq 0x49540
movq %rbx, %rdi
callq 0x392b6
movl $0x3, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq