// File: /workspace/github_c_makefile_star2_O1/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 0x42215(%rip), %rsi     # 0x9ee63
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x5, %ebp
jne 0x5ccab
testl %eax, %eax
jne 0x5ccab
movq 0x20(%rbx), %rdi
callq 0x1f710
testl %eax, %eax
jle 0x5cd47
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 0x5c139
testq %rax, %rax
je 0x5cd9e
movb $0x1, %cl
jmp 0x5cd50
leaq 0x423c7(%rip), %rsi     # 0x9f079
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5ccf8
testl %eax, %eax
jne 0x5ccf8
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x98(%r14)
testl %eax, %eax
jle 0x5cd3b
movq %r14, %rdi
callq 0x5cbb9
jmp 0x5cd58
leaq 0x423d7(%rip), %rsi     # 0x9f0d6
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5cd5f
testl %eax, %eax
jne 0x5cd5f
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
cltq
movq %rax, 0x148(%r14)
testl %eax, %eax
jg 0x5cd58
leaq 0x42373(%rip), %rax     # 0x9f0b5
jmp 0x5cfb6
leaq 0x422ba(%rip), %rax     # 0x9f008
xorl %ecx, %ecx
testb %cl, %cl
je 0x5cfb6
xorl %eax, %eax
jmp 0x5cfb6
leaq 0x42381(%rip), %rsi     # 0x9f0e7
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5cdc9
testl %eax, %eax
jne 0x5cdc9
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x1f710
movl %eax, 0xd4(%r14)
jmp 0x5cd58
callq 0x1f810
movl (%rax), %eax
cmpl $0x16, %eax
je 0x5ce87
cmpl $0x10, %eax
je 0x5ce7b
cmpl $0x2, %eax
jne 0x5cca4
leaq 0x42276(%rip), %rax     # 0x9f03d
jmp 0x5cd4e
leaq 0x42326(%rip), %rsi     # 0x9f0f6
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5ce22
testl %eax, %eax
jne 0x5ce22
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x5ceff
movq 0x10(%rbx), %rdi
callq 0x281da
movq %rax, 0x160(%r14)
jmp 0x5cd58
leaq 0x4231b(%rip), %rsi     # 0x9f144
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5ce93
testl %eax, %eax
jne 0x5ce93
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0x1fa20
cmpl $-0x1, %eax
je 0x5cf61
movq 0x10(%rbx), %rdi
callq 0x281da
movq %rax, 0x168(%r14)
jmp 0x5cd58
leaq 0x421a3(%rip), %rax     # 0x9f025
jmp 0x5cd4e
leaq 0x421d7(%rip), %rax     # 0x9f065
jmp 0x5cd4e
leaq 0x42305(%rip), %rsi     # 0x9f19f
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5ced5
testl %eax, %eax
jne 0x5ced5
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x281da
movq %rax, 0xd8(%r14)
jmp 0x5cd58
leaq 0x422cd(%rip), %rsi     # 0x9f1a9
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x2, %ebp
jne 0x5cf0b
testl %eax, %eax
jne 0x5cf0b
movq 0x8(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
jmp 0x5cf48
leaq 0x42204(%rip), %rax     # 0x9f10a
jmp 0x5cfb6
leaq 0x3ff95(%rip), %rsi     # 0x9cea7
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5cf6a
testl %eax, %eax
jne 0x5cf6a
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
movq %rax, 0x18(%r14)
cmpq 0x81999(%rip), %rax     # 0xde8e8
jbe 0x5cd58
movq %rax, 0x8198c(%rip)     # 0xde8e8
jmp 0x5cd58
leaq 0x421f3(%rip), %rax     # 0x9f15b
jmp 0x5cfb6
leaq 0x42970(%rip), %rsi     # 0x9f8e1
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x3, %ebp
jne 0x5cfc1
testl %eax, %eax
jne 0x5cfc1
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5cfaf
movq %rax, %r14
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1fa00
movq %rax, 0x120(%r14)
jmp 0x5cd58
leaq 0x420db(%rip), %rax     # 0x9f091
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x421ef(%rip), %rsi     # 0x9f1b7
movq %r14, %rdi
callq 0x1f2e0
cmpl $0x4, %ebp
jne 0x5d028
testl %eax, %eax
jne 0x5d028
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5d0c3
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 0x5c139
testq %rax, %rax
setne %cl
leaq 0x421a0(%rip), %rax     # 0x9f1c3
jmp 0x5cd50
leaq 0x421b6(%rip), %rsi     # 0x9f1e5
movq %r14, %rdi
callq 0x1f2e0
movl %eax, %ecx
movl %ebp, %edx
andl $-0x2, %edx
leaq 0x421d4(%rip), %rax     # 0x9f219
cmpl $0x4, %edx
jne 0x5cfb6
testl %ecx, %ecx
jne 0x5cfb6
movq 0x8(%rbx), %rdi
callq 0x5c679
testq %rax, %rax
je 0x5d0c3
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 0x5c139
movq %rax, %r14
testq %rax, %rax
setne %cl
leaq 0x42155(%rip), %rax     # 0x9f1f4
cmpl $0x5, %ebp
jne 0x5cd50
testq %r14, %r14
je 0x5cd50
movq 0x20(%rbx), %rdi
callq 0x281da
movq %rax, 0x10(%r14)
jmp 0x5cca4
leaq 0x41fc7(%rip), %rax     # 0x9f091
jmp 0x5cd4e