// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x14(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x95fc6
jmp 0x95fe8
leaq 0xb01bb(%rip), %rdi     # 0x146188
leaq 0xaff88(%rip), %rsi     # 0x145f5c
movl $0x47f, %edx            # imm = 0x47F
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x95ffa
cmpq $0x0, -0x30(%rbp)
je 0x95ffc
jmp 0x9601e
leaq 0xb01b1(%rip), %rdi     # 0x1461b4
leaq 0xaff52(%rip), %rsi     # 0x145f5c
movl $0x480, %edx            # imm = 0x480
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x94810
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x96042
movq $0x0, -0x8(%rbp)
jmp 0x963d3
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x96070
leaq -0xa0(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movl $0x4e, %esi
callq 0x2cdc0
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x96088
movq 0xf6fbe(%rip), %rax     # 0x18d040
movq %rax, -0x48(%rbp)
jmp 0x960c2
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x960a4
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x960c0
movl -0x14(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x960be
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x960c0
jmp 0x960c2
movq -0x10(%rbp), %rdi
callq 0x38510
movq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x2dcb0
cmpq $0x0, %rax
je 0x96115
movq -0x40(%rbp), %rdi
callq 0x94900
movq -0xa8(%rbp), %rdi
callq 0x38620
callq 0x26880
movl $0x10, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x963d3
movl $0x138, %edi            # imm = 0x138
callq 0x3acd0
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0xa8(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
callq 0x95870
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
callq 0x2ff70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
callq 0x2ff70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
callq 0x2ff70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x50(%rax)
cmpq $0x0, -0x30(%rbp)
je 0x961cf
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x961dd
movl $0x7530, %eax           # imm = 0x7530
movq %rax, -0xb0(%rbp)
jmp 0x961dd
movq -0xb0(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xa0(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x98(%rax)
movq -0x38(%rbp), %rax
movl $0x64, 0xa8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xb0(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xc0(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0xc8(%rax)
movq -0x38(%rbp), %rax
movl $0x1, 0xcc(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xd0(%rax)
leaq 0xe10d8(%rip), %rdi     # 0x177340
xorl %eax, %eax
movl %eax, %esi
callq 0x2d330
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x80(%rax)
movl -0x28(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x38(%rbp), %rax
movl $0x1, 0x94(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0xb8(%rax)
leaq 0xe1090(%rip), %rdi     # 0x177340
xorl %eax, %eax
movl %eax, %esi
callq 0x2d330
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xd8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xe0(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xe8(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0xf0(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0xf8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x100(%rax)
movq -0x38(%rbp), %rax
movq $0x2bf20, 0x108(%rax) # imm = 0x2BF20
movq -0x38(%rbp), %rax
movq $0x0, 0x110(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x118(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x120(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x128(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x130(%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
andl $0x3, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x68(%rax)
callq 0x2ff70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x70(%rax)
callq 0x2ff70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x2d8c0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq