// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %r14
testq %rdi, %rdi
je 0x17f35
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, 0x28(%rsp)
callq 0x18ec4
testq %rax, %rax
je 0x17f31
movq %rax, %r14
movq %rbx, 0x18(%rsp)
xorl %eax, %eax
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %r15, %r8
movzbl (%r8), %ecx
movslq %r12d, %r15
cmpl $0x20, %ecx
je 0x179f3
cmpl $0x25, %ecx
je 0x1799f
testl %ecx, %ecx
je 0x17d72
movq %r14, %rdi
movq %r8, %rsi
pushq $0x1
popq %rdx
movq %r8, %r15
callq 0x194d0
movq %r15, %r8
pushq $0x1
popq %rbp
testq %rax, %rax
jne 0x17d65
jmp 0x17f04
movzbl 0x1(%r8), %ecx
testl %ecx, %ecx
je 0x1797a
cmpl $0x25, %ecx
je 0x17a6e
cmpl $0x62, %ecx
movq 0x18(%rsp), %rdi
je 0x17a85
cmpl $0x73, %ecx
jne 0x17ab9
movq %r14, %r15
movq 0x18(%rsp), %rdx
movl (%rdx), %ecx
movq %r8, %rbp
movq %r12, %r14
cmpq $0x28, %rcx
ja 0x17b49
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x8, %ecx
movl %ecx, (%rdx)
jmp 0x17b55
xorl %ebp, %ebp
testl %eax, %eax
je 0x17a66
movq %r8, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq %r12, %rbx
leaq 0x8(,%r15,8), %rsi
movq %r13, %rdi
callq 0x104b0
testq %rax, %rax
je 0x17db7
movq %rax, %r12
leal 0x1(%r15), %r13d
movq %r14, (%rax,%r15,8)
movq %r14, %rdi
callq 0x17316
movq %rax, %rdi
callq 0x17f72
movq %rax, %r14
callq 0x18ec4
testq %rax, %rax
je 0x17dbf
movq 0x8(%rsp), %rbx
addl %r14d, %ebx
movq %r13, %rcx
movq %r12, %r13
movq %rcx, %r12
movq 0x10(%rsp), %r8
jmp 0x17d65
movq %r14, %rax
jmp 0x17d65
movq %r14, %rdi
leaq 0x29db1(%rip), %rsi     # 0x41829
movq %r8, %r15
callq 0x1952f
jmp 0x17bae
movl (%rdi), %ecx
cmpq $0x29, %rcx
jae 0x17b7c
movq 0x10(%rdi), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%rdi)
movq (%rdx,%rcx), %rsi
cmpl $0x20, %ecx
ja 0x17b8b
addq 0x10(%rdi), %rax
addl $0x10, %ecx
movl %ecx, (%rdi)
jmp 0x17b97
movq %r14, 0x8(%rsp)
movq %r12, 0x10(%rsp)
leaq 0x1(%r8), %rax
leaq 0x2(%r8), %rdx
xorl %esi, %esi
cmpb $0x23, %cl
sete %sil
cmoveq %rdx, %rax
xorl %ecx, %ecx
movq %r8, %r14
cmpb $0x30, 0x1(%rsi,%r8)
sete %cl
leaq (%rax,%rcx), %rdx
xorl %esi, %esi
cmpb $0x2d, (%rax,%rcx)
sete %sil
xorl %edi, %edi
cmpb $0x20, (%rsi,%rdx)
leaq (%rdx,%rsi), %rdx
sete %dil
leaq (%rdx,%rdi), %r12
xorl %r8d, %r8d
cmpb $0x2b, (%rdi,%rdx)
sete %r8b
addq %r8, %r12
addq %rsi, %rdi
addq %rcx, %rdi
addq %r8, %rdi
leaq (%rax,%rdi), %r15
incq %r15
movsbq (%r12), %rbp
testq %rbp, %rbp
je 0x17bd4
callq 0x10710
movq (%rax), %rax
testb $0x8, 0x1(%rax,%rbp,2)
je 0x17bb6
incq %r12
incq %r15
jmp 0x17b24
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movq (%rax), %r12
movq %r12, %rdi
callq 0x101c0
testq %rax, %rax
je 0x17c16
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x194d0
jmp 0x17c19
movq 0x8(%rdi), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdi)
movq (%rax), %rsi
movq 0x8(%rdi), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdi)
movq (%rax), %rdx
testq %rdx, %rdx
je 0x17c27
movq %r14, %rdi
movq %r8, %r15
callq 0x194d0
movq %r15, %r8
jmp 0x17d56
cmpb $0x2e, %bpl
jne 0x17bd4
movq %r15, %r12
movsbq (%r15), %rcx
testq %rcx, %rcx
je 0x17bd4
leaq 0x1(%r12), %r15
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x17bbc
movq 0x18(%rsp), %r15
movq 0x10(%r15), %rax
movq %rax, 0x40(%rsp)
movups (%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movsbl (%r12), %ebp
leaq 0x29bd9(%rip), %rdi     # 0x417d0
movl %ebp, %esi
pushq $0x7
popq %rdx
callq 0x102e0
testq %rax, %rax
je 0x17c2f
movl (%r15), %eax
cmpl $0x28, %eax
ja 0x17c63
addl $0x8, %eax
movl %eax, (%r15)
jmp 0x17c68
movq %r15, %rax
movq %r14, %r12
movq %r15, %r14
movq %rbp, %r8
jmp 0x17d56
movq %r14, %rax
jmp 0x17d56
leaq 0x29bf5(%rip), %rdi     # 0x4182b
movl %ebp, %esi
pushq $0x9
popq %rdx
callq 0x102e0
testq %rax, %rax
je 0x17c70
movl 0x4(%r15), %eax
cmpl $0xa0, %eax
movq %r14, %r8
ja 0x17d01
addl $0x10, %eax
movl %eax, 0x4(%r15)
jmp 0x17d06
addq $0x8, 0x8(%r15)
movq %r14, %r8
jmp 0x17d06
cmpb $0x6c, %bpl
je 0x17cbd
movzbl %bpl, %eax
cmpl $0x68, %eax
jne 0x17f47
movzbl 0x1(%r12), %eax
cmpl $0x68, %eax
jne 0x17cc8
movsbl 0x2(%r12), %esi
testl %esi, %esi
je 0x17f47
leaq 0x29b2d(%rip), %rdi     # 0x417d0
pushq $0x7
popq %rdx
callq 0x102e0
testq %rax, %rax
je 0x17f47
movq %r14, %r8
addq $0x2, %r12
jmp 0x17cf1
movzbl 0x1(%r12), %eax
cmpl $0x6c, %eax
je 0x17c8e
testl %eax, %eax
je 0x17f47
movsbl %al, %esi
leaq 0x29af6(%rip), %rdi     # 0x417d0
pushq $0x7
popq %rdx
callq 0x102e0
testq %rax, %rax
je 0x17f47
movq %r14, %r8
incq %r12
movl (%r15), %eax
cmpl $0x28, %eax
ja 0x17d01
addl $0x8, %eax
movl %eax, (%r15)
jmp 0x17d06
addq $0x8, 0x8(%r15)
movq %r12, %rbp
subq %r8, %rbp
incq %rbp
cmpq $0xd, %rbp
ja 0x17d47
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r8, %rsi
movq %rbp, %rdx
callq 0x10400
movb $0x0, 0x50(%rsp,%rbp)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq 0x196cc
decq %r12
movq %r12, %r8
jmp 0x17d4c
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
testq %rax, %rax
je 0x17f04
incq %r8
pushq $0x1
popq %rbp
incq %r8
movq %rax, %r14
movl %ebp, %eax
jmp 0x1795d
testl %eax, %eax
je 0x17dd0
movq %rbx, %rbp
leaq 0x8(,%r15,8), %rsi
movq %r13, %rdi
callq 0x104b0
testq %rax, %rax
je 0x17f04
movq %rax, %rbx
leal 0x1(%r15), %r12d
movq %r14, (%rax,%r15,8)
movq %r14, %rdi
callq 0x17316
movq %rax, %rdi
callq 0x17f72
addl %eax, %ebp
movq %rbx, %r13
movq %rbp, %rbx
jmp 0x17dd8
movq %rbx, %r12
jmp 0x17f04
xorl %r14d, %r14d
movq %r13, %rax
movq %r12, %r13
movq %rax, %r12
jmp 0x17f04
movq %r14, %rdi
callq 0x18f40
movl %r12d, %edi
callq 0x17f86
movq %r12, %r14
movl %eax, %r12d
leal (%rbx,%r12), %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x10450
movq %rax, %rdi
movq %rbx, %rax
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x17efe
movq %r13, 0x18(%rsp)
addl %r12d, %eax
addl $0x3, %eax
movl %eax, 0x24(%rsp)
leaq 0x29a18(%rip), %rsi     # 0x41834
movq %rdi, 0x8(%rsp)
movl %r14d, %edx
xorl %eax, %eax
callq 0x10620
movl %eax, %ebp
testl %r14d, %r14d
cmovlel %ebx, %r14d
xorl %r12d, %r12d
movq %r14, 0x10(%rsp)
movq 0x18(%rsp), %rbx
cmpq %r12, %r14
je 0x17ed4
movslq %ebp, %r13
movq 0x8(%rsp), %rax
addq %rax, %r13
movq %rax, %r14
movq (%rbx,%r12,8), %rdi
callq 0x17316
movq %r13, %rdi
leaq 0x299cf(%rip), %rsi     # 0x4183a
movq %rax, %rdx
xorl %eax, %eax
callq 0x10620
addl %ebp, %eax
movslq %eax, %r15
leaq (%r14,%r15), %r13
movq (%rbx,%r12,8), %rbp
movq %rbp, %rdi
callq 0x17316
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x10400
movq (%rbx,%r12,8), %r13
movq %r13, %rdi
callq 0x17316
movq %rax, %rbp
leal (%r15,%rax), %r14d
movq %r13, %rdi
callq 0x18f40
movslq %r14d, %rax
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rcx
movw $0xa0d, (%rcx,%rax)     # imm = 0xA0D
addl %r15d, %ebp
addl $0x2, %ebp
incq %r12
jmp 0x17e41
movl 0x24(%rsp), %r14d
cmpl %r14d, %ebp
jne 0x17f53
movslq %r14d, %rax
movq 0x8(%rsp), %rbx
movb $0x0, (%rbx,%rax)
movq 0x18(%rsp), %rdi
callq 0x10060
movq 0x28(%rsp), %rax
movq %rbx, (%rax)
jmp 0x17f35
movq %r14, %r12
xorl %r14d, %r14d
movslq %r12d, %rbx
decq %rbx
cmpq $-0x1, %rbx
je 0x17f1c
movq (%r13,%rbx,8), %rdi
callq 0x18f40
jmp 0x17f07
movq %r13, %rdi
callq 0x10060
testq %r14, %r14
je 0x17f31
movq %r14, %rdi
callq 0x18f40
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
jmp 0x17f04
leaq 0x298e7(%rip), %rdi     # 0x41841
leaq 0x29885(%rip), %rsi     # 0x417e6
leaq 0x298e7(%rip), %rcx     # 0x4184f
movl $0x37a, %edx            # imm = 0x37A
callq 0x10250