// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0x4cd65(%rip), %rdx     # 0xba3d1
pushq $0x1
popq %rcx
leaq 0xc(%rsp), %r14
movq %r14, %r8
callq 0x32003
movq %rax, %rbx
cmpl $0x8, (%r14)
jne 0x6d929
movq 0x20(%rbx), %rdi
callq 0x6b8b4
testq %rax, %rax
je 0x6d929
movq %rax, %r14
movq 0x8(%rbx), %rdi
callq 0x26760
movl %eax, %r15d
movq 0x30(%rbx), %rdi
callq 0x26760
movq %rax, 0x10(%rsp)
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movq 0x10(%rbx), %rcx
movl %r15d, %edx
callq 0x6b382
movq %rax, %r12
movq 0x18(%rbx), %rdi
pushq $0xa
popq %r13
xorl %esi, %esi
movl %r13d, %edx
callq 0x26a70
movq %rax, %rbp
movq 0x38(%rbx), %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x26a70
movq %rax, %r13
testq %r12, %r12
jne 0x6d817
movq %r13, (%rsp)
movq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0x6b83d
movl %eax, %r13d
testl %eax, %eax
je 0x6d743
movq (%rbx), %r8
subq $0x8, %rsp
leaq 0x500a4(%rip), %rsi     # 0xbd7c9
leaq 0x500b6(%rip), %rcx     # 0xbd7e2
pushq $0x2
popq %rdi
movq %r14, %rdx
movl %r15d, %r9d
xorl %eax, %eax
pushq 0x10(%rbx)
callq 0x6a7bb
popq %rax
popq %rcx
jmp 0x6d78b
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6b382
testq %rax, %rax
je 0x6d78b
movq %rax, %r12
leaq 0x50094(%rip), %rsi     # 0xbd7fa
leaq 0x4f9df(%rip), %rcx     # 0xbd14c
pushq $0x2
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x6a7bb
movq 0x20(%r12), %rax
andl $0x0, 0x8(%rax)
movq %r12, %rdi
callq 0x6b430
movq (%rbx), %rdx
movq 0x10(%rbx), %rdi
movl 0x90(%r14), %r8d
pushq $0x4
popq %rsi
movl %r15d, %ecx
movq %r14, %r9
callq 0x6b555
testq %rax, %rax
je 0x6d7d4
movq %rax, %r12
testl %r13d, %r13d
je 0x6d7dd
movq 0x10(%rbx), %rdi
callq 0x3115a
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x6b2bb
movq %r12, %rdi
callq 0x6b430
jmp 0x6d80e
xorl %r12d, %r12d
movq (%rsp), %r13
jmp 0x6d817
leaq 0x5002d(%rip), %rsi     # 0xbd811
leaq 0x4f961(%rip), %rcx     # 0xbd14c
pushq $0x2
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6a7bb
movq 0x10(%rbx), %rdi
callq 0x3115a
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x6b2bb
movq (%rsp), %r13
callq 0x6a604
cmpq 0xa0eea(%rip), %rbp     # 0x10e708
jbe 0x6d84e
movq %rbp, 0xa0ee1(%rip)     # 0x10e708
callq 0x6a604
movq 0xa0ed5(%rip), %r8      # 0x10e708
leaq 0x4ffe1(%rip), %rsi     # 0xbd81b
leaq 0x4b890(%rip), %rcx     # 0xb90d1
pushq $0x3
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a7bb
testq %r12, %r12
je 0x6d929
cmpq %r13, 0x18(%r14)
jae 0x6d91f
movq %r13, 0x18(%r14)
movq 0x20(%r14), %rax
movq 0x10(%rsp), %rcx
cmpl 0x8(%rax), %ecx
jne 0x6d887
movq (%rax), %rdi
movq 0x28(%rbx), %rsi
callq 0x268f0
testl %eax, %eax
je 0x6d91f
leaq 0x4ff98(%rip), %rsi     # 0xbd826
leaq 0x4f8b7(%rip), %rcx     # 0xbd14c
pushq $0x3
popq %rbp
movl %ebp, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6a7bb
movq 0x8(%r14), %r8
movq 0x20(%r14), %rax
movq (%rax), %r9
movl 0x8(%rax), %r10d
subq $0x8, %rsp
leaq 0x4ff7c(%rip), %rsi     # 0xbd83a
leaq 0x4ff84(%rip), %rcx     # 0xbd849
movl %ebp, %edi
movq %r14, %rdx
xorl %eax, %eax
movq 0x18(%rsp), %r13
pushq %r13
pushq 0x28(%rbx)
pushq %r10
callq 0x6a7bb
addq $0x20, %rsp
movq 0x20(%r14), %rdi
callq 0x6a753
movq %rax, %r15
movq 0x28(%rbx), %rsi
movq %r14, %rdi
movl %r13d, %edx
callq 0x6bb07
movq 0x20(%r14), %r8
leaq 0x4ff85(%rip), %rdx     # 0xbd88c
movq %r14, %rdi
movl $0x40000, %esi          # imm = 0x40000
movq %r15, %rcx
callq 0x6b0e1
movq %r15, %rdi
callq 0x6a782
callq 0x2b8ae
movq %rax, 0x38(%r12)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x321be
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq