// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/sentinel.c
// Function: sentinelProcessHelloMessage
void sentinelProcessHelloMessage(char *hello, int hello_len) {
    /* Format is composed of 8 tokens:
     * 0=ip,1=port,2=runid,3=current_epoch,4=master_name,
     * 5=master_ip,6=master_port,7=master_config_epoch. */
    int numtokens, port, removed, master_port;
    uint64_t current_epoch, master_config_epoch;
    char **token = sdssplitlen(hello, hello_len, ",", 1, &numtokens);
    sentinelRedisInstance *si, *master;

    if (numtokens == 8) {
        /* Obtain a reference to the master this hello message is about */
        master = sentinelGetMasterByName(token[4]);
        if (!master) goto cleanup; /* Unknown master, skip the message. */

        /* First, try to see if we already have this sentinel. */
        port = atoi(token[1]);
        master_port = atoi(token[6]);
        si = getSentinelRedisInstanceByAddrAndRunID(
                        master->sentinels,token[0],port,token[2]);
        current_epoch = strtoull(token[3],NULL,10);
        master_config_epoch = strtoull(token[7],NULL,10);

        if (!si) {
            /* If not, remove all the sentinels that have the same runid
             * because there was an address change, and add the same Sentinel
             * with the new address back. */
            removed = removeMatchingSentinelFromMaster(master,token[2]);
            if (removed) {
                sentinelEvent(LL_NOTICE,"+sentinel-address-switch",master,
                    "%@ ip %s port %d for %s", token[0],port,token[2]);
            } else {
                /* Check if there is another Sentinel with the same address this
                 * new one is reporting. What we do if this happens is to set its
                 * port to 0, to signal the address is invalid. We'll update it
                 * later if we get an HELLO message. */
                sentinelRedisInstance *other =
                    getSentinelRedisInstanceByAddrAndRunID(
                        master->sentinels, token[0],port,NULL);
                if (other) {
                    sentinelEvent(LL_NOTICE,"+sentinel-invalid-addr",other,"%@");
                    other->addr->port = 0; /* It means: invalid address. */
                    sentinelUpdateSentinelAddressInAllMasters(other);
                }
            }

            /* Add the new sentinel. */
            si = createSentinelRedisInstance(token[2],SRI_SENTINEL,
                            token[0],port,master->quorum,master);

            if (si) {
                if (!removed) sentinelEvent(LL_NOTICE,"+sentinel",si,"%@");
                /* The runid is NULL after a new instance creation and
                 * for Sentinels we don't have a later chance to fill it,
                 * so do it now. */
                si->runid = sdsnew(token[2]);
                sentinelTryConnectionSharing(si);
                if (removed) sentinelUpdateSentinelAddressInAllMasters(si);
                sentinelFlushConfig();
            }
        }

        /* Update local current_epoch if received current_epoch is greater.*/
        if (current_epoch > sentinel.current_epoch) {
            sentinel.current_epoch = current_epoch;
            sentinelFlushConfig();
            sentinelEvent(LL_WARNING,"+new-epoch",master,"%llu",
                (unsigned long long) sentinel.current_epoch);
        }

        /* Update master info if received configuration is newer. */
        if (si && master->config_epoch < master_config_epoch) {
            master->config_epoch = master_config_epoch;
            if (master_port != master->addr->port ||
                strcmp(master->addr->ip, token[5]))
            {
                sentinelAddr *old_addr;

                sentinelEvent(LL_WARNING,"+config-update-from",si,"%@");
                sentinelEvent(LL_WARNING,"+switch-master",
                    master,"%s %s %d %s %d",
                    master->name,
                    master->addr->ip, master->addr->port,
                    token[5], master_port);

                old_addr = dupSentinelAddr(master->addr);
                sentinelResetMasterAndChangeAddress(master, token[5], master_port);
                sentinelCallClientReconfScript(master,
                    SENTINEL_OBSERVER,"start",
                    old_addr,master->addr);
                releaseSentinelAddr(old_addr);
            }
        }

        /* Update the state of the Sentinel. */
        if (si) si->last_hello_time = mstime();
    }

cleanup:
    sdsfreesplitres(token,numtokens);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x4ea01(%rip), %rdx     # 0xcc361
leaq 0xc(%rsp), %r14
movl $0x1, %ecx
movq %r14, %r8
callq 0x3a9d4
movq %rax, %rbx
cmpl $0x8, (%r14)
jne 0x7dc50
movq 0x20(%rbx), %rdi
callq 0x7b804
testq %rax, %rax
je 0x7dc50
movq %rax, %r14
movq 0x8(%rbx), %rdi
callq 0x26770
movl %eax, %r15d
movq 0x30(%rbx), %rdi
callq 0x26770
movl %eax, %r13d
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movq 0x10(%rbx), %rcx
movl %r15d, %edx
callq 0x7b208
movq %rax, %r12
movq 0x18(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a80
movq %rax, %rbp
movq 0x38(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a80
movq %rax, 0x10(%rsp)
testq %r12, %r12
jne 0x7db1a
movq %r13, (%rsp)
movq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0x7b785
movl %eax, %r13d
testl %eax, %eax
je 0x7da3d
movq (%rbx), %r8
subq $0x8, %rsp
leaq 0x52062(%rip), %rsi     # 0xcfa7d
leaq 0x52074(%rip), %rcx     # 0xcfa96
movl $0x2, %edi
movq %r14, %rdx
movl %r15d, %r9d
xorl %eax, %eax
pushq 0x10(%rbx)
callq 0x7a50c
addq $0x10, %rsp
jmp 0x7da8a
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x7b208
testq %rax, %rax
je 0x7da8a
movq %rax, %r12
leaq 0x5204e(%rip), %rsi     # 0xcfaae
leaq 0x51999(%rip), %rcx     # 0xcf400
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x7a50c
movq 0x20(%r12), %rax
movl $0x0, 0x8(%rax)
movq %r12, %rdi
callq 0x7b2e3
movq (%rbx), %rdx
movq 0x10(%rbx), %rdi
movl 0x90(%r14), %r8d
movl $0x4, %esi
movl %r15d, %ecx
movq %r14, %r9
callq 0x7b48e
testq %rax, %rax
je 0x7dad5
movq %rax, %r12
testl %r13d, %r13d
je 0x7dade
movq 0x10(%rbx), %rdi
callq 0x39245
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x7b12f
movq %r12, %rdi
callq 0x7b2e3
jmp 0x7db11
xorl %r12d, %r12d
movq (%rsp), %r13
jmp 0x7db1a
leaq 0x51fe0(%rip), %rsi     # 0xcfac5
leaq 0x51914(%rip), %rcx     # 0xcf400
movl $0x2, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x7a50c
movq 0x10(%rbx), %rdi
callq 0x39245
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x7b12f
movq (%rsp), %r13
callq 0x7a33b
cmpq 0x9db87(%rip), %rbp     # 0x11b6a8
jbe 0x7db53
movq %rbp, 0x9db7e(%rip)     # 0x11b6a8
callq 0x7a33b
movq 0x9db72(%rip), %r8      # 0x11b6a8
leaq 0x51f92(%rip), %rsi     # 0xcfacf
leaq 0x4d51d(%rip), %rcx     # 0xcb061
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x7a50c
testq %r12, %r12
je 0x7dc50
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%r14)
jae 0x7dc46
movq %rax, 0x18(%r14)
movq 0x20(%r14), %rax
cmpl 0x8(%rax), %r13d
jne 0x7db8d
movq (%rax), %rdi
movq 0x28(%rbx), %rsi
callq 0x26900
testl %eax, %eax
je 0x7dc46
leaq 0x51f46(%rip), %rsi     # 0xcfada
leaq 0x51865(%rip), %rcx     # 0xcf400
movl $0x3, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x7a50c
movq 0x8(%r14), %r8
movq 0x20(%r14), %rax
movq (%rax), %r9
movl 0x8(%rax), %r10d
subq $0x8, %rsp
leaq 0x51f2a(%rip), %rsi     # 0xcfaee
leaq 0x51f32(%rip), %rcx     # 0xcfafd
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
pushq %r13
pushq 0x28(%rbx)
pushq %r10
callq 0x7a50c
addq $0x20, %rsp
movq %r13, %rbp
movq 0x20(%r14), %r13
movl $0x10, %edi
callq 0x3b29d
movq %rax, %r15
movq (%r13), %rdi
callq 0x39245
movq %rax, (%r15)
movl 0x8(%r13), %eax
movl %eax, 0x8(%r15)
movq 0x28(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x7ba76
movq 0x20(%r14), %r8
leaq 0x51f1a(%rip), %rdx     # 0xcfb40
movq %r14, %rdi
movl $0x40000, %esi          # imm = 0x40000
movq %r15, %rcx
callq 0x7af3c
movq (%r15), %rdi
callq 0x392b6
movq %r15, %rdi
callq 0x3b3df
callq 0x330c8
movq %rax, 0x38(%r12)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x3ab7f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq