// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/sentinel.c
// Function: sentinelScheduleScriptExecution
void sentinelScheduleScriptExecution(char *path, ...) {
    va_list ap;
    char *argv[SENTINEL_SCRIPT_MAX_ARGS+1];
    int argc = 1;
    sentinelScriptJob *sj;

    // 生成参数
    va_start(ap, path);
    while(argc < SENTINEL_SCRIPT_MAX_ARGS) {
        argv[argc] = va_arg(ap,char*);
        if (!argv[argc]) break;
        argv[argc] = sdsnew(argv[argc]); /* Copy the string. */
        argc++;
    }
    va_end(ap);
    argv[0] = sdsnew(path);
    
    // 初始化脚本结构
    sj = zmalloc(sizeof(*sj));
    sj->flags = SENTINEL_SCRIPT_NONE;
    sj->retry_num = 0;
    sj->argv = zmalloc(sizeof(char*)*(argc+1));
    sj->start_time = 0;
    sj->pid = 0;
    memcpy(sj->argv,argv,sizeof(char*)*(argc+1));

    // 添加到等待执行脚本队列的末尾， FIFO
    listAddNodeTail(sentinel.scripts_queue,sj);

    /* Remove the oldest non running script if we already hit the limit. */
    // 如果入队的脚本数量太多，那么移除最旧的未执行脚本
    if (listLength(sentinel.scripts_queue) > SENTINEL_SCRIPT_MAX_QUEUE) {
        listNode *ln;
        listIter li;

        listRewind(sentinel.scripts_queue,&li);
        while ((ln = listNext(&li)) != NULL) {
            sj = ln->value;

            // 不删除正在运行的脚本
            if (sj->flags & SENTINEL_SCRIPT_RUNNING) continue;
            /* The first node is the oldest as we add on tail. */
            listDelNode(sentinel.scripts_queue,ln);
            sentinelReleaseScriptJob(sj);
            break;
        }
        redisAssert(listLength(sentinel.scripts_queue) <=
                    SENTINEL_SCRIPT_MAX_QUEUE);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
leaq 0xc0(%rsp), %rdi
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %r8, 0x20(%rdi)
movq %r9, 0x28(%rdi)
testb %al, %al
je 0x5b99f
movaps %xmm0, 0xf0(%rsp)
movaps %xmm1, 0x100(%rsp)
movaps %xmm2, 0x110(%rsp)
movaps %xmm3, 0x120(%rsp)
movaps %xmm4, 0x130(%rsp)
movaps %xmm5, 0x140(%rsp)
movaps %xmm6, 0x150(%rsp)
movaps %xmm7, 0x160(%rsp)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rsp)
leaq 0x1a0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movl $0x1, %r15d
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x5b9de
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x5b9ec
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdi
movq %rdi, 0x30(%rsp,%r15,8)
testq %rdi, %rdi
je 0x5ba12
callq 0x281da
movq %rax, 0x30(%rsp,%r15,8)
incq %r15
cmpq $0x10, %r15
jne 0x5b9c5
movl $0x10, %r15d
movq %rbx, %rdi
callq 0x281da
leaq 0x30(%rsp), %rbx
movq %rax, (%rbx)
movl $0x20, %edi
callq 0x29709
movq %rax, %r14
xorl %r12d, %r12d
movq %r12, (%rax)
leaq 0x8(,%r15,8), %rax
movabsq $0x7fffffff8, %r15      # imm = 0x7FFFFFFF8
andq %rax, %r15
movq %r15, %rdi
callq 0x29709
movq %rax, 0x8(%r14)
movq %r12, 0x10(%r14)
movl $0x0, 0x18(%r14)
movq %rax, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1fbd0
movq 0x82e99(%rip), %rdi     # 0xde910
movq %r14, %rsi
callq 0x2045f
movq 0x82e8a(%rip), %rdi     # 0xde910
cmpq $0x101, 0x28(%rdi)      # imm = 0x101
jb 0x5badc
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x205d2
movq %rbx, %rdi
callq 0x205ef
testq %rax, %rax
je 0x5bacb
movq 0x10(%rax), %r14
testb $0x1, (%r14)
jne 0x5ba9d
movq 0x82e55(%rip), %rdi     # 0xde910
movq %rax, %rsi
callq 0x20544
movq %r14, %rdi
callq 0x5bb0d
movq 0x82e3e(%rip), %rax     # 0xde910
cmpq $0x101, 0x28(%rax)      # imm = 0x101
jae 0x5baeb
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x43386(%rip), %rdi     # 0x9ee78
leaq 0x432bb(%rip), %rsi     # 0x9edb4
movl $0x3c9, %edx            # imm = 0x3C9
callq 0x4d037
movl $0x1, %edi
callq 0x1f3b0