// File: /workspace/github_c_makefile_star2_O3/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 0x4287d(%rip), %rsi     # 0x9eed3
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x5, %ebp
jne 0x5c6da
testl %eax, %eax
jne 0x5c6da
movq 0x20(%rbx), %rdi
callq 0x1f710
testl %eax, %eax
jle 0x5c77d
movl %eax, %ebp
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
movq %r14, %rdi
movl $0x1, %esi
movq %r15, %rdx
movl %eax, %ecx
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x5bb77
testq %rax, %rax
jne 0x5c95e
callq 0x1f810
movl (%rax), %eax
cmpl $0x16, %eax
je 0x5c889
cmpl $0x10, %eax
je 0x5c87d
cmpl $0x2, %eax
jne 0x5c95e
leaq 0x429d8(%rip), %rax     # 0x9f0ad
jmp 0x5caa6
leaq 0x42a08(%rip), %rsi     # 0x9f0e9
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c72a
testl %eax, %eax
jne 0x5c72a
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x98(%r14)
testl %eax, %eax
jle 0x5c771
movq %r14, %rdi
callq 0x5c5c1
jmp 0x5c95e
leaq 0x42a15(%rip), %rsi     # 0x9f146
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c789
testl %eax, %eax
jne 0x5c789
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x148(%r14)
testl %eax, %eax
jg 0x5c95e
leaq 0x429ad(%rip), %rax     # 0x9f125
jmp 0x5caa6
leaq 0x428f4(%rip), %rax     # 0x9f078
jmp 0x5caa6
leaq 0x429c7(%rip), %rsi     # 0x9f157
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c7cb
testl %eax, %eax
jne 0x5c7cb
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
movl %eax, 0xd4(%r14)
jmp 0x5c95e
leaq 0x42994(%rip), %rsi     # 0x9f166
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c824
testl %eax, %eax
jne 0x5c824
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x5c901
movq 0x10(%rbx), %rdi
callq 0x28486
movq %rax, 0x160(%r14)
jmp 0x5c95e
leaq 0x42989(%rip), %rsi     # 0x9f1b4
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c895
testl %eax, %eax
jne 0x5c895
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x5c965
movq 0x10(%rbx), %rdi
callq 0x28486
movq %rax, 0x168(%r14)
jmp 0x5c95e
leaq 0x42811(%rip), %rax     # 0x9f095
jmp 0x5caa6
leaq 0x42845(%rip), %rax     # 0x9f0d5
jmp 0x5caa6
leaq 0x42973(%rip), %rsi     # 0x9f20f
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c8d7
testl %eax, %eax
jne 0x5c8d7
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x28486
movq %rax, 0xd8(%r14)
jmp 0x5c95e
leaq 0x4293b(%rip), %rsi     # 0x9f219
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x2, %ebp
jne 0x5c90d
testl %eax, %eax
jne 0x5c90d
movq 0x8(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
jmp 0x5c94e
leaq 0x42872(%rip), %rax     # 0x9f17a
jmp 0x5caa6
leaq 0x405d3(%rip), %rsi     # 0x9cee7
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c971
testl %eax, %eax
jne 0x5c971
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
movq %rax, 0x18(%r14)
cmpq 0x81f93(%rip), %rax     # 0xde8e8
jbe 0x5c95e
movq %rax, 0x81f8a(%rip)     # 0xde8e8
xorl %eax, %eax
jmp 0x5caa6
leaq 0x4285f(%rip), %rax     # 0x9f1cb
jmp 0x5caa6
leaq 0x42fd9(%rip), %rsi     # 0x9f951
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5c9b7
testl %eax, %eax
jne 0x5c9b7
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
movq %rax, 0x120(%r14)
jmp 0x5c95e
leaq 0x42869(%rip), %rsi     # 0x9f227
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x4, %ebp
jne 0x5ca21
testl %eax, %eax
jne 0x5ca21
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
movl 0xd0(%r14), %r8d
xorl %edi, %edi
movl $0x2, %esi
movq %r15, %rdx
movl %eax, %ecx
movq %r14, %r9
callq 0x5bb77
testq %rax, %rax
jne 0x5c95e
leaq 0x42817(%rip), %rax     # 0x9f233
jmp 0x5caa6
leaq 0x4282d(%rip), %rsi     # 0x9f255
movq %r14, %rdi
callq 0x1f2e0
movl %eax, %ecx
movl %ebp, %edx
andl $-0x2, %edx
leaq 0x4284b(%rip), %rax     # 0x9f289
cmpl $0x4, %edx
jne 0x5caa6
testl %ecx, %ecx
jne 0x5caa6
movq 0x8(%rbx), %rdi
callq 0x5c08f
testq %rax, %rax
je 0x5ca9f
movq %rax, %r14
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rdi
callq 0x1f710
movl 0xd0(%r14), %r8d
xorl %edi, %edi
movl $0x4, %esi
movq %r15, %rdx
movl %eax, %ecx
movq %r14, %r9
callq 0x5bb77
movq %rax, %r14
cmpl $0x5, %ebp
jne 0x5cab1
testq %r14, %r14
je 0x5cab1
movq 0x20(%rbx), %rdi
callq 0x28486
movq %rax, 0x10(%r14)
jmp 0x5c95e
leaq 0x4265b(%rip), %rax     # 0x9f101
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
jne 0x5c95e
leaq 0x427a3(%rip), %rax     # 0x9f264
jmp 0x5caa6