// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelResetMasterAndChangeAddress
int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip, int port) {
    sentinelAddr *oldaddr, *newaddr;
    sentinelAddr **slaves = NULL;
    int numslaves = 0, j;
    dictIterator *di;
    dictEntry *de;

    newaddr = createSentinelAddr(ip,port);
    if (newaddr == NULL) return C_ERR;

    /* Make a list of slaves to add back after the reset.
     * Don't include the one having the address we are switching to. */
    di = dictGetIterator(master->slaves);
    while((de = dictNext(di)) != NULL) {
        sentinelRedisInstance *slave = dictGetVal(de);

        if (sentinelAddrIsEqual(slave->addr,newaddr)) continue;
        slaves = zrealloc(slaves,sizeof(sentinelAddr*)*(numslaves+1));
        slaves[numslaves++] = createSentinelAddr(slave->addr->ip,
                                                 slave->addr->port);
    }
    dictReleaseIterator(di);

    /* If we are switching to a different address, include the old address
     * as a slave as well, so that we'll be able to sense / reconfigure
     * the old master. */
    if (!sentinelAddrIsEqual(newaddr,master->addr)) {
        slaves = zrealloc(slaves,sizeof(sentinelAddr*)*(numslaves+1));
        slaves[numslaves++] = createSentinelAddr(master->addr->ip,
                                                 master->addr->port);
    }

    /* Reset and switch address. */
    sentinelResetMaster(master,SENTINEL_RESET_NO_SENTINELS);
    oldaddr = master->addr;
    master->addr = newaddr;
    master->o_down_since_time = 0;
    master->s_down_since_time = 0;

    /* Add slaves back. */
    for (j = 0; j < numslaves; j++) {
        sentinelRedisInstance *slave;

        slave = createSentinelRedisInstance(NULL,SRI_SLAVE,slaves[j]->ip,
                    slaves[j]->port, master->quorum, master);
        releaseSentinelAddr(slaves[j]);
        if (slave) sentinelEvent(LL_NOTICE,"+slave",slave,"%@");
    }
    zfree(slaves);

    /* Release the old address at the end so we are safe even if the function
     * gets the master->addr->ip and master->addr->port as arguments. */
    releaseSentinelAddr(oldaddr);
    sentinelFlushConfig();
    return C_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsi, %rdi
movl %edx, %esi
callq 0x7694e
testq %rax, %rax
je 0x7801c
movq %rax, %r15
movq 0x88(%rbx), %rdi
callq 0x2efbb
movq %rax, %r12
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
movq %rbx, (%rsp)
je 0x78026
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%rax), %rbp
movq 0x20(%rbp), %rax
movl 0x8(%rax), %ecx
cmpl 0x8(%r15), %ecx
jne 0x77fdd
movq (%rax), %rdi
movq (%r15), %rsi
callq 0x262f0
testl %eax, %eax
je 0x7800d
movslq %r13d, %rbx
incl %r13d
leaq 0x8(,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3837d
movq %rax, %r14
movq 0x20(%rbp), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
callq 0x7694e
movq %rax, (%r14,%rbx,8)
movq (%rsp), %rbx
movq %r12, %rdi
callq 0x2f015
testq %rax, %rax
jne 0x77fbd
jmp 0x7802c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x78134
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x2f0dd
movq 0x20(%rbx), %rax
movl 0x8(%r15), %ecx
cmpl 0x8(%rax), %ecx
jne 0x78050
movq (%r15), %rdi
movq (%rax), %rsi
callq 0x262f0
testl %eax, %eax
je 0x78084
movslq %r13d, %rbx
incl %r13d
leaq 0x8(,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3837d
movq %rax, %r14
movq (%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
callq 0x7694e
movq %rax, (%r14,%rbx,8)
movq (%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x77da6
movq 0x20(%rbx), %rax
movq %rax, (%rsp)
movq %r15, 0x20(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
testl %r13d, %r13d
jle 0x78111
movl %r13d, %r15d
xorl %r13d, %r13d
movq (%r14,%r13,8), %rax
movq (%rax), %rdx
movl 0x8(%rax), %ecx
movl 0x90(%rbx), %r8d
xorl %edi, %edi
movl $0x2, %esi
movq %rbx, %r9
callq 0x7798b
movq %rax, %rbp
movq (%r14,%r13,8), %r12
movq (%r12), %rdi
callq 0x36330
movq %r12, %rdi
callq 0x38413
testq %rbp, %rbp
je 0x78109
movl $0x2, %edi
leaq 0x5440b(%rip), %rsi     # 0xcc503
movq %rbp, %rdx
leaq 0x543fe(%rip), %rcx     # 0xcc500
xorl %eax, %eax
callq 0x76a24
incq %r13
cmpq %r13, %r15
jne 0x780af
movq %r14, %rdi
callq 0x38413
movq (%rsp), %rbx
movq (%rbx), %rdi
callq 0x36330
movq %rbx, %rdi
callq 0x38413
callq 0x76861
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq