// File: /workspace/github_c_makefile_star2_O3/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 0x77bd5
movq %r9, %rbx
movl %r8d, 0xc(%rsp)
testq %r9, %r9
setne %al
orb %r12b, %al
testb $0x1, %al
je 0x77bea
movl %ecx, %r14d
movq %rdx, %rbp
movq %rdi, %r15
movq %rdx, %rdi
movl %ecx, %esi
callq 0x7694e
testq %rax, %rax
je 0x77a6e
movq %rax, %r13
testb $0x2, %r12b
jne 0x779f5
testb $0x1, %r12b
jne 0x77a13
testb $0x4, %r12b
jne 0x77a25
xorl %r14d, %r14d
jmp 0x77a2f
leaq 0x10(%rsp), %r15
movl $0x4e, %esi
movq %r15, %rdi
movq %rbp, %rdx
movl %r14d, %ecx
callq 0x2e363
testb $0x1, %r12b
je 0x77a1c
leaq 0x9ecf6(%rip), %rax     # 0x116710
jmp 0x77a2c
leaq 0x88(%rbx), %rax
jmp 0x77a2c
leaq 0x80(%rbx), %rax
movq (%rax), %r14
movq %r15, %rdi
callq 0x362b0
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2ebca
testq %rax, %rax
je 0x77a76
movq (%r13), %rdi
callq 0x36330
movq %r13, %rdi
callq 0x38413
movq %rbp, %rdi
callq 0x36330
callq 0x26880
movl $0x10, (%rax)
xorl %r15d, %r15d
jmp 0x77bc3
movl $0x138, %edi            # imm = 0x138
callq 0x382d1
movq %rax, %r15
movl %r12d, (%rax)
movq %rbp, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %r13, 0x20(%rax)
callq 0x774f4
movq %rax, 0x28(%r15)
callq 0x2ffce
movq %rax, 0x30(%r15)
callq 0x2ffce
movq %rax, 0x38(%r15)
callq 0x2ffce
movq %rax, 0x40(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r15)
testq %rbx, %rbx
je 0x77acc
movq 0x58(%rbx), %rax
jmp 0x77ad1
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 0x89798(%rip), %r12     # 0x1012b0
movq %r12, %rdi
xorl %esi, %esi
callq 0x2e68c
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 0x2e68c
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 0x2ffce
movq %rax, 0x70(%r15)
callq 0x2ffce
movq %rax, 0x78(%r15)
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2e9b8
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x548a0(%rip), %rdi     # 0xcc47c
leaq 0x5466d(%rip), %rsi     # 0xcc250
movl $0x47f, %edx            # imm = 0x47F
jmp 0x77bfd
leaq 0x548b7(%rip), %rdi     # 0xcc4a8
leaq 0x54658(%rip), %rsi     # 0xcc250
movl $0x480, %edx            # imm = 0x480
callq 0x61908
movl $0x1, %edi
callq 0x263c0