// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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, %r14
movq 0xa597f(%rip), %rdi     # 0x1163a8
movzbl -0x1(%rdi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x70ade
leaq 0x58dee(%rip), %rdx     # 0xc9830
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x70a65
movq -0x11(%rdi), %rax
jmp 0x70a65
movzwl -0x5(%rdi), %eax
jmp 0x70a65
movl -0x9(%rdi), %eax
jmp 0x70a65
movzbl -0x3(%rdi), %eax
xorl %r15d, %r15d
testq %rax, %rax
je 0x70ade
callq 0x362e0
movq %rax, %rbx
movq %rax, %rdi
movl $0x2a, %esi
callq 0x267f0
testq %rax, %rax
je 0x70ac3
movq %rax, %r12
leaq 0x5334b(%rip), %rsi     # 0xc3ddc
movq %rax, %rdi
callq 0x266b0
testq %rax, %rax
je 0x70ac0
movq %rax, %r13
incq %r12
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x26760
movl %eax, (%r14)
leal -0x401(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jae 0x70af3
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %rdi
movl %r15d, %esi
callq 0x37c04
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x36330
jmp 0x70ae1
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shll $0x3, %eax
movq %rax, %rdi
callq 0x382d1
movq %rax, %r12
xorl %r15d, %r15d
movslq (%r14), %rax
cmpq %rax, %r15
jge 0x70ad4
leaq 0x2(%r13), %rdi
cmpb $0x24, (%rdi)
jne 0x70ac6
leaq 0x532c0(%rip), %rsi     # 0xc3ddc
callq 0x266b0
testq %rax, %rax
je 0x70ac6
movq %rax, %rbp
addq $0x3, %r13
movb $0x0, (%rax)
movq %r13, %rdi
callq 0x26760
leal -0x401(%rax), %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jb 0x70ac6
leaq 0x2(%rbp), %rdi
movl %eax, %r13d
movq %r13, %rsi
callq 0x36178
movq %rax, (%r12,%r15,8)
cmpb $0xd, 0x2(%rbp,%r13)
jne 0x70b77
addq %rbp, %r13
addq $0x2, %r13
incq %r15
cmpb $0xa, 0x1(%r13)
je 0x70b04
jmp 0x70ac6
incq %r15
jmp 0x70ac6