// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0x6b796
movq %r9, %rbx
movl %r8d, 0xc(%rsp)
testq %r9, %r9
setne %al
orb %r12b, %al
testb $0x1, %al
je 0x6b7ab
movl %ecx, %r14d
movq %rdx, %rbp
movq %rdi, %r15
movq %rdx, %rdi
movl %ecx, %esi
callq 0x6a6eb
testq %rax, %rax
je 0x6b62d
movq %rax, %r13
testb $0x2, %r12b
jne 0x6b5bf
testb $0x1, %r12b
jne 0x6b5db
testb $0x4, %r12b
jne 0x6b5ed
xorl %r14d, %r14d
jmp 0x6b5f7
leaq 0x10(%rsp), %r15
pushq $0x4e
popq %rsi
movq %r15, %rdi
movq %rbp, %rdx
movl %r14d, %ecx
callq 0x29e9c
testb $0x1, %r12b
je 0x6b5e4
leaq 0xa312e(%rip), %rax     # 0x10e710
jmp 0x6b5f4
leaq 0x88(%rbx), %rax
jmp 0x6b5f4
leaq 0x80(%rbx), %rax
movq (%rax), %r14
movq %r15, %rdi
callq 0x3115a
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2a5f9
testq %rax, %rax
je 0x6b635
movq %r13, %rdi
callq 0x6a782
movq %rbp, %rdi
callq 0x311c8
callq 0x26880
movl $0x10, (%rax)
xorl %r15d, %r15d
jmp 0x6b784
movl $0x138, %edi            # imm = 0x138
callq 0x327b9
movq %rax, %r15
movl %r12d, (%rax)
movq %rbp, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %r13, 0x20(%rax)
callq 0x6b18d
movq %rax, 0x28(%r15)
callq 0x2b8ae
movq %rax, 0x30(%r15)
callq 0x2b8ae
movq %rax, 0x38(%r15)
callq 0x2b8ae
movq %rax, 0x40(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r15)
testq %rbx, %rbx
je 0x6b68b
movq 0x58(%rbx), %rax
jmp 0x6b690
movl $0x7530, %eax           # imm = 0x7530
movq %rax, 0x58(%r15)
movups %xmm0, 0x98(%r15)
movl $0x64, 0xa8(%r15)
andq $0x0, 0xb0(%r15)
andq $0x0, 0xc0(%r15)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xc8(%r15)
andq $0x0, 0xd0(%r15)
leaq 0x8dbd9(%rip), %r12     # 0xf92b0
movq %r12, %rdi
xorl %esi, %esi
callq 0x2a155
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 0x2a155
movq %rax, 0x88(%r15)
andq $0x0, 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)
andq $0x0, 0x130(%r15)
movups %xmm0, 0x120(%r15)
movl (%r15), %eax
andl $0x3, %eax
movl %eax, 0x68(%r15)
callq 0x2b8ae
movq %rax, 0x70(%r15)
callq 0x2b8ae
movq %rax, 0x78(%r15)
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2a3ed
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5192b(%rip), %rdi     # 0xbd0c8
leaq 0x516f8(%rip), %rsi     # 0xbce9c
movl $0x47f, %edx            # imm = 0x47F
jmp 0x6b7be
leaq 0x51942(%rip), %rdi     # 0xbd0f4
leaq 0x516e3(%rip), %rsi     # 0xbce9c
movl $0x480, %edx            # imm = 0x480
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0