// File: /workspace/github_c_makefile_star2_O2/antirez[P]stonky/stonky.c
// Function: sqlGenericQuery
int sqlGenericQuery(sqlRow *row, const char *sql, va_list ap) {
    int rc = SQLITE_ERROR;
    sqlite3_stmt *stmt = NULL;
    sds query = sdsempty();
    if (row) row->stmt = NULL; /* On error sqlNextRow() should return false. */

    /* We need to build the query, substituting the following three
     * classes of patterns with just "?", remembering the order and
     * type, and later using the sql3 binding API in order to prepare
     * the query:
     *
     * ?s string
     * ?b blob (varargs must have char ptr and size_t len)
     * ?i int64_t
     * ?d double
     */
    char spec[SQL_MAX_SPEC];
    int numspec = 0;
    const char *p = sql;
    while(p[0]) {
        if (p[0] == '?') {
            if (p[1] == 's' || p[1] == 'i' || p[1] == 'd' || p[1] == 'b') {
                if (numspec == SQL_MAX_SPEC) goto error;
                spec[numspec++] = p[1];
            } else {
                goto error;
            }
            query = sdscatlen(query,"?",1);
            p++; /* Skip the specifier. */
        } else {
            query = sdscatlen(query,p,1);
        }
        p++;
    }

    /* Prepare the query and bind the query arguments. */
    rc = sqlite3_prepare_v2(DbHandle,query,-1,&stmt,NULL);
    if (rc != SQLITE_OK) {
        if (VerboseMode) printf("%p: Query error: %s: %s\n",
                                (void*)DbHandle,
                                query,
                                sqlite3_errmsg(DbHandle));
        goto error;
    }

    for (int j = 0; j < numspec; j++) {
        switch(spec[j]) {
        case 'b': {
                  char *blobptr = va_arg(ap,char*);
                  size_t bloblen = va_arg(ap,size_t);
                  rc = sqlite3_bind_blob64(stmt,j+1,blobptr,bloblen,NULL);
                  }
                  break;
        case 's': rc = sqlite3_bind_text(stmt,j+1,va_arg(ap,char*),-1,NULL);
                  break;
        case 'i': rc = sqlite3_bind_int64(stmt,j+1,va_arg(ap,int64_t));
                  break;
        case 'd': rc = sqlite3_bind_double(stmt,j+1,va_arg(ap,double));
                  break;
        }
        if (rc != SQLITE_OK) goto error;
    }

    /* Execute. */
    rc = sqlite3_step(stmt);
    if (rc == SQLITE_ROW) {
        if (row) {
            row->stmt = stmt;
            row->cols = 0;
            row->col = NULL;
            stmt = NULL; /* Don't free it on cleanup. */
        }
    }

error:
    if (stmt) sqlite3_finalize(stmt);
    sdsfree(query);
    return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r14
andq $0x0, 0x8(%rsp)
callq 0x4ee9
movq %rax, %rbx
testq %r14, %r14
je 0x6bc2
andq $0x0, (%r14)
movq %r14, 0x18(%rsp)
xorl %r14d, %r14d
leaq 0x60c4(%rip), %r12      # 0xcc95
pushq $0x1
popq %rbp
movzbl (%r15), %eax
cmpl $0x3f, %eax
je 0x6be6
testl %eax, %eax
je 0x6c3d
movq %r15, %r13
jmp 0x6c24
movzbl 0x1(%r15), %eax
movl %eax, %ecx
addl $-0x64, %ecx
cmpl $0xf, %ecx
ja 0x6bff
movl $0x8021, %edx           # imm = 0x8021
btl %ecx, %edx
jb 0x6c07
cmpb $0x62, %al
jne 0x6c97
cmpl $0x20, %r14d
je 0x6c97
movq %r15, %r13
incq %r13
movslq %r14d, %rcx
incl %r14d
movb %al, 0x20(%rsp,%rcx)
movq %r12, %r15
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x5534
movq %rax, %rbx
incq %r13
movq %r13, %r15
jmp 0x6bd4
movq %fs:-0x8, %rdi
xorl %r13d, %r13d
pushq $-0x1
popq %rdx
leaq 0x8(%rsp), %rcx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x2230
testl %eax, %eax
je 0x6cc4
cmpl $0x0, 0xc64d(%rip)      # 0x132b4
je 0x6c9a
movq %fs:-0x8, %r14
movq %r14, %rdi
movl %eax, %ebp
callq 0x2250
leaq 0x58c3(%rip), %rdi      # 0xc546
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
movl %ebp, %eax
jmp 0x6c9a
pushq $0x1
popq %rax
movl %eax, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x6cab
callq 0x2420
movq %rbx, %rdi
callq 0x4f65
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
cmovlel %r13d, %r14d
pushq $-0x1
popq %rbp
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r12
cmpq %r13, %r14
je 0x6e4f
movzbl 0x20(%rsp,%r13), %eax
cmpl $0x73, %eax
je 0x6d81
cmpl $0x64, %eax
je 0x6d3f
cmpl $0x69, %eax
je 0x6d5f
cmpl $0x62, %eax
jne 0x6e47
movl (%r12), %ecx
cmpq $0x29, %rcx
jae 0x6dc5
movq 0x10(%r12), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%r12)
movq (%rdx,%rcx), %rdx
cmpl $0x20, %ecx
ja 0x6dd6
addq 0x10(%r12), %rax
addl $0x10, %ecx
movl %ecx, (%r12)
jmp 0x6de4
movl 0x4(%r12), %ecx
cmpq $0xa0, %rcx
ja 0x6da3
movq %rcx, %rax
addq 0x10(%r12), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%r12)
jmp 0x6db1
movl (%r12), %ecx
cmpq $0x28, %rcx
ja 0x6dfa
movq %rcx, %rax
addq 0x10(%r12), %rax
addl $0x8, %ecx
movl %ecx, (%r12)
jmp 0x6e08
movl (%r12), %ecx
cmpq $0x28, %rcx
ja 0x6e1b
movq %rcx, %rax
addq 0x10(%r12), %rax
addl $0x8, %ecx
movl %ecx, (%r12)
jmp 0x6e29
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq 0x8(%rsp), %rdi
movsd (%rax), %xmm0
leal 0x1(%r13), %esi
callq 0x20b0
jmp 0x6e3f
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq (%rax), %rdx
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq (%rax), %rcx
movq 0x8(%rsp), %rdi
leal 0x1(%r13), %esi
xorl %r8d, %r8d
callq 0x23c0
jmp 0x6e3f
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq 0x8(%rsp), %rdi
movq (%rax), %rdx
leal 0x1(%r13), %esi
callq 0x2270
jmp 0x6e3f
movq 0x8(%r12), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r12)
movq 0x8(%rsp), %rdi
movq (%rax), %rdx
leal 0x1(%r13), %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2200
testl %eax, %eax
jne 0x6c9a
incq %r13
jmp 0x6cd8
testq %r15, %r15
sete %bpl
movq 0x8(%rsp), %rdi
callq 0x2360
cmpl $0x64, %eax
setne %cl
orb %bpl, %cl
jne 0x6c9a
movq 0x8(%rsp), %rax
movq %rax, (%r15)
andl $0x0, 0x8(%r15)
andq $0x0, 0x10(%r15)
andq $0x0, 0x8(%rsp)
pushq $0x64
popq %rbp
jmp 0x6cab