// File: /workspace/github_c_makefile_star2_O2/andyfighting[P]hiredis_timer_cmpt/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 error_type = 0; /* 0 = no error; -1 = memory error; -2 = format error */
    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 memory_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 memory_err;
                    touched = 0;
                }
            } else {
                newarg = sdscatlen(curarg,c,1);
                if (newarg == NULL) goto memory_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";
                    static const char flags[] = "#0-+ ";
                    char _format[16];
                    const char *_p = c+1;
                    size_t _l = 0;
                    va_list _cpy;

                    /* Flags */
                    while (*_p != '\0' && strchr(flags,*_p) != NULL) _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 format_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 memory_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 memory_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+countDigits(argc)+2;

    /* Build the command at protocol level */
    cmd = malloc(totlen+1);
    if (cmd == NULL) goto memory_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;

format_err:
    error_type = -2;
    goto cleanup;

memory_err:
    error_type = -1;
    goto cleanup;

cleanup:
    if (curargv) {
        while(argc--)
            sdsfree(curargv[argc]);
        free(curargv);
    }

    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 error_type;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
pushq $-0x1
popq %rax
testq %rdi, %rdi
je 0x44ec
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
movl %eax, %ebx
callq 0x34a0
movq %rax, %r13
movl %ebx, %eax
testq %r13, %r13
je 0x44ec
movq %r12, 0x10(%rsp)
movq %r15, 0x28(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x4(%rsp)
pushq $0x1
popq %r15
leaq 0x5470(%rip), %rbp      # 0x9414
xorl %eax, %eax
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movzbl (%r14), %ecx
cmpl $0x20, %ecx
je 0x4039
cmpl $0x25, %ecx
je 0x3ff0
testl %ecx, %ecx
je 0x4364
movq %r13, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x3430
movl %r15d, %ebx
testq %rax, %rax
jne 0x4357
jmp 0x44b7
movzbl 0x1(%r14), %ebx
testl %ebx, %ebx
je 0x3fd1
cmpl $0x25, %ebx
je 0x40b8
cmpl $0x62, %ebx
je 0x40cc
cmpl $0x73, %ebx
jne 0x4105
movq 0x10(%rsp), %rdx
movl (%rdx), %ecx
movq %r12, %rbx
cmpq $0x28, %rcx
ja 0x41c9
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x8, %ecx
movl %ecx, (%rdx)
jmp 0x41d5
xorl %ebx, %ebx
testl %eax, %eax
je 0x40b0
movq %r14, 0x18(%rsp)
movq %rbp, %r14
movq 0x8(%rsp), %rbp
movslq %ebp, %r15
leaq 0x8(,%r15,8), %rsi
movq %r12, %rdi
callq 0x33b0
testq %rax, %rax
je 0x43ab
movq %rax, %r12
leal 0x1(%r15), %eax
movq %rax, 0x8(%rsp)
movq %r13, (%r12,%r15,8)
movslq -0x8(%r13), %rdi
callq 0x451a
movq %rax, %r13
callq 0x34a0
testq %rax, %rax
je 0x43b3
movq %r14, %rbp
movq 0x20(%rsp), %rcx
addl %r13d, %ecx
movq %rcx, 0x20(%rsp)
pushq $0x1
popq %r15
movq 0x18(%rsp), %r14
jmp 0x4357
movq %r13, %rax
jmp 0x4357
movq %r13, %rdi
leaq 0x500a(%rip), %rsi      # 0x90cc
callq 0x3390
jmp 0x4348
movq 0x10(%rsp), %rdi
movl (%rdi), %ecx
cmpq $0x29, %rcx
jae 0x41f5
movq 0x10(%rdi), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%rdi)
movq (%rdx,%rcx), %rsi
cmpl $0x20, %ecx
ja 0x4204
addq 0x10(%rdi), %rax
addl $0x10, %ecx
movl %ecx, (%rdi)
jmp 0x4210
movq %r12, 0x18(%rsp)
leaq 0x1(%r14), %r15
leaq 0x2(%r14), %r12
testb %bl, %bl
je 0x413f
movsbl %bl, %esi
movq %rbp, %rdi
pushq $0x6
popq %rdx
callq 0x3250
testq %rax, %rax
je 0x413f
movb 0x1(%r15), %bl
incq %r15
incq %r12
jmp 0x4112
movb 0x1(%r15), %bl
incq %r15
incq %r12
testb %bl, %bl
je 0x4173
callq 0x3540
movq (%rax), %rax
movsbq %bl, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x4135
cmpb $0x2e, %bl
jne 0x4173
movq %r12, %r15
movsbq (%r12), %rcx
testq %rcx, %rcx
je 0x4173
leaq 0x1(%r15), %r12
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x415b
movq 0x10(%rsp), %r12
movq 0x10(%r12), %rax
movq %rax, 0x40(%rsp)
movups (%r12), %xmm0
movaps %xmm0, 0x30(%rsp)
movsbl (%r15), %ebx
leaq 0x5276(%rip), %rdi      # 0x940d
movl %ebx, %esi
pushq $0x7
popq %rdx
callq 0x3250
testq %rax, %rax
je 0x4238
movl (%r12), %eax
cmpl $0x28, %eax
movq %r12, %rcx
movq 0x18(%rsp), %r12
ja 0x42f7
addl $0x8, %eax
movl %eax, (%rcx)
jmp 0x42fc
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movq (%rax), %r12
movq %r12, %rdi
callq 0x3140
testq %rax, %rax
je 0x4225
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x3430
jmp 0x4228
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 0x4230
movq %r13, %rdi
callq 0x3430
jmp 0x4348
movq %r13, %rax
movq %rbx, %r12
jmp 0x4348
movq %r13, %rax
jmp 0x4348
leaq 0x4e8f(%rip), %rdi      # 0x90ce
movl %ebx, %esi
pushq $0x9
popq %rdx
callq 0x3250
testq %rax, %rax
movq 0x18(%rsp), %r12
je 0x4271
movq 0x10(%rsp), %rcx
movl 0x4(%rcx), %eax
cmpl $0xa0, %eax
ja 0x42f7
addl $0x10, %eax
movl %eax, 0x4(%rcx)
jmp 0x42fc
cmpb $0x6c, %bl
je 0x42b7
movzbl %bl, %eax
cmpl $0x68, %eax
jne 0x44b0
movzbl 0x1(%r15), %eax
cmpl $0x68, %eax
jne 0x42c1
movsbl 0x2(%r15), %esi
testl %esi, %esi
je 0x44b0
leaq 0x516d(%rip), %rdi      # 0x940d
pushq $0x7
popq %rdx
callq 0x3250
testq %rax, %rax
je 0x44b0
addq $0x2, %r15
jmp 0x42e7
movzbl 0x1(%r15), %eax
cmpl $0x6c, %eax
je 0x428c
testl %eax, %eax
je 0x44b0
movsbl %al, %esi
leaq 0x513a(%rip), %rdi      # 0x940d
pushq $0x7
popq %rdx
callq 0x3250
testq %rax, %rax
je 0x44b0
incq %r15
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
cmpl $0x28, %eax
jbe 0x41bf
addq $0x8, 0x8(%rcx)
movq %r15, %rbx
subq %r14, %rbx
incq %rbx
cmpq $0xd, %rbx
ja 0x4341
movq %r14, %rsi
movq %rbp, %r14
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x3300
movb $0x0, 0x50(%rsp,%rbx)
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rbp
leaq 0x30(%rsp), %rdx
callq 0x33d0
decq %r15
movq %r15, %r14
jmp 0x4344
movq %r13, %rax
pushq $0x1
popq %r15
testq %rax, %rax
je 0x44b7
incq %r14
movl %r15d, %ebx
incq %r14
movq %rax, %r13
movl %ebx, %eax
jmp 0x3fbb
movq 0x8(%rsp), %r14
movslq %r14d, %rbx
testl %eax, %eax
je 0x43c0
leaq 0x8(,%rbx,8), %rsi
movq %r12, %rdi
callq 0x33b0
testq %rax, %rax
movq 0x20(%rsp), %rbp
je 0x44bc
movq %rax, %r15
incl %r14d
movq %r13, (%rax,%rbx,8)
incq %rbx
movslq -0x8(%r13), %rdi
callq 0x451a
addl %eax, %ebp
movq %r15, %r12
jmp 0x43cd
movq %rbp, %r14
jmp 0x44bc
xorl %r13d, %r13d
movq 0x8(%rsp), %r14
jmp 0x44c1
movq %r13, %rdi
callq 0x3290
movq 0x20(%rsp), %rbp
movq %rbx, %rdi
callq 0x452f
movl %eax, %r15d
leal (%r15,%rbp), %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x3350
xorl %r13d, %r13d
testq %rax, %rax
je 0x44bc
movq %rax, %rbx
leal (%r15,%rbp), %eax
addl $0x3, %eax
movl %eax, 0x4(%rsp)
leaq 0x4ccf(%rip), %rsi      # 0x90d7
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x3470
movl %eax, %ebp
testl %r14d, %r14d
cmovlel %r13d, %r14d
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
cmpq %r14, 0x8(%rsp)
je 0x448b
movslq %ebp, %rdi
addq %rbx, %rdi
movq (%r12,%r14,8), %rax
movslq -0x8(%rax), %rdx
leaq 0x4c9b(%rip), %rsi      # 0x90dd
xorl %eax, %eax
callq 0x3470
addl %ebp, %eax
movq %r12, %r15
movslq %eax, %r12
leaq (%rbx,%r12), %rdi
movq (%r15,%r14,8), %rsi
movslq -0x8(%rsi), %rdx
callq 0x3300
movq (%r15,%r14,8), %rdi
movl -0x8(%rdi), %r13d
leal (%r12,%r13), %ebp
callq 0x3290
movslq %ebp, %rax
movw $0xa0d, (%rbx,%rax)     # imm = 0xA0D
leal (%r12,%r13), %ebp
addl $0x2, %ebp
movq %r15, %r12
incq %r14
jmp 0x4426
cmpl 0x4(%rsp), %ebp
jne 0x44fb
movslq 0x4(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq %r12, %rdi
callq 0x3050
movl 0x4(%rsp), %eax
movq 0x28(%rsp), %rcx
movq %rbx, (%rcx)
jmp 0x44ec
pushq $-0x2
popq %rax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %r14
testq %r12, %r12
je 0x44e0
movslq %r14d, %rbx
decq %rbx
cmpq $-0x1, %rbx
je 0x44d8
movq (%r12,%rbx,8), %rdi
callq 0x3290
jmp 0x44c4
movq %r12, %rdi
callq 0x3050
movq %r13, %rdi
callq 0x3290
movl 0x4(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4be2(%rip), %rdi      # 0x90e4
leaq 0x4be9(%rip), %rsi      # 0x90f2
leaq 0x4bec(%rip), %rcx      # 0x90fc
movl $0x19c, %edx            # imm = 0x19C
callq 0x31c0