// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq 0x100756(%rip), %rdi    # 0x18ccd8
callq 0x895c0
cmpq $0x0, %rax
jne 0x8c59a
movq $0x0, -0x8(%rbp)
jmp 0x8c764
movq 0x100737(%rip), %rdi    # 0x18ccd8
callq 0x38560
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x2a, %esi
callq 0x267f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8c5d0
jmp 0x8c747
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xb1ca1(%rip), %rsi     # 0x13e288
callq 0x266c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8c5fc
jmp 0x8c747
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x26760
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x8c635
movq -0x10(%rbp), %rax
cmpl $0x400, (%rax)          # imm = 0x400
jle 0x8c63a
jmp 0x8c747
movq -0x10(%rbp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
callq 0x3acd0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x8c734
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
je 0x8c675
jmp 0x8c747
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xb1bfc(%rip), %rsi     # 0x13e288
callq 0x266c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8c6a1
jmp 0x8c747
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x26760
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x8c6cf
cmpl $0x400, -0x3c(%rbp)     # imm = 0x400
jle 0x8c6d1
jmp 0x8c747
movq -0x30(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x38230
movq %rax, %rdx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x8c721
movq -0x30(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0xa, %eax
je 0x8c723
jmp 0x8c747
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x8c655
movq -0x28(%rbp), %rdi
callq 0x38620
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8c764
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x3a270
movq -0x28(%rbp), %rdi
callq 0x38620
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop