// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/sentinel.c
// Function: sentinelHandleConfiguration
char *sentinelHandleConfiguration(char **argv, int argc) {
    sentinelRedisInstance *ri;

    // SENTINEL monitor 选项
    if (!strcasecmp(argv[0],"monitor") && argc == 5) {
        /* monitor <name> <host> <port> <quorum> */

        // 读入 quorum 参数
        int quorum = atoi(argv[4]);

        // 检查 quorum 参数必须大于 0
        if (quorum <= 0) return "Quorum must be 1 or greater.";

        // 创建主服务器实例
        if (createSentinelRedisInstance(argv[1],SRI_MASTER,argv[2],
                                        atoi(argv[3]),quorum,NULL) == NULL)
        {
            switch(errno) {
            case EBUSY: return "Duplicated master name.";
            case ENOENT: return "Can't resolve master instance hostname.";
            case EINVAL: return "Invalid port number";
            }
        }

    // SENTINEL down-after-milliseconds 选项
    } else if (!strcasecmp(argv[0],"down-after-milliseconds") && argc == 3) {

        /* down-after-milliseconds <name> <milliseconds> */

        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        // 设置选项
        ri->down_after_period = atoi(argv[2]);
        if (ri->down_after_period <= 0)
            return "negative or zero time parameter.";

        sentinelPropagateDownAfterPeriod(ri);

    // SENTINEL failover-timeout 选项
    } else if (!strcasecmp(argv[0],"failover-timeout") && argc == 3) {

        /* failover-timeout <name> <milliseconds> */

        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        // 设置选项
        ri->failover_timeout = atoi(argv[2]);
        if (ri->failover_timeout <= 0)
            return "negative or zero time parameter.";

   // Sentinel parallel-syncs 选项
   } else if (!strcasecmp(argv[0],"parallel-syncs") && argc == 3) {

        /* parallel-syncs <name> <milliseconds> */

        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        // 设置选项
        ri->parallel_syncs = atoi(argv[2]);

    // SENTINEL notification-script 选项
   } else if (!strcasecmp(argv[0],"notification-script") && argc == 3) {

        /* notification-script <name> <path> */
        
        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        // 检查给定路径所指向的文件是否存在，以及是否可执行
        if (access(argv[2],X_OK) == -1)
            return "Notification script seems non existing or non executable.";

        // 设置选项
        ri->notification_script = sdsnew(argv[2]);

    // SENTINEL client-reconfig-script 选项
   } else if (!strcasecmp(argv[0],"client-reconfig-script") && argc == 3) {

        /* client-reconfig-script <name> <path> */

        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";
        // 检查给定路径所指向的文件是否存在，以及是否可执行
        if (access(argv[2],X_OK) == -1)
            return "Client reconfiguration script seems non existing or "
                   "non executable.";

        // 设置选项
        ri->client_reconfig_script = sdsnew(argv[2]);

    // 设置 SENTINEL auth-pass 选项
   } else if (!strcasecmp(argv[0],"auth-pass") && argc == 3) {

        /* auth-pass <name> <password> */

        // 查找主服务器
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        // 设置选项
        ri->auth_pass = sdsnew(argv[2]);

    } else if (!strcasecmp(argv[0],"current-epoch") && argc == 2) {
        /* current-epoch <epoch> */
        unsigned long long current_epoch = strtoull(argv[1],NULL,10);
        if (current_epoch > sentinel.current_epoch)
            sentinel.current_epoch = current_epoch;

    // SENTINEL config-epoch 选项
    } else if (!strcasecmp(argv[0],"config-epoch") && argc == 3) {

        /* config-epoch <name> <epoch> */

        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";

        ri->config_epoch = strtoull(argv[2],NULL,10);
        /* The following update of current_epoch is not really useful as
         * now the current epoch is persisted on the config file, but
         * we leave this check here for redundancy. */
        if (ri->config_epoch > sentinel.current_epoch)
            sentinel.current_epoch = ri->config_epoch;

    } else if (!strcasecmp(argv[0],"leader-epoch") && argc == 3) {
        /* leader-epoch <name> <epoch> */
        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";
        ri->leader_epoch = strtoull(argv[2],NULL,10);

    // SENTINEL known-slave 选项
    } else if (!strcasecmp(argv[0],"known-slave") && argc == 4) {
        sentinelRedisInstance *slave;

        /* known-slave <name> <ip> <port> */

        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";
        if ((slave = createSentinelRedisInstance(NULL,SRI_SLAVE,argv[2],
                    atoi(argv[3]), ri->quorum, ri)) == NULL)
        {
            return "Wrong hostname or port for slave.";
        }

    // SENTINEL known-sentinel 选项
    } else if (!strcasecmp(argv[0],"known-sentinel") &&
               (argc == 4 || argc == 5)) {
        sentinelRedisInstance *si;

        /* known-sentinel <name> <ip> <port> [runid] */

        ri = sentinelGetMasterByName(argv[1]);
        if (!ri) return "No such master with specified name.";
        if ((si = createSentinelRedisInstance(NULL,SRI_SENTINEL,argv[2],
                    atoi(argv[3]), ri->quorum, ri)) == NULL)
        {
            return "Wrong hostname or port for sentinel.";
        }
        if (argc == 5) si->runid = sdsnew(argv[4]);

    } else {
        return "Unrecognized sentinel configuration statement.";
    }
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq (%rdi), %r14
leaq 0x3d2b0(%rip), %rsi     # 0x94e47
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x5, %ebp
jne 0x57c19
testl %eax, %eax
jne 0x57c19
movq 0x20(%rbx), %rdi
callq 0x1f710
testl %eax, %eax
jle 0x57cbc
movl %eax, %ebp
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %r15, %rdx
movl %eax, %ecx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x5715c
testq %rax, %rax
jne 0x57e95
callq 0x1f810
movl (%rax), %eax
cmpl $0x16, %eax
je 0x57dc4
cmpl $0x10, %eax
je 0x57db8
cmpl $0x2, %eax
jne 0x57e95
leaq 0x3d40d(%rip), %rax     # 0x95021
jmp 0x57fd7
leaq 0x3d43d(%rip), %rsi     # 0x9505d
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57c69
testl %eax, %eax
jne 0x57c69
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x98(%r14)
testl %eax, %eax
jle 0x57cb0
movq %r14, %rdi
callq 0x57b0b
jmp 0x57e95
leaq 0x3d44a(%rip), %rsi     # 0x950ba
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57cc8
testl %eax, %eax
jne 0x57cc8
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x148(%r14)
testl %eax, %eax
jg 0x57e95
leaq 0x3d3e2(%rip), %rax     # 0x95099
jmp 0x57fd7
leaq 0x3d329(%rip), %rax     # 0x94fec
jmp 0x57fd7
leaq 0x3d3fc(%rip), %rsi     # 0x950cb
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57d0a
testl %eax, %eax
jne 0x57d0a
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
movl %eax, 0xd4(%r14)
jmp 0x57e95
leaq 0x3d3c9(%rip), %rsi     # 0x950da
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57d61
testl %eax, %eax
jne 0x57d61
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x57e3a
movq 0x10(%rbx), %rdi
callq 0x271cd
movq %rax, 0x160(%r14)
jmp 0x57e95
leaq 0x3d3c0(%rip), %rsi     # 0x95128
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57dd0
testl %eax, %eax
jne 0x57dd0
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x57e9c
movq 0x10(%rbx), %rdi
callq 0x271cd
movq %rax, 0x168(%r14)
jmp 0x57e95
leaq 0x3d24a(%rip), %rax     # 0x95009
jmp 0x57fd7
leaq 0x3d27e(%rip), %rax     # 0x95049
jmp 0x57fd7
leaq 0x3d3ac(%rip), %rsi     # 0x95183
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57e12
testl %eax, %eax
jne 0x57e12
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x271cd
movq %rax, 0xd8(%r14)
jmp 0x57e95
leaq 0x3d374(%rip), %rsi     # 0x9518d
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x2, %ebp
jne 0x57e46
testl %eax, %eax
jne 0x57e46
movq 0x8(%rbx), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1fa00
jmp 0x57e85
leaq 0x3d2ad(%rip), %rax     # 0x950ee
jmp 0x57fd7
leaq 0x3b05a(%rip), %rsi     # 0x92ea7
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57ea8
testl %eax, %eax
jne 0x57ea8
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1fa00
movq %rax, 0x18(%r14)
cmpq 0x83a5c(%rip), %rax     # 0xdb8e8
jbe 0x57e95
movq %rax, 0x83a53(%rip)     # 0xdb8e8
xorl %eax, %eax
jmp 0x57fd7
leaq 0x3d29c(%rip), %rax     # 0x9513f
jmp 0x57fd7
leaq 0x3da16(%rip), %rsi     # 0x958c5
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x57eec
testl %eax, %eax
jne 0x57eec
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1fa00
movq %rax, 0x120(%r14)
jmp 0x57e95
leaq 0x3d2a8(%rip), %rsi     # 0x9519b
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x4, %ebp
jne 0x57f54
testl %eax, %eax
jne 0x57f54
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
movl 0xd0(%r14), %r8d
pushq $0x2
popq %rsi
xorl %edi, %edi
movq %r15, %rdx
movl %eax, %ecx
movq %r14, %r9
callq 0x5715c
testq %rax, %rax
jne 0x57e95
leaq 0x3d258(%rip), %rax     # 0x951a7
jmp 0x57fd7
leaq 0x3d26e(%rip), %rsi     # 0x951c9
movq %r14, %rdi
callq 0x1f2e0
movl %eax, %ecx
movl %ebp, %edx
andl $-0x2, %edx
leaq 0x3d28c(%rip), %rax     # 0x951fd
cmpl $0x4, %edx
jne 0x57fd7
testl %ecx, %ecx
jne 0x57fd7
movq 0x8(%rbx), %rdi
callq 0x5764f
testq %rax, %rax
je 0x57fd0
movq %rax, %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
movl 0xd0(%r14), %r8d
pushq $0x4
popq %rsi
xorl %edi, %edi
movq %r15, %rdx
movl %eax, %ecx
movq %r14, %r9
callq 0x5715c
movq %rax, %r14
cmpl $0x5, %ebp
jne 0x57fe2
testq %r14, %r14
je 0x57fe2
movq 0x20(%rbx), %rdi
callq 0x271cd
movq %rax, 0x10(%r14)
jmp 0x57e95
leaq 0x3d09e(%rip), %rax     # 0x95075
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
jne 0x57e95
leaq 0x3d1e6(%rip), %rax     # 0x951d8
jmp 0x57fd7