// File: /workspace/github_c_makefile_star2_O1/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
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x4606
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
callq 0x3490
testq %rax, %rax
je 0x4606
movq %rax, %rbx
xorl %r15d, %r15d
xorl %ebp, %ebp
movl $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq %r14, %r8
movq %r13, 0x28(%rsp)
movzbl (%r8), %eax
cmpl $0x20, %eax
je 0x422e
cmpl $0x25, %eax
je 0x4155
testl %eax, %eax
je 0x457b
movl $0x1, %edx
movq %rbx, %rdi
movq %r8, %r15
movq %r8, %rsi
callq 0x3420
testq %rax, %rax
je 0x45d0
movl $0x1, %r12d
movq %rax, %rbx
movq %rbp, %r14
movq %r15, %r8
jmp 0x4545
movzbl 0x1(%r8), %ecx
cmpl $0x61, %ecx
jg 0x4183
testl %ecx, %ecx
je 0x4226
cmpl $0x25, %ecx
jne 0x41b8
movq %rbx, %rdi
leaq 0x4f56(%rip), %rsi      # 0x90cc
movq %r8, %r14
callq 0x3380
jmp 0x4339
cmpl $0x62, %ecx
je 0x42a8
cmpl $0x73, %ecx
jne 0x41b8
movl (%r13), %ecx
movq %r8, %r12
movq %rbx, %r14
cmpq $0x28, %rcx
ja 0x42c2
movq %rcx, %rax
addq 0x10(%r13), %rax
addl $0x8, %ecx
movl %ecx, (%r13)
jmp 0x42ce
movq %r8, %r12
leaq 0x1(%r8), %r14
movb (%r14), %al
testb %al, %al
je 0x41e8
movsbl %al, %esi
movl $0x6, %edx
leaq 0x523f(%rip), %rdi      # 0x9414
callq 0x3240
testq %rax, %rax
je 0x41e8
movb 0x1(%r14), %al
incq %r14
jmp 0x41c2
movq %rbx, 0x8(%rsp)
movb (%r14), %bl
testb %bl, %bl
je 0x437b
callq 0x3520
movq (%rax), %rcx
leaq 0x1(%r14), %rax
movsbq %bl, %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x4357
movb 0x1(%r14), %bl
incq %r14
incq %rax
testb %bl, %bl
jne 0x4204
jmp 0x437b
cmpb $0x20, %al
jne 0x4125
xorl %r12d, %r12d
testl %r15d, %r15d
je 0x4542
movq %r8, 0x8(%rsp)
movl 0x10(%rsp), %eax
movq %rbp, %r15
movslq %eax, %rbp
leaq 0x8(,%rbp,8), %rsi
movq %r15, %rdi
callq 0x33a0
testq %rax, %rax
je 0x45c6
movq %rax, %r14
leal 0x1(%rbp), %eax
movl %eax, 0x10(%rsp)
movq %rbx, (%r14,%rbp,8)
movslq -0x8(%rbx), %rdi
callq 0x47a4
movq %rax, %rbp
callq 0x3490
testq %rax, %rax
je 0x45cb
movq %rax, %rbx
movq 0x18(%rsp), %rax
addl %ebp, %eax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %r8
jmp 0x4545
movl (%r13), %ecx
cmpq $0x28, %rcx
ja 0x42f1
movq %rcx, %rax
addq 0x10(%r13), %rax
addl $0x8, %ecx
movl %ecx, (%r13)
jmp 0x42fd
movq 0x8(%r13), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x3130
testq %rax, %rax
je 0x4341
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rbx
movq %rax, %rdx
callq 0x3420
jmp 0x4347
movq 0x8(%r13), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%rax), %rsi
movl (%r13), %ecx
cmpq $0x28, %rcx
ja 0x431a
movq %rcx, %rax
addq 0x10(%r13), %rax
addl $0x8, %ecx
movl %ecx, (%r13)
jmp 0x4326
movq 0x8(%r13), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%rax), %rdx
testq %rdx, %rdx
je 0x434f
movq %rbx, %rdi
movq %r8, %r14
callq 0x3420
movq %r14, %r8
jmp 0x4521
movq %r14, %rbx
movq %r14, %rax
movq %r12, %r8
jmp 0x4521
movq %rbx, %rax
jmp 0x4521
cmpb $0x2e, %bl
jne 0x437b
movq %rax, %r14
movsbq (%rax), %rbx
testq %rbx, %rbx
je 0x437b
callq 0x3520
movq (%rax), %rcx
leaq 0x1(%r14), %rax
testb $0x8, 0x1(%rcx,%rbx,2)
jne 0x435c
movq 0x10(%r13), %rax
movq %rax, 0x40(%rsp)
movups (%r13), %xmm0
movaps %xmm0, 0x30(%rsp)
movsbl (%r14), %ebx
movl $0x7, %edx
leaq 0x506f(%rip), %rdi      # 0x940d
movl %ebx, %esi
callq 0x3240
testq %rax, %rax
je 0x43bc
movl (%r13), %eax
cmpl $0x28, %eax
ja 0x43f3
addl $0x8, %eax
movl %eax, (%r13)
jmp 0x43f8
movl $0x9, %edx
leaq 0x4d06(%rip), %rdi      # 0x90ce
movl %ebx, %esi
callq 0x3240
testq %rax, %rax
je 0x445a
movl 0x4(%r13), %eax
cmpl $0xa0, %eax
movq %r12, %r8
ja 0x4509
addl $0x10, %eax
movl %eax, 0x4(%r13)
jmp 0x43fb
addq $0x8, 0x8(%r13)
movq %r12, %r8
movq %r14, %rbx
subq %r8, %rbx
incq %rbx
movl $0x5, %ecx
movb $0x1, %dl
cmpq $0xd, %rbx
ja 0x4515
movl %r15d, %r12d
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r8, %rsi
movq %rbx, %rdx
callq 0x32f0
movb $0x0, 0x50(%rsp,%rbx)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %r15d
leaq 0x30(%rsp), %rdx
callq 0x33c0
movb $0x1, %dl
movl $0x5, %ecx
decq %r14
movq %r14, %r8
jmp 0x451d
movl $0xe, %ecx
cmpb $0x6c, %bl
movq %r12, %r8
je 0x448c
movzbl %bl, %eax
cmpl $0x68, %eax
jne 0x4513
cmpb $0x68, 0x1(%r14)
je 0x4493
cmpb $0x6c, %bl
je 0x448c
movzbl %bl, %eax
cmpl $0x68, %eax
je 0x44c6
jmp 0x4513
cmpb $0x6c, 0x1(%r14)
jne 0x44c1
movsbl 0x2(%r14), %esi
testl %esi, %esi
je 0x4513
movl $0x7, %edx
leaq 0x4f65(%rip), %rdi      # 0x940d
callq 0x3240
testq %rax, %rax
movq 0x8(%rsp), %rbx
je 0x4553
addq $0x2, %r14
jmp 0x44f1
cmpb $0x6c, %bl
jne 0x4513
movsbl 0x1(%r14), %esi
testl %esi, %esi
movq 0x8(%rsp), %rbx
je 0x4562
movl $0x7, %edx
leaq 0x4f29(%rip), %rdi      # 0x940d
callq 0x3240
testq %rax, %rax
je 0x4553
incq %r14
movl (%r13), %eax
cmpl $0x28, %eax
movq %r12, %r8
ja 0x4509
addl $0x8, %eax
movl %eax, (%r13)
jmp 0x43fb
addq $0x8, 0x8(%r13)
jmp 0x43fb
xorl %edx, %edx
movq 0x8(%rsp), %rbx
movq %rbx, %rax
testb %dl, %dl
je 0x453b
testq %rax, %rax
je 0x4536
incq %r8
xorl %ecx, %ecx
movl $0x1, %r15d
movq %rax, %rbx
jmp 0x453b
movl $0x4, %ecx
testl %ecx, %ecx
jne 0x4566
movl %r15d, %r12d
movq %rbp, %r14
incq %r8
movl %r12d, %r15d
movq %r14, %rbp
jmp 0x410b
xorl %edx, %edx
movq %rbx, %rax
movq %r12, %r8
movl $0xe, %ecx
jmp 0x451d
xorl %edx, %edx
jmp 0x451a
cmpl $0x4, %ecx
je 0x45d0
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
cmpl $0xe, %ecx
je 0x45d6
jmp 0x4606
testl %r15d, %r15d
je 0x4618
movq %rbx, %r13
movslq 0x10(%rsp), %r14
leaq 0x8(,%r14,8), %rsi
movq %rbp, %rdi
callq 0x33a0
testq %rax, %rax
movq 0x18(%rsp), %r12
je 0x467b
movq %rax, %rbx
incl 0x10(%rsp)
movq %r13, (%rax,%r14,8)
movslq -0x8(%r13), %rdi
callq 0x47a4
addl %eax, %r12d
movq %rbx, %rbp
jmp 0x4625
movq %r15, %rbp
jmp 0x45d0
xorl %ebx, %ebx
movq %r14, %rbp
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rbp, %rbp
je 0x45fe
cmpl $0x0, 0x10(%rsp)
je 0x45f6
movslq 0x10(%rsp), %r14
movq -0x8(%rbp,%r14,8), %rdi
callq 0x3280
decq %r14
jne 0x45e7
movq %rbp, %rdi
callq 0x3050
movq %rbx, %rdi
callq 0x3280
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x3280
movq 0x18(%rsp), %r12
movl $0x1, %ebx
cmpl $0xa, 0x10(%rsp)
jb 0x4690
movslq 0x10(%rsp), %rcx
movl $0x4, %ebx
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
cmpq $0x63, %rcx
jbe 0x4689
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x468e
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x4690
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %ebx
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x4645
addl $-0x3, %ebx
jmp 0x4690
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %r13, %rbx
jmp 0x45d6
addl $-0x2, %ebx
jmp 0x4690
decl %ebx
leal (%r12,%rbx), %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x3340
testq %rax, %rax
je 0x474e
movq %rax, %rdi
movq %rbp, 0x18(%rsp)
leal (%r12,%rbx), %eax
addl $0x3, %eax
movl %eax, 0x8(%rsp)
leaq 0x4a15(%rip), %rsi      # 0x90d7
movq %rdi, %r14
movl 0x10(%rsp), %ebx
movl %ebx, %edx
xorl %eax, %eax
callq 0x3460
testl %ebx, %ebx
jle 0x475b
movl 0x10(%rsp), %ecx
movq %rcx, 0x10(%rsp)
xorl %r13d, %r13d
movq 0x18(%rsp), %r15
movq %r14, %rbx
movslq %eax, %rbp
leaq (%rbx,%rbp), %rdi
movq (%r15,%r13,8), %rax
movslq -0x8(%rax), %rdx
leaq 0x49d9(%rip), %rsi      # 0x90dd
xorl %eax, %eax
callq 0x3460
addl %eax, %ebp
movslq %ebp, %rbp
leaq (%rbx,%rbp), %rdi
movq (%r15,%r13,8), %rsi
movslq -0x8(%rsi), %rdx
callq 0x32f0
movq (%r15,%r13,8), %rdi
movl -0x8(%rdi), %r14d
leal (%r14,%rbp), %r12d
callq 0x3280
movslq %r12d, %rax
movw $0xa0d, (%rbx,%rax)     # imm = 0xA0D
leal (%r14,%rbp), %eax
addl $0x2, %eax
incq %r13
cmpq %r13, 0x10(%rsp)
jne 0x46ee
jmp 0x475e
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
jmp 0x45d6
movq %r14, %rbx
movl 0x8(%rsp), %r15d
cmpl %r15d, %eax
jne 0x4785
cltq
movb $0x0, (%rbx,%rax)
movq 0x18(%rsp), %rdi
callq 0x3050
movq 0x20(%rsp), %rax
movq %rbx, (%rax)
jmp 0x4606
leaq 0x4958(%rip), %rdi      # 0x90e4
leaq 0x495f(%rip), %rsi      # 0x90f2
leaq 0x4962(%rip), %rcx      # 0x90fc
movl $0x19c, %edx            # imm = 0x19C
callq 0x31b0