// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/deps/hiredis/hiredis.c
// Function: redisvFormatCommand
int redisvFormatCommand(char **target, const char *format, va_list ap) {
    const char *c = format;
    char *cmd = NULL; /* final command */
    int pos; /* position in final command */
    sds curarg, newarg; /* current argument */
    int touched = 0; /* was the current argument touched? */
    char **curargv = NULL, **newargv = NULL;
    int argc = 0;
    int totlen = 0;
    int j;

    /* Abort if there is not target to set */
    if (target == NULL)
        return -1;

    /* Build the command string accordingly to protocol */
    curarg = sdsempty();
    if (curarg == NULL)
        return -1;

    while(*c != '\0') {
        if (*c != '%' || c[1] == '\0') {
            if (*c == ' ') {
                if (touched) {
                    newargv = realloc(curargv,sizeof(char*)*(argc+1));
                    if (newargv == NULL) goto err;
                    curargv = newargv;
                    curargv[argc++] = curarg;
                    totlen += bulklen(sdslen(curarg));

                    /* curarg is put in argv so it can be overwritten. */
                    curarg = sdsempty();
                    if (curarg == NULL) goto err;
                    touched = 0;
                }
            } else {
                newarg = sdscatlen(curarg,c,1);
                if (newarg == NULL) goto err;
                curarg = newarg;
                touched = 1;
            }
        } else {
            char *arg;
            size_t size;

            /* Set newarg so it can be checked even if it is not touched. */
            newarg = curarg;

            switch(c[1]) {
            case 's':
                arg = va_arg(ap,char*);
                size = strlen(arg);
                if (size > 0)
                    newarg = sdscatlen(curarg,arg,size);
                break;
            case 'b':
                arg = va_arg(ap,char*);
                size = va_arg(ap,size_t);
                if (size > 0)
                    newarg = sdscatlen(curarg,arg,size);
                break;
            case '%':
                newarg = sdscat(curarg,"%");
                break;
            default:
                /* Try to detect printf format */
                {
                    static const char intfmts[] = "diouxX";
                    char _format[16];
                    const char *_p = c+1;
                    size_t _l = 0;
                    va_list _cpy;

                    /* Flags */
                    if (*_p != '\0' && *_p == '#') _p++;
                    if (*_p != '\0' && *_p == '0') _p++;
                    if (*_p != '\0' && *_p == '-') _p++;
                    if (*_p != '\0' && *_p == ' ') _p++;
                    if (*_p != '\0' && *_p == '+') _p++;

                    /* Field width */
                    while (*_p != '\0' && isdigit(*_p)) _p++;

                    /* Precision */
                    if (*_p == '.') {
                        _p++;
                        while (*_p != '\0' && isdigit(*_p)) _p++;
                    }

                    /* Copy va_list before consuming with va_arg */
                    va_copy(_cpy,ap);

                    /* Integer conversion (without modifiers) */
                    if (strchr(intfmts,*_p) != NULL) {
                        va_arg(ap,int);
                        goto fmt_valid;
                    }

                    /* Double conversion (without modifiers) */
                    if (strchr("eEfFgGaA",*_p) != NULL) {
                        va_arg(ap,double);
                        goto fmt_valid;
                    }

                    /* Size: char */
                    if (_p[0] == 'h' && _p[1] == 'h') {
                        _p += 2;
                        if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
                            va_arg(ap,int); /* char gets promoted to int */
                            goto fmt_valid;
                        }
                        goto fmt_invalid;
                    }

                    /* Size: short */
                    if (_p[0] == 'h') {
                        _p += 1;
                        if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
                            va_arg(ap,int); /* short gets promoted to int */
                            goto fmt_valid;
                        }
                        goto fmt_invalid;
                    }

                    /* Size: long long */
                    if (_p[0] == 'l' && _p[1] == 'l') {
                        _p += 2;
                        if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
                            va_arg(ap,long long);
                            goto fmt_valid;
                        }
                        goto fmt_invalid;
                    }

                    /* Size: long */
                    if (_p[0] == 'l') {
                        _p += 1;
                        if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
                            va_arg(ap,long);
                            goto fmt_valid;
                        }
                        goto fmt_invalid;
                    }

                fmt_invalid:
                    va_end(_cpy);
                    goto err;

                fmt_valid:
                    _l = (_p+1)-c;
                    if (_l < sizeof(_format)-2) {
                        memcpy(_format,c,_l);
                        _format[_l] = '\0';
                        newarg = sdscatvprintf(curarg,_format,_cpy);

                        /* Update current position (note: outer blocks
                         * increment c twice so compensate here) */
                        c = _p-1;
                    }

                    va_end(_cpy);
                    break;
                }
            }

            if (newarg == NULL) goto err;
            curarg = newarg;

            touched = 1;
            c++;
        }
        c++;
    }

    /* Add the last argument if needed */
    if (touched) {
        newargv = realloc(curargv,sizeof(char*)*(argc+1));
        if (newargv == NULL) goto err;
        curargv = newargv;
        curargv[argc++] = curarg;
        totlen += bulklen(sdslen(curarg));
    } else {
        sdsfree(curarg);
    }

    /* Clear curarg because it was put in curargv or was free'd. */
    curarg = NULL;

    /* Add bytes needed to hold multi bulk count */
    totlen += 1+intlen(argc)+2;

    /* Build the command at protocol level */
    cmd = malloc(totlen+1);
    if (cmd == NULL) goto err;

    pos = sprintf(cmd,"*%d\r\n",argc);
    for (j = 0; j < argc; j++) {
        pos += sprintf(cmd+pos,"$%zu\r\n",sdslen(curargv[j]));
        memcpy(cmd+pos,curargv[j],sdslen(curargv[j]));
        pos += sdslen(curargv[j]);
        sdsfree(curargv[j]);
        cmd[pos++] = '\r';
        cmd[pos++] = '\n';
    }
    assert(pos == totlen);
    cmd[pos] = '\0';

    free(curargv);
    *target = cmd;
    return totlen;

err:
    while(argc--)
        sdsfree(curargv[argc]);
    free(curargv);

    if (curarg != NULL)
        sdsfree(curarg);

    /* No need to check cmd since it is the last statement that can fail,
     * but do it anyway to be as defensive as possible. */
    if (cmd != NULL)
        free(cmd);

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x17199
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
callq 0x1846f
testq %rax, %rax
je 0x17199
movq %rax, %r15
movq %rbx, 0x38(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %r14, 0x10(%rsp)
movq %r12, %rbx
xorl %r12d, %r12d
movzbl (%rbx), %eax
cmpl $0x20, %eax
je 0x16b96
cmpl $0x25, %eax
je 0x16a79
testl %eax, %eax
je 0x16f0e
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x18c9d
testq %rax, %rax
je 0x17164
movl $0x1, %r12d
movq %rax, %r15
jmp 0x16f02
movzbl 0x1(%rbx), %ecx
cmpl $0x61, %ecx
jg 0x16aa3
testl %ecx, %ecx
je 0x16b8e
cmpl $0x25, %ecx
jne 0x16ad0
movq %r15, %rdi
leaq 0x23900(%rip), %rsi     # 0x3a399
callq 0x18d6d
jmp 0x16ee3
cmpl $0x62, %ecx
je 0x16bf2
cmpl $0x73, %ecx
jne 0x16ad0
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x16c84
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x16c90
movq %r12, 0x20(%rsp)
movq %r15, 0x8(%rsp)
movl %ebp, 0x2c(%rsp)
leaq 0x1(%rbx), %rdx
leaq 0x2(%rbx), %rax
xorl %ecx, %ecx
cmpb $0x23, 0x1(%rbx)
cmoveq %rax, %rdx
sete %cl
xorl %esi, %esi
movq %rbx, 0x30(%rsp)
cmpb $0x30, 0x1(%rcx,%rbx)
sete %sil
leaq (%rdx,%rsi), %rax
xorl %r15d, %r15d
cmpb $0x2d, (%rdx,%rsi)
sete %r15b
leaq (%rax,%r15), %rcx
xorl %ebx, %ebx
cmpb $0x20, (%r15,%rax)
sete %bl
leaq (%rcx,%rbx), %r14
xorl %ebp, %ebp
cmpb $0x2b, (%rbx,%rcx)
sete %bpl
movb (%rbp,%r14), %r12b
addq %rbp, %r14
testb %r12b, %r12b
je 0x16cf8
movq %rdx, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
callq 0xb5d0
movq (%rax), %rcx
addq %rbx, %rbp
addq 0x40(%rsp), %r15
addq %rbp, %r15
movq 0x48(%rsp), %rax
addq %r15, %rax
incq %rax
movl 0x2c(%rsp), %ebp
movsbq %r12b, %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x16d13
movb 0x1(%r14), %r12b
incq %r14
incq %rax
testb %r12b, %r12b
jne 0x16b6b
jmp 0x16d38
cmpb $0x20, %al
jne 0x16a52
testl %r12d, %r12d
je 0x16bea
movq %rbx, %r12
movslq %ebp, %rbx
leaq 0x8(,%rbx,8), %rsi
movq 0x18(%rsp), %rdi
callq 0xb3d0
testq %rax, %rax
je 0x17164
movq %rax, %r14
movq %r15, (%rax,%rbx,8)
movzbl -0x1(%r15), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x16c2b
leaq 0x236b3(%rip), %rdx     # 0x3a28c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %r12, %rbx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x16c30
xorl %r12d, %r12d
jmp 0x16f02
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x16cb0
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x16cbc
movq -0x11(%r15), %rax
jmp 0x16c30
movzwl -0x5(%r15), %eax
jmp 0x16c30
movl -0x9(%r15), %eax
jmp 0x16c30
movzbl -0x3(%r15), %eax
jmp 0x16c30
xorl %eax, %eax
movq %r12, %rbx
incl %ebp
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %eax, %edx
shrl $0x1f, %edx
addl %edx, %r13d
addl %eax, %r13d
addl $0x5, %r13d
movl $0xcccccccd, %edx       # imm = 0xCCCCCCCD
movl %ecx, %eax
imulq %rdx, %rax
shrq $0x23, %rax
incl %r13d
cmpl $0x9, %ecx
movl %eax, %ecx
ja 0x16c4d
callq 0x1846f
xorl %r12d, %r12d
testq %rax, %rax
je 0x16f59
movq %rax, %r15
movq %r14, 0x18(%rsp)
movq 0x10(%rsp), %r14
jmp 0x16f02
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq %r14, %rdi
callq 0xb190
testq %rax, %rax
je 0x16cfe
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x18c9d
jmp 0x16d01
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x16cd7
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x16ce3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rdx
testq %rdx, %rdx
je 0x16d0b
movq %r15, %rdi
callq 0x18c9d
jmp 0x16ee3
movl 0x2c(%rsp), %ebp
jmp 0x16d38
movq %r15, %rax
movq 0x10(%rsp), %r14
jmp 0x16ee3
movq %r15, %rax
jmp 0x16ee3
cmpb $0x2e, %r12b
jne 0x16d38
movq %rax, %r14
movsbq (%rax), %rbx
testq %rbx, %rbx
je 0x16d38
callq 0xb5d0
movq (%rax), %rcx
leaq 0x1(%r14), %rax
testb $0x8, 0x1(%rcx,%rbx,2)
jne 0x16d19
movq 0x10(%rsp), %rbx
movq 0x10(%rbx), %rax
movq %rax, 0x60(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0x50(%rsp)
movsbl (%r14), %r15d
movl $0x7, %edx
leaq 0x235e2(%rip), %rdi     # 0x3a340
movl %r15d, %esi
callq 0xb270
testq %rax, %rax
je 0x16d7e
movl (%rbx), %eax
cmpl $0x28, %eax
movq 0x20(%rsp), %r12
ja 0x16dbc
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x16dc1
movl $0x9, %edx
leaq 0x23611(%rip), %rdi     # 0x3a39b
movl %r15d, %esi
callq 0xb270
testq %rax, %rax
movq 0x20(%rsp), %r12
je 0x16e1b
movq 0x10(%rsp), %rcx
movl 0x4(%rcx), %eax
cmpl $0xa0, %eax
movq 0x30(%rsp), %rbx
ja 0x16ec6
addl $0x10, %eax
movl %eax, 0x4(%rcx)
jmp 0x16dc6
addq $0x8, 0x8(%rbx)
movq 0x30(%rsp), %rbx
movq %r14, %r15
subq %rbx, %r15
incq %r15
movb $0x1, %cl
cmpq $0xd, %r15
ja 0x16ed2
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0xb340
movb $0x0, 0x70(%rsp,%r15)
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq 0x20(%rsp), %r12
leaq 0x50(%rsp), %rdx
callq 0x1900f
movb $0x1, %cl
decq %r14
movq %r14, %rbx
jmp 0x16eda
cmpb $0x6c, %r15b
movq 0x30(%rsp), %rbx
je 0x16e4e
movzbl %r15b, %eax
cmpl $0x68, %eax
jne 0x16ed0
cmpb $0x68, 0x1(%r14)
je 0x16e55
cmpb $0x6c, %r15b
je 0x16e4e
movzbl %r15b, %eax
cmpl $0x68, %eax
je 0x16e89
jmp 0x16ed0
cmpb $0x6c, 0x1(%r14)
jne 0x16e83
movsbl 0x2(%r14), %esi
testl %esi, %esi
je 0x16ed0
movl $0x7, %edx
leaq 0x234d6(%rip), %rdi     # 0x3a340
callq 0xb270
testq %rax, %rax
movq 0x8(%rsp), %r15
je 0x16f0a
addq $0x2, %r14
jmp 0x16eb0
cmpb $0x6c, %r15b
jne 0x16ed0
movsbl 0x1(%r14), %esi
testl %esi, %esi
movq 0x8(%rsp), %r15
je 0x16f0a
movl $0x7, %edx
leaq 0x2349d(%rip), %rdi     # 0x3a340
callq 0xb270
testq %rax, %rax
je 0x16f0a
incq %r14
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
cmpl $0x28, %eax
ja 0x16ec6
addl $0x8, %eax
movl %eax, (%rcx)
jmp 0x16dc6
addq $0x8, 0x8(%rcx)
jmp 0x16dc6
xorl %ecx, %ecx
movq 0x8(%rsp), %r15
movq %r15, %rax
testb %cl, %cl
movq 0x10(%rsp), %r14
je 0x16ef8
testq %rax, %rax
je 0x16ef8
incq %rbx
movb $0x1, %cl
movl $0x1, %r12d
movq %rax, %r15
jmp 0x16efa
xorl %ecx, %ecx
testb %cl, %cl
je 0x17164
incq %rbx
jmp 0x16a39
xorl %ecx, %ecx
jmp 0x16ed7
testl %r12d, %r12d
je 0x16f66
movslq %ebp, %rbx
leaq 0x8(,%rbx,8), %rsi
movq 0x18(%rsp), %rdi
callq 0xb3d0
testq %rax, %rax
je 0x17164
movq %r15, (%rax,%rbx,8)
movzbl -0x1(%r15), %ecx
movl %ecx, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x16f8a
leaq 0x23355(%rip), %rsi     # 0x3a2a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %ecx
jmp 0x16f8c
xorl %r15d, %r15d
movq %r14, 0x18(%rsp)
jmp 0x17164
movq %r15, %rdi
callq 0x18503
jmp 0x16fc1
movq -0x11(%r15), %rcx
jmp 0x16f8c
movzwl -0x5(%r15), %ecx
jmp 0x16f8c
movl -0x9(%r15), %ecx
jmp 0x16f8c
movzbl -0x3(%r15), %ecx
jmp 0x16f8c
xorl %ecx, %ecx
incl %ebp
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %ecx, %esi
shrl $0x1f, %esi
addl %ecx, %esi
addl %esi, %r13d
addl $0x5, %r13d
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
movl %edx, %esi
imulq %rcx, %rsi
shrq $0x23, %rsi
incl %r13d
cmpl $0xa, %edx
movl %esi, %edx
jae 0x16fa8
movq %rax, 0x18(%rsp)
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
movl %ebp, %r15d
sarl $0x1f, %r15d
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
movl %eax, %edx
imulq %rcx, %rdx
shrq $0x23, %rdx
decl %r15d
cmpl $0x9, %eax
movl %edx, %eax
ja 0x16fd4
movl %r13d, %ebx
subl %r15d, %ebx
leal 0x4(%rbx), %eax
movslq %eax, %rdi
callq 0xb390
testq %rax, %rax
je 0x17161
movq %rax, %r14
movq %rbx, 0x8(%rsp)
leaq 0x23393(%rip), %rsi     # 0x3a3a4
movq %rax, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xb4f0
movl %ebp, %ecx
movl %eax, %ebp
testl %ecx, %ecx
movq %r14, 0x10(%rsp)
jle 0x171ad
movq %r14, %rbx
movl %ecx, %eax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
movq (%rdi,%r14,8), %rax
movzbl -0x1(%rax), %edx
movl %edx, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1707e
leaq 0x2325b(%rip), %rsi     # 0x3a2b4
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
shrl $0x3, %edx
jmp 0x17080
movq -0x11(%rax), %rdx
jmp 0x17080
movzwl -0x5(%rax), %edx
jmp 0x17080
movl -0x9(%rax), %edx
jmp 0x17080
movzbl -0x3(%rax), %edx
jmp 0x17080
xorl %edx, %edx
movslq %ebp, %rdi
addq %rbx, %rdi
leaq 0x2331d(%rip), %rsi     # 0x3a3aa
xorl %eax, %eax
callq 0xb4f0
movl %eax, %r12d
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x170da
leaq 0x23213(%rip), %rcx     # 0x3a2c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x170dc
movq -0x11(%rsi), %rdx
jmp 0x170dc
movzwl -0x5(%rsi), %edx
jmp 0x170dc
movl -0x9(%rsi), %edx
jmp 0x170dc
movzbl -0x3(%rsi), %edx
jmp 0x170dc
xorl %edx, %edx
addl %ebp, %r12d
movslq %r12d, %rdi
addq %rbx, %rdi
callq 0xb340
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rdi
movzbl -0x1(%rdi), %ebp
movl %ebp, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x1712d
leaq 0x231d4(%rip), %rcx     # 0x3a2dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %ebp
jmp 0x1712f
movq -0x11(%rdi), %rbp
jmp 0x1712f
movzwl -0x5(%rdi), %ebp
jmp 0x1712f
movl -0x9(%rdi), %ebp
jmp 0x1712f
movzbl -0x3(%rdi), %ebp
jmp 0x1712f
xorl %ebp, %ebp
leal (%r12,%rbp), %ebx
callq 0x18503
movslq %ebx, %rax
movq 0x10(%rsp), %rbx
movw $0xa0d, (%rbx,%rax)     # imm = 0xA0D
addl %r12d, %ebp
addl $0x2, %ebp
incq %r14
cmpq %r14, 0x20(%rsp)
movq 0x18(%rsp), %rdi
jne 0x17040
jmp 0x171b2
xorl %r15d, %r15d
testl %ebp, %ebp
movq 0x18(%rsp), %r14
je 0x1717f
movslq %ebp, %rbx
movq -0x8(%r14,%rbx,8), %rdi
callq 0x18503
decq %rbx
jne 0x17170
movq %r14, %rdi
callq 0xb050
testq %r15, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
je 0x17199
movq %r15, %rdi
callq 0x18503
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rdi
subl %ebp, %r13d
addl $0x3, %r13d
cmpl %r15d, %r13d
jne 0x171e4
movq 0x8(%rsp), %rbx
addl $0x3, %ebx
movslq %ebp, %rax
movq 0x10(%rsp), %r14
movb $0x0, (%r14,%rax)
callq 0xb050
movq 0x38(%rsp), %rax
movq %r14, (%rax)
movl %ebx, %ebp
jmp 0x17199
leaq 0x231c6(%rip), %rdi     # 0x3a3b1
leaq 0x23164(%rip), %rsi     # 0x3a356
leaq 0x231c6(%rip), %rcx     # 0x3a3bf
movl $0x37a, %edx            # imm = 0x37A
callq 0xb210