// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/sentinel.c
// Function: createSentinelRedisInstance
sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *hostname, int port, int quorum, sentinelRedisInstance *master) {
    sentinelRedisInstance *ri;
    sentinelAddr *addr;
    dict *table = NULL;
    char slavename[NET_PEER_ID_LEN], *sdsname;

    serverAssert(flags & (SRI_MASTER|SRI_SLAVE|SRI_SENTINEL));
    serverAssert((flags & SRI_MASTER) || master != NULL);

    /* Check address validity. */
    addr = createSentinelAddr(hostname,port);
    if (addr == NULL) return NULL;

    /* For slaves use ip:port as name. */
    if (flags & SRI_SLAVE) {
        anetFormatAddr(slavename, sizeof(slavename), hostname, port);
        name = slavename;
    }

    /* Make sure the entry is not duplicated. This may happen when the same
     * name for a master is used multiple times inside the configuration or
     * if we try to add multiple times a slave or sentinel with same ip/port
     * to a master. */
    if (flags & SRI_MASTER) table = sentinel.masters;
    else if (flags & SRI_SLAVE) table = master->slaves;
    else if (flags & SRI_SENTINEL) table = master->sentinels;
    sdsname = sdsnew(name);
    if (dictFind(table,sdsname)) {
        releaseSentinelAddr(addr);
        sdsfree(sdsname);
        errno = EBUSY;
        return NULL;
    }

    /* Create the instance object. */
    ri = zmalloc(sizeof(*ri));
    /* Note that all the instances are started in the disconnected state,
     * the event loop will take care of connecting them. */
    ri->flags = flags;
    ri->name = sdsname;
    ri->runid = NULL;
    ri->config_epoch = 0;
    ri->addr = addr;
    ri->link = createInstanceLink();
    ri->last_pub_time = mstime();
    ri->last_hello_time = mstime();
    ri->last_master_down_reply_time = mstime();
    ri->s_down_since_time = 0;
    ri->o_down_since_time = 0;
    ri->down_after_period = master ? master->down_after_period :
                            SENTINEL_DEFAULT_DOWN_AFTER;
    ri->master_link_down_time = 0;
    ri->auth_pass = NULL;
    ri->slave_priority = SENTINEL_DEFAULT_SLAVE_PRIORITY;
    ri->slave_reconf_sent_time = 0;
    ri->slave_master_host = NULL;
    ri->slave_master_port = 0;
    ri->slave_master_link_status = SENTINEL_MASTER_LINK_STATUS_DOWN;
    ri->slave_repl_offset = 0;
    ri->sentinels = dictCreate(&instancesDictType,NULL);
    ri->quorum = quorum;
    ri->parallel_syncs = SENTINEL_DEFAULT_PARALLEL_SYNCS;
    ri->master = master;
    ri->slaves = dictCreate(&instancesDictType,NULL);
    ri->info_refresh = 0;

    /* Failover state. */
    ri->leader = NULL;
    ri->leader_epoch = 0;
    ri->failover_epoch = 0;
    ri->failover_state = SENTINEL_FAILOVER_STATE_NONE;
    ri->failover_state_change_time = 0;
    ri->failover_start_time = 0;
    ri->failover_timeout = SENTINEL_DEFAULT_FAILOVER_TIMEOUT;
    ri->failover_delay_logged = 0;
    ri->promoted_slave = NULL;
    ri->notification_script = NULL;
    ri->client_reconfig_script = NULL;
    ri->info = NULL;

    /* Role */
    ri->role_reported = ri->flags & (SRI_MASTER|SRI_SLAVE);
    ri->role_reported_time = mstime();
    ri->slave_conf_change_time = mstime();

    /* Add into the right table. */
    dictAdd(table, ri->name, ri);
    return ri;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %r12d
testb $0x7, %r12b
je 0x7b6d8
movq %r9, %rbx
movl %r8d, 0xc(%rsp)
testq %r9, %r9
setne %al
orb %r12b, %al
testb $0x1, %al
je 0x7b6ed
movl %ecx, %r14d
movq %rdx, %rbp
movq %rdi, %r15
movq %rdx, %rdi
movl %ecx, %esi
callq 0x7a436
testq %rax, %rax
je 0x7b571
movq %rax, %r13
testb $0x2, %r12b
je 0x7b4ff
leaq 0x10(%rsp), %r15
movl $0x4e, %esi
movq %r15, %rdi
movq %rbp, %rdx
movl %r14d, %ecx
callq 0x3144a
testb $0x1, %r12b
je 0x7b50e
leaq 0xa01a4(%rip), %rax     # 0x11b6b0
jmp 0x7b52f
testb $0x2, %r12b
jne 0x7b51f
testb $0x4, %r12b
jne 0x7b528
xorl %r14d, %r14d
jmp 0x7b532
leaq 0x88(%rbx), %rax
jmp 0x7b52f
leaq 0x80(%rbx), %rax
movq (%rax), %r14
movq %r15, %rdi
callq 0x39245
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x31cca
testq %rax, %rax
je 0x7b579
movq (%r13), %rdi
callq 0x392b6
movq %r13, %rdi
callq 0x3b3df
movq %rbp, %rdi
callq 0x392b6
callq 0x26890
movl $0x10, (%rax)
xorl %r15d, %r15d
jmp 0x7b6c6
movl $0x138, %edi            # imm = 0x138
callq 0x3b29d
movq %rax, %r15
movl %r12d, (%rax)
movq %rbp, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %r13, 0x20(%rax)
callq 0x7afdb
movq %rax, 0x28(%r15)
callq 0x330c8
movq %rax, 0x30(%r15)
callq 0x330c8
movq %rax, 0x38(%r15)
callq 0x330c8
movq %rax, 0x40(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r15)
testq %rbx, %rbx
je 0x7b5cf
movq 0x58(%rbx), %rax
jmp 0x7b5d4
movl $0x7530, %eax           # imm = 0x7530
movq %rax, 0x58(%r15)
movups %xmm0, 0x98(%r15)
movl $0x64, 0xa8(%r15)
xorl %r13d, %r13d
movq %r13, 0xb0(%r15)
movq %r13, 0xc0(%r15)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xc8(%r15)
movq %r13, 0xd0(%r15)
leaq 0x8abf5(%rip), %r12     # 0x106210
movq %r12, %rdi
xorl %esi, %esi
callq 0x31774
movq %rax, 0x80(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0x90(%r15)
movl $0x1, 0x94(%r15)
movq %rbx, 0xb8(%r15)
movq %r12, %rdi
xorl %esi, %esi
callq 0x31774
movq %rax, 0x88(%r15)
movq %r13, 0x60(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0xd8(%r15)
movups %xmm0, 0xe4(%r15)
movups %xmm0, 0xf8(%r15)
movq $0x2bf20, 0x108(%r15) # imm = 0x2BF20
movups %xmm0, 0x110(%r15)
movups %xmm0, 0x120(%r15)
movq %r13, 0x130(%r15)
movl (%r15), %eax
andl $0x3, %eax
movl %eax, 0x68(%r15)
callq 0x330c8
movq %rax, 0x70(%r15)
callq 0x330c8
movq %rax, 0x78(%r15)
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x31a95
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53c9d(%rip), %rdi     # 0xcf37c
leaq 0x53a6a(%rip), %rsi     # 0xcf150
movl $0x47f, %edx            # imm = 0x47F
jmp 0x7b700
leaq 0x53cb4(%rip), %rdi     # 0xcf3a8
leaq 0x53a55(%rip), %rsi     # 0xcf150
movl $0x480, %edx            # imm = 0x480
callq 0x654e1
movl $0x1, %edi
callq 0x263d0