// File: /workspace/github_c_makefile_star2_O3/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 0x4f547(%rip), %rdx     # 0xc93e9
leaq 0xc(%rsp), %r14
movl $0x1, %ecx
movq %r14, %r8
callq 0x37a38
movq %rax, %rbx
cmpl $0x8, (%r14)
jne 0x7a192
movq 0x20(%rbx), %rdi
callq 0x77d01
testq %rax, %rax
je 0x7a192
movq %rax, %r14
movq 0x8(%rbx), %rdi
callq 0x26760
movl %eax, %r15d
movq 0x30(%rbx), %rdi
callq 0x26760
movl %eax, %r13d
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movq 0x10(%rbx), %rcx
movl %r15d, %edx
callq 0x7771c
movq %rax, %r12
movq 0x18(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a70
movq %rax, %rbp
movq 0x38(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a70
movq %rax, 0x10(%rsp)
testq %r12, %r12
jne 0x7a05c
movq %r13, (%rsp)
movq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0x77c82
movl %eax, %r13d
testl %eax, %eax
je 0x79f7f
movq (%rbx), %r8
subq $0x8, %rsp
leaq 0x52c20(%rip), %rsi     # 0xccb7d
leaq 0x52c32(%rip), %rcx     # 0xccb96
movl $0x2, %edi
movq %r14, %rdx
movl %r15d, %r9d
xorl %eax, %eax
pushq 0x10(%rbx)
callq 0x76a24
addq $0x10, %rsp
jmp 0x79fcc
movq 0x80(%r14), %rdi
movq (%rbx), %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x7771c
testq %rax, %rax
je 0x79fcc
movq %rax, %r12
leaq 0x52c0c(%rip), %rsi     # 0xccbae
leaq 0x52557(%rip), %rcx     # 0xcc500
movl $0x2, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x76a24
movq 0x20(%r12), %rax
movl $0x0, 0x8(%rax)
movq %r12, %rdi
callq 0x777cf
movq (%rbx), %rdx
movq 0x10(%rbx), %rdi
movl 0x90(%r14), %r8d
movl $0x4, %esi
movl %r15d, %ecx
movq %r14, %r9
callq 0x7798b
testq %rax, %rax
je 0x7a017
movq %rax, %r12
testl %r13d, %r13d
je 0x7a020
movq 0x10(%rbx), %rdi
callq 0x362b0
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x77648
movq %r12, %rdi
callq 0x777cf
jmp 0x7a053
xorl %r12d, %r12d
movq (%rsp), %r13
jmp 0x7a05c
leaq 0x52b9e(%rip), %rsi     # 0xccbc5
leaq 0x524d2(%rip), %rcx     # 0xcc500
movl $0x2, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x76a24
movq 0x10(%rbx), %rdi
callq 0x362b0
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x77648
movq (%rsp), %r13
callq 0x76861
cmpq 0x9c6a5(%rip), %rbp     # 0x116708
jbe 0x7a095
movq %rbp, 0x9c69c(%rip)     # 0x116708
callq 0x76861
movq 0x9c690(%rip), %r8      # 0x116708
leaq 0x52b50(%rip), %rsi     # 0xccbcf
leaq 0x4e063(%rip), %rcx     # 0xc80e9
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x76a24
testq %r12, %r12
je 0x7a192
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%r14)
jae 0x7a188
movq %rax, 0x18(%r14)
movq 0x20(%r14), %rax
cmpl 0x8(%rax), %r13d
jne 0x7a0cf
movq (%rax), %rdi
movq 0x28(%rbx), %rsi
callq 0x268f0
testl %eax, %eax
je 0x7a188
leaq 0x52b04(%rip), %rsi     # 0xccbda
leaq 0x52423(%rip), %rcx     # 0xcc500
movl $0x3, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x76a24
movq 0x8(%r14), %r8
movq 0x20(%r14), %rax
movq (%rax), %r9
movl 0x8(%rax), %r10d
subq $0x8, %rsp
leaq 0x52ae8(%rip), %rsi     # 0xccbee
leaq 0x52af0(%rip), %rcx     # 0xccbfd
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
pushq %r13
pushq 0x28(%rbx)
pushq %r10
callq 0x76a24
addq $0x20, %rsp
movq %r13, %rbp
movq 0x20(%r14), %r13
movl $0x10, %edi
callq 0x382d1
movq %rax, %r15
movq (%r13), %rdi
callq 0x362b0
movq %rax, (%r15)
movl 0x8(%r13), %eax
movl %eax, 0x8(%r15)
movq 0x28(%rbx), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x77f73
movq 0x20(%r14), %r8
leaq 0x52ad8(%rip), %rdx     # 0xccc40
movq %r14, %rdi
movl $0x40000, %esi          # imm = 0x40000
movq %r15, %rcx
callq 0x77455
movq (%r15), %rdi
callq 0x36330
movq %r15, %rdi
callq 0x38413
callq 0x2ffce
movq %rax, 0x38(%r12)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x37c04
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq