// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 $0x68, %rsp
movq %rdx, 0x10(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x1c489
movq %rsi, %r15
movq %rdi, %rbx
callq 0x1d966
testq %rax, %rax
je 0x1c489
movq %rbx, 0x20(%rsp)
xorl %ecx, %ecx
xorl %r12d, %r12d
movl $0x0, (%rsp)
xorl %r13d, %r13d
movq %rax, %rbp
movq 0x10(%rsp), %rbx
movzbl (%r15), %eax
cmpl $0x20, %eax
je 0x1c04c
cmpl $0x25, %eax
je 0x1c01b
testl %eax, %eax
je 0x1c49a
movl $0x1, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1e1ae
testq %rax, %rax
jne 0x1c43d
jmp 0x1c44d
movb 0x1(%r15), %al
movzbl %al, %ecx
cmpl $0x61, %ecx
jg 0x1c0ac
testl %ecx, %ecx
je 0x1bffd
cmpl $0x25, %ecx
jne 0x1c0de
movq %rbp, %rdi
leaq 0x2a9af(%rip), %rsi     # 0x469f1
callq 0x1e279
jmp 0x1c435
testl %ecx, %ecx
je 0x1c0d7
movslq (%rsp), %rbx
leaq 0x8(,%rbx,8), %rsi
movq %r12, %rdi
callq 0x104b0
testq %rax, %rax
je 0x1c44d
movq %rax, %r14
movq %rbp, (%rax,%rbx,8)
movzbl -0x1(%rbp), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1c1e8
leaq 0x2a853(%rip), %rdx     # 0x468e4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq 0x10(%rsp), %rbx
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
jmpq *%rcx
shrl $0x3, %eax
jmp 0x1c1f4
cmpl $0x62, %ecx
je 0x1c19d
cmpl $0x73, %ecx
jne 0x1c0de
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x1c23c
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x1c248
xorl %ecx, %ecx
jmp 0x1c445
movq %rbp, 0x8(%rsp)
movq %r12, 0x18(%rsp)
leaq 0x1(%r15), %rsi
leaq 0x2(%r15), %rcx
xorl %edx, %edx
cmpb $0x23, %al
cmoveq %rcx, %rsi
sete %dl
xorl %edi, %edi
movq %r15, 0x38(%rsp)
cmpb $0x30, 0x1(%rdx,%r15)
sete %dil
leaq (%rsi,%rdi), %rax
xorl %r15d, %r15d
cmpb $0x2d, (%rsi,%rdi)
sete %r15b
leaq (%rax,%r15), %rcx
xorl %ebp, %ebp
cmpb $0x20, (%r15,%rax)
sete %bpl
leaq (%rcx,%rbp), %r14
xorl %ebx, %ebx
cmpb $0x2b, (%rbp,%rcx)
sete %bl
movb (%rbx,%r14), %r12b
addq %rbx, %r14
testb %r12b, %r12b
je 0x1c29b
movq %rsi, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
callq 0x10710
movq (%rax), %rax
addq %rbp, %rbx
addq 0x28(%rsp), %r15
addq %rbx, %r15
movq 0x30(%rsp), %rcx
addq %r15, %rcx
incq %rcx
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rbx
movsbq %r12b, %rdx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x1c2a7
movb 0x1(%r14), %r12b
incq %r14
incq %rcx
testb %r12b, %r12b
jne 0x1c17a
jmp 0x1c2c4
movl (%rbx), %ecx
cmpq $0x29, %rcx
jae 0x1c263
movq 0x10(%rbx), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%rbx)
movq (%rdx,%rcx), %rsi
cmpl $0x20, %ecx
ja 0x1c272
addq 0x10(%rbx), %rax
addl $0x10, %ecx
movl %ecx, (%rbx)
jmp 0x1c27e
movq -0x11(%rbp), %rax
jmp 0x1c1f4
movzwl -0x5(%rbp), %eax
jmp 0x1c1f4
movl -0x9(%rbp), %eax
jmp 0x1c1f4
movzbl -0x3(%rbp), %eax
jmp 0x1c1f4
xorl %eax, %eax
movq 0x10(%rsp), %rbx
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
incl (%rsp)
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %eax, %edx
shrl $0x1f, %edx
addl %edx, %r13d
addl %eax, %r13d
addl $0x5, %r13d
movl %ecx, %eax
imulq %rsi, %rax
shrq $0x23, %rax
incl %r13d
cmpl $0x9, %ecx
movl %eax, %ecx
ja 0x1c20d
callq 0x1d966
xorl %ecx, %ecx
testq %rax, %rax
je 0x1c4e1
movq %rax, %rbp
movq %r14, %r12
jmp 0x1c445
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq (%rax), %r14
movq %r14, %rdi
callq 0x101c0
testq %rax, %rax
je 0x1c293
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
jmp 0x1c289
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq (%rax), %rsi
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq (%rax), %rdx
testq %rdx, %rdx
je 0x1c293
movq %rbp, %rdi
callq 0x1e1ae
jmp 0x1c435
movq %rbp, %rax
jmp 0x1c435
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rbx
jmp 0x1c2c4
cmpb $0x2e, %r12b
jne 0x1c2c4
movq %rcx, %r14
movsbq (%rcx), %rdx
testq %rdx, %rdx
je 0x1c2c4
leaq 0x1(%r14), %rcx
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x1c2ad
movq 0x10(%rbx), %rax
movq %rax, 0x60(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0x50(%rsp)
movsbl (%r14), %r15d
movl $0x7, %edx
leaq 0x2a6b3(%rip), %rdi     # 0x46998
movl %r15d, %esi
callq 0x102e0
testq %rax, %rax
je 0x1c30c
movl (%rbx), %eax
cmpl $0x28, %eax
movq 0x18(%rsp), %r12
ja 0x1c3e9
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x1c3ee
movl $0x9, %edx
leaq 0x2a6db(%rip), %rdi     # 0x469f3
movl %r15d, %esi
callq 0x102e0
testq %rax, %rax
movq 0x18(%rsp), %r12
je 0x1c343
movl 0x4(%rbx), %eax
cmpl $0xa0, %eax
ja 0x1c3e9
addl $0x10, %eax
movl %eax, 0x4(%rbx)
jmp 0x1c3ee
cmpb $0x6c, %r15b
je 0x1c36d
movzbl %r15b, %eax
cmpl $0x68, %eax
movl (%rsp), %r15d
jne 0x1c456
movzbl 0x1(%r14), %eax
cmpl $0x68, %eax
je 0x1c3b7
testl %eax, %eax
jne 0x1c383
jmp 0x1c456
movzbl 0x1(%r14), %eax
cmpl $0x6c, %eax
je 0x1c3a5
testl %eax, %eax
movl (%rsp), %r15d
je 0x1c456
movsbl %al, %esi
movl $0x7, %edx
leaq 0x2a606(%rip), %rdi     # 0x46998
callq 0x102e0
testq %rax, %rax
je 0x1c456
incq %r14
jmp 0x1c3de
movsbl 0x2(%r14), %esi
testl %esi, %esi
movl (%rsp), %r15d
jne 0x1c3c4
jmp 0x1c456
movsbl 0x2(%r14), %esi
testl %esi, %esi
je 0x1c456
movl $0x7, %edx
leaq 0x2a5c8(%rip), %rdi     # 0x46998
callq 0x102e0
testq %rax, %rax
je 0x1c456
addq $0x2, %r14
movl (%rbx), %eax
cmpl $0x28, %eax
jbe 0x1c302
addq $0x8, 0x8(%rbx)
movq %r14, %r15
movq 0x38(%rsp), %rsi
subq %rsi, %r15
incq %r15
cmpq $0xd, %r15
ja 0x1c42f
leaq 0x40(%rsp), %rdi
movq %r15, %rdx
callq 0x10400
movb $0x0, 0x40(%rsp,%r15)
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1e51b
decq %r14
movq %r14, %r15
jmp 0x1c435
movq %rbp, %rax
movq %rsi, %r15
testq %rax, %rax
je 0x1c44d
incq %r15
movl $0x1, %ecx
movq %rax, %rbp
incq %r15
jmp 0x1bfe7
movq %rbp, 0x8(%rsp)
movl (%rsp), %r15d
testl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
je 0x1c472
movslq %r15d, %rbx
movq -0x8(%r12,%rbx,8), %rdi
callq 0x1da09
decq %rbx
jne 0x1c463
movq %r12, %rdi
callq 0x10060
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1c489
callq 0x1da09
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ecx, %ecx
je 0x1c4f2
movl (%rsp), %r15d
movslq %r15d, %rbx
leaq 0x8(,%rbx,8), %rsi
movq %r12, %rdi
callq 0x104b0
testq %rax, %rax
je 0x1c500
movq %rbp, (%rax,%rbx,8)
movzbl -0x1(%rbp), %ecx
movl %ecx, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x1c521
leaq 0x2a425(%rip), %rsi     # 0x468f8
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %ecx
jmp 0x1c523
movq $0x0, 0x8(%rsp)
movq %r14, %r12
jmp 0x1c452
movq %rbp, %rdi
callq 0x1da09
movl (%rsp), %r15d
jmp 0x1c557
movq %rbp, 0x8(%rsp)
jmp 0x1c456
movq -0x11(%rbp), %rcx
jmp 0x1c523
movzwl -0x5(%rbp), %ecx
jmp 0x1c523
movl -0x9(%rbp), %ecx
jmp 0x1c523
movzbl -0x3(%rbp), %ecx
jmp 0x1c523
xorl %ecx, %ecx
incl %r15d
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 0x1c540
movq %rax, %r12
movl %r15d, %eax
negl %eax
cmovsl %r15d, %eax
movl %r15d, %ebx
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 0x1c56c
movl %r13d, %r14d
subl %r15d, %r14d
leal 0x4(%r14), %eax
movslq %eax, %rdi
callq 0x10450
testq %rax, %rax
je 0x1c729
movq %r14, 0x8(%rsp)
leaq 0x2a455(%rip), %rsi     # 0x469fc
movq %rax, (%rsp)
movq %rax, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10620
movl %eax, %ebp
testl %ebx, %ebx
jle 0x1c6f2
movl %ebx, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movq %r12, 0x18(%rsp)
movq (%rsp), %rbx
movq (%r12,%r14,8), %rax
movzbl -0x1(%rax), %edx
movl %edx, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1c612
leaq 0x2a31f(%rip), %rsi     # 0x4690c
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
shrl $0x3, %edx
jmp 0x1c614
movq -0x11(%rax), %rdx
jmp 0x1c614
movzwl -0x5(%rax), %edx
jmp 0x1c614
movl -0x9(%rax), %edx
jmp 0x1c614
movzbl -0x3(%rax), %edx
jmp 0x1c614
xorl %edx, %edx
movslq %ebp, %rdi
addq %rbx, %rdi
leaq 0x2a3e1(%rip), %rsi     # 0x46a02
xorl %eax, %eax
callq 0x10620
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 0x1c66e
leaq 0x2a2d7(%rip), %rcx     # 0x46920
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x1c670
movq -0x11(%rsi), %rdx
jmp 0x1c670
movzwl -0x5(%rsi), %edx
jmp 0x1c670
movl -0x9(%rsi), %edx
jmp 0x1c670
movzbl -0x3(%rsi), %edx
jmp 0x1c670
xorl %edx, %edx
addl %ebp, %r12d
movslq %r12d, %rdi
addq %rbx, %rdi
callq 0x10400
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rdi
movzbl -0x1(%rdi), %ebp
movl %ebp, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x1c6c1
leaq 0x2a298(%rip), %rcx     # 0x46934
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %ebp
jmp 0x1c6c3
movq -0x11(%rdi), %rbp
jmp 0x1c6c3
movzwl -0x5(%rdi), %ebp
jmp 0x1c6c3
movl -0x9(%rdi), %ebp
jmp 0x1c6c3
movzbl -0x3(%rdi), %ebp
jmp 0x1c6c3
xorl %ebp, %ebp
leal (%r12,%rbp), %ebx
callq 0x1da09
movslq %ebx, %rax
movq (%rsp), %rbx
movw $0xa0d, (%rbx,%rax)     # imm = 0xA0D
addl %r12d, %ebp
addl $0x2, %ebp
incq %r14
cmpq %r14, 0x10(%rsp)
movq 0x18(%rsp), %r12
jne 0x1c5d4
subl %ebp, %r13d
addl $0x3, %r13d
cmpl %r15d, %r13d
jne 0x1c73a
movq 0x8(%rsp), %rbx
addl $0x3, %ebx
movslq %ebx, %rax
movq (%rsp), %r14
movb $0x0, (%r14,%rax)
movq %r12, %rdi
callq 0x10060
movq 0x20(%rsp), %rax
movq %r14, (%rax)
movl %ebx, %ebp
jmp 0x1c489
movq $0x0, 0x8(%rsp)
movl %ebx, %r15d
jmp 0x1c456
leaq 0x2a2c8(%rip), %rdi     # 0x46a09
leaq 0x2a266(%rip), %rsi     # 0x469ae
leaq 0x2a2c8(%rip), %rcx     # 0x46a17
movl $0x37a, %edx            # imm = 0x37A
callq 0x10250