// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/scripting.c
// Function: ldbReplParseCommand
sds *ldbReplParseCommand(int *argcp) {
    sds *argv = NULL;
    int argc = 0;
    if (sdslen(ldb.cbuf) == 0) return NULL;

    /* Working on a copy is simpler in this case. We can modify it freely
     * for the sake of simpler parsing. */
    sds copy = sdsdup(ldb.cbuf);
    char *p = copy;

    /* This Redis protocol parser is a joke... just the simplest thing that
     * works in this context. It is also very forgiving regarding broken
     * protocol. */

    /* Seek and parse *<count>\r\n. */
    p = strchr(p,'*'); if (!p) goto protoerr;
    char *plen = p+1; /* Multi bulk len pointer. */
    p = strstr(p,"\r\n"); if (!p) goto protoerr;
    *p = '\0'; p += 2;
    *argcp = atoi(plen);
    if (*argcp <= 0 || *argcp > 1024) goto protoerr;

    /* Parse each argument. */
    argv = zmalloc(sizeof(sds)*(*argcp));
    argc = 0;
    while(argc < *argcp) {
        if (*p != '$') goto protoerr;
        plen = p+1; /* Bulk string len pointer. */
        p = strstr(p,"\r\n"); if (!p) goto protoerr;
        *p = '\0'; p += 2;
        int slen = atoi(plen); /* Length of this arg. */
        if (slen <= 0 || slen > 1024) goto protoerr;
        argv[argc++] = sdsnewlen(p,slen);
        p += slen; /* Skip the already parsed argument. */
        if (p[0] != '\r' || p[1] != '\n') goto protoerr;
        p += 2; /* Skip \r\n. */
    }
    sdsfree(copy);
    return argv;

protoerr:
    sdsfreesplitres(argv,argc);
    sdsfree(copy);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xa6e9e(%rip), %rdi     # 0x11b348
movzbl -0x1(%rdi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x744e4
leaq 0x582d9(%rip), %rdx     # 0xcc798
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x744e6
movq -0x11(%rdi), %rax
jmp 0x744e6
movzwl -0x5(%rdi), %eax
jmp 0x744e6
movl -0x9(%rdi), %eax
jmp 0x744e6
movzbl -0x3(%rdi), %eax
jmp 0x744e6
xorl %eax, %eax
xorl %r15d, %r15d
testq %rax, %rax
je 0x7455e
callq 0x39266
movq %rax, %r14
movq %rax, %rdi
movl $0x2a, %esi
callq 0x26800
testq %rax, %rax
je 0x74543
movq %rax, %r12
leaq 0x5285e(%rip), %rsi     # 0xc6d70
movq %rax, %rdi
callq 0x266c0
testq %rax, %rax
je 0x74540
movq %rax, %r13
incq %r12
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x26770
movl %eax, (%rbx)
leal -0x401(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jae 0x74573
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %rdi
movl %r15d, %esi
callq 0x3ab7f
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x392b6
jmp 0x74561
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x2, %r13
shll $0x3, %eax
movq %rax, %rdi
callq 0x3b29d
movq %rax, %r12
xorl %r15d, %r15d
cmpl (%rbx), %r15d
jge 0x74554
cmpb $0x24, (%r13)
jne 0x74546
movq %r13, %rdi
leaq 0x527d2(%rip), %rsi     # 0xc6d70
callq 0x266c0
testq %rax, %rax
je 0x74546
movq %rax, %rbp
incq %r13
movb $0x0, (%rax)
addq $0x2, %rbp
movq %r13, %rdi
callq 0x26770
leal -0x401(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jae 0x745cf
xorl %eax, %eax
jmp 0x74609
movl %eax, %r13d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3910c
movslq %r15d, %rcx
incl %r15d
movq %rax, (%r12,%rcx,8)
movq %rbp, %rcx
addq %r13, %rcx
cmpb $0xd, (%rbp,%r13)
jne 0x74604
xorl %eax, %eax
cmpb $0xa, 0x1(%rcx)
sete %al
leaq (%rcx,%rax,2), %rbp
jmp 0x74609
xorl %eax, %eax
movq %rcx, %rbp
movq %rbp, %r13
testb %al, %al
jne 0x74588
jmp 0x74546