// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x4667
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x3490
testq %rax, %rax
je 0x4667
movq %rax, %r15
movq %rbx, 0x28(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movzbl (%rbp), %ecx
cmpl $0x20, %ecx
je 0x411e
cmpl $0x25, %ecx
je 0x40ee
testl %ecx, %ecx
je 0x4480
movl $0x1, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3420
testq %rax, %rax
jne 0x445e
jmp 0x4470
movb 0x1(%rbp), %bl
movzbl %bl, %eax
cmpl $0x61, %eax
jg 0x4189
testl %eax, %eax
je 0x40d0
cmpl $0x25, %eax
jne 0x41c0
movq %r15, %rdi
leaq 0x4fb8(%rip), %rsi      # 0x90cc
callq 0x3380
jmp 0x4456
xorl %ebx, %ebx
testl %eax, %eax
je 0x41b8
movl 0x8(%rsp), %r12d
movslq %r12d, %r13
leaq 0x8(,%r13,8), %rsi
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x44c1
movq %rax, %r14
leal 0x1(%r13), %eax
movl %eax, 0x8(%rsp)
movq %r15, (%r14,%r13,8)
movslq -0x8(%r15), %rdi
callq 0x46a3
movq %rax, %r15
callq 0x3490
testq %rax, %rax
movq 0x20(%rsp), %r12
je 0x44cc
movq 0x18(%rsp), %rcx
addl %r15d, %ecx
movq %rcx, 0x18(%rsp)
jmp 0x4463
cmpl $0x62, %eax
je 0x41fc
cmpl $0x73, %eax
jne 0x41c0
movl (%r12), %ecx
movq %r14, %rbx
cmpq $0x28, %rcx
ja 0x4263
movq %rcx, %rax
addq 0x10(%r12), %rax
addl $0x8, %ecx
movl %ecx, (%r12)
jmp 0x4271
movq %r15, %rax
jmp 0x4463
movq %r14, 0x10(%rsp)
leaq 0x1(%rbp), %r13
leaq 0x2(%rbp), %r14
leaq 0x5240(%rip), %r12      # 0x9414
movsbl %bl, %esi
movl $0x6, %edx
movq %r12, %rdi
callq 0x3240
testq %rax, %rax
je 0x4231
movb 0x1(%r13), %bl
incq %r13
incq %r14
testb %bl, %bl
jne 0x41d4
jmp 0x42f0
movl (%r12), %ecx
cmpq $0x29, %rcx
jae 0x4291
movq 0x10(%r12), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%r12)
movq (%rdx,%rcx), %rsi
cmpl $0x20, %ecx
ja 0x42a2
addq 0x10(%r12), %rax
addl $0x10, %ecx
movl %ecx, (%r12)
jmp 0x42b0
testb %bl, %bl
je 0x42f0
callq 0x3520
movq (%rax), %rax
movsbq %bl, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x42d4
movb 0x1(%r13), %bl
incq %r13
incq %r14
testb %bl, %bl
jne 0x4241
jmp 0x42f0
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq (%rax), %r14
movq %r14, %rdi
callq 0x3130
testq %rax, %rax
je 0x42c9
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3420
jmp 0x42cc
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq (%rax), %rsi
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq (%rax), %rdx
testq %rdx, %rdx
je 0x4453
movq %r15, %rdi
callq 0x3420
jmp 0x4456
movq %r15, %rax
movq %rbx, %r14
jmp 0x4456
cmpb $0x2e, %bl
jne 0x42f0
movq %r14, %r13
movsbq (%r14), %rcx
testq %rcx, %rcx
je 0x42f0
leaq 0x1(%r13), %r14
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x42d9
movq 0x20(%rsp), %r12
movq 0x10(%r12), %rax
movq %rax, 0x50(%rsp)
movups (%r12), %xmm0
movaps %xmm0, 0x40(%rsp)
movsbl (%r13), %ebx
movl $0x7, %edx
leaq 0x50f3(%rip), %rdi      # 0x940d
movl %ebx, %esi
callq 0x3240
testq %rax, %rax
je 0x4344
movl (%r12), %eax
cmpl $0x28, %eax
movq 0x10(%rsp), %r14
ja 0x440f
addl $0x8, %eax
movl %eax, (%r12)
jmp 0x4415
movl $0x9, %edx
leaq 0x4d7e(%rip), %rdi      # 0x90ce
movl %ebx, %esi
callq 0x3240
testq %rax, %rax
movq 0x10(%rsp), %r14
je 0x4383
movq 0x20(%rsp), %r12
movl 0x4(%r12), %eax
cmpl $0xa0, %eax
ja 0x440f
addl $0x10, %eax
movl %eax, 0x4(%r12)
jmp 0x4415
cmpb $0x6c, %bl
movq 0x20(%rsp), %r12
je 0x43d0
movzbl %bl, %eax
cmpl $0x68, %eax
jne 0x4679
movzbl 0x1(%r13), %eax
cmpl $0x68, %eax
jne 0x43da
movsbl 0x2(%r13), %esi
testl %esi, %esi
je 0x4679
movl $0x7, %edx
leaq 0x5051(%rip), %rdi      # 0x940d
callq 0x3240
testq %rax, %rax
je 0x4679
addq $0x2, %r13
jmp 0x4402
movzbl 0x1(%r13), %eax
cmpl $0x6c, %eax
je 0x43a3
testl %eax, %eax
je 0x4679
movsbl %al, %esi
movl $0x7, %edx
leaq 0x501c(%rip), %rdi      # 0x940d
callq 0x3240
testq %rax, %rax
je 0x4679
incq %r13
movl (%r12), %eax
cmpl $0x28, %eax
jbe 0x4338
addq $0x8, 0x8(%r12)
movq %r13, %rbx
subq %rbp, %rbx
incq %rbx
cmpq $0xd, %rbx
ja 0x4453
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x32f0
movb $0x0, 0x30(%rsp,%rbx)
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x33c0
decq %r13
movq %r13, %rbp
jmp 0x4456
movq %r15, %rax
testq %rax, %rax
je 0x4470
incq %rbp
movl $0x1, %ebx
incq %rbp
movq %rax, %r15
movl %ebx, %eax
jmp 0x40ba
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x8(%rsp), %r12d
jmp 0x463b
testl %eax, %eax
je 0x44df
movl 0x8(%rsp), %r12d
movslq %r12d, %rbx
leaq 0x8(,%rbx,8), %rsi
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
movq 0x18(%rsp), %r13
je 0x44c1
movq %rax, %r14
incl %r12d
movq %r15, (%rax,%rbx,8)
incq %rbx
movslq -0x8(%r15), %rdi
callq 0x46a3
addl %eax, %r13d
jmp 0x44f4
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x463b
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl 0x8(%rsp), %r12d
jmp 0x4640
movq %r15, %rdi
callq 0x3280
movl 0x8(%rsp), %r12d
movslq %r12d, %rbx
movq 0x18(%rsp), %r13
movl $0x1, %r15d
cmpl $0xa, %r12d
jb 0x4551
movl $0x4, %r15d
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
cmpq $0x63, %rbx
jbe 0x4548
cmpq $0x3e7, %rbx            # imm = 0x3E7
jbe 0x454e
cmpq $0x2710, %rbx           # imm = 0x2710
jb 0x4551
movq %rbx, %rax
mulq %rcx
shrq $0xb, %rdx
addl $0x4, %r15d
cmpq $0x1869f, %rbx          # imm = 0x1869F
movq %rdx, %rbx
ja 0x4510
addl $-0x3, %r15d
jmp 0x4551
addl $-0x2, %r15d
jmp 0x4551
decl %r15d
movq %r14, 0x10(%rsp)
leal (%r15,%r13), %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x3340
testq %rax, %rax
je 0x462d
movq %rax, %r14
leal (%r15,%r13), %eax
addl $0x3, %eax
movl %eax, 0x18(%rsp)
leaq 0x4b54(%rip), %rsi      # 0x90d7
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3460
testl %r12d, %r12d
jle 0x4607
movl %r12d, %ecx
movq %rcx, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x10(%rsp), %rbp
movslq %eax, %r15
leaq (%r14,%r15), %rdi
movq (%rbp,%r13,8), %rax
movslq -0x8(%rax), %rdx
leaq 0x4b21(%rip), %rsi      # 0x90dd
xorl %eax, %eax
callq 0x3460
addl %eax, %r15d
movslq %r15d, %r15
leaq (%r14,%r15), %rdi
movq (%rbp,%r13,8), %rsi
movslq -0x8(%rsi), %rdx
callq 0x32f0
movq (%rbp,%r13,8), %rdi
movl -0x8(%rdi), %ebx
leal (%rbx,%r15), %r12d
callq 0x3280
movslq %r12d, %rax
movw $0xa0d, (%r14,%rax)     # imm = 0xA0D
leal (%rbx,%r15), %eax
addl $0x2, %eax
incq %r13
cmpq %r13, 0x8(%rsp)
jne 0x45a5
movl 0x18(%rsp), %r13d
cmpl %r13d, %eax
jne 0x4684
movslq %r13d, %rax
movb $0x0, (%r14,%rax)
movq 0x10(%rsp), %rdi
callq 0x3050
movq 0x28(%rsp), %rax
movq %r14, (%rax)
jmp 0x4667
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x465f
testl %r12d, %r12d
je 0x4657
movslq %r12d, %r12
movq -0x8(%r14,%r12,8), %rdi
callq 0x3280
decq %r12
jne 0x4648
movq %r14, %rdi
callq 0x3050
movq %r15, %rdi
callq 0x3280
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
jmp 0x4476
leaq 0x4a59(%rip), %rdi      # 0x90e4
leaq 0x4a60(%rip), %rsi      # 0x90f2
leaq 0x4a63(%rip), %rcx      # 0x90fc
movl $0x19c, %edx            # imm = 0x19C
callq 0x31b0