// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rdi, %r14
movq $0x0, (%rsp)
callq 0x5889
movq %rax, %rbx
testq %r14, %r14
je 0x8055
movq $0x0, (%r14)
movq %r14, 0x8(%rsp)
xorl %r15d, %r15d
leaq 0x6fe9(%rip), %r14      # 0xf04d
movl $0x8021, %r13d          # imm = 0x8021
movzbl (%r12), %eax
cmpl $0x3f, %eax
je 0x807d
testl %eax, %eax
je 0x80e3
movq %r12, %rbp
jmp 0x80c8
movzbl 0x1(%r12), %eax
movl %eax, %ecx
addl $-0x64, %ecx
cmpl $0xf, %ecx
ja 0x809e
btl %ecx, %r13d
jae 0x809e
cmpl $0x20, %r15d
jne 0x80b5
jmp 0x8142
movl $0x1, %ebp
cmpb $0x62, %al
jne 0x8322
cmpl $0x20, %r15d
je 0x8322
movq %r12, %rbp
incq %rbp
movslq %r15d, %rcx
incl %r15d
movb %al, 0x20(%rsp,%rcx)
movq %r14, %r12
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6120
movq %rax, %rbx
incq %rbp
movq %rbp, %r12
jmp 0x806a
movq %fs:-0x8, %rdi
xorl %r13d, %r13d
movq %rsp, %rcx
movq %rbx, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x2220
testl %eax, %eax
je 0x814c
movl %eax, %ebp
cmpl $0x0, 0xd1a5(%rip)      # 0x152b4
je 0x8322
movq %fs:-0x8, %r14
movq %r14, %rdi
callq 0x2240
leaq 0x67d1(%rip), %rdi      # 0xe8fe
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
jmp 0x8322
movl $0x1, %ebp
jmp 0x8322
testl %r15d, %r15d
setg %r14b
jle 0x82d7
movl %r15d, %ebp
movq %rbp, 0x18(%rsp)
negq %rbp
movl $0x1, %r12d
movq 0x10(%rsp), %r15
movzbl 0x1f(%rsp,%r12), %eax
cmpl $0x68, %eax
jg 0x81ab
cmpl $0x62, %eax
je 0x81d7
movl $0x0, %r13d
cmpl $0x64, %eax
jne 0x82b2
movl 0x4(%r15), %ecx
cmpq $0xa0, %rcx
ja 0x8207
movq %rcx, %rax
addq 0x10(%r15), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%r15)
jmp 0x8213
cmpl $0x69, %eax
je 0x81ef
movl $0x0, %r13d
cmpl $0x73, %eax
jne 0x82b2
movl (%r15), %ecx
cmpq $0x28, %rcx
ja 0x8228
movq %rcx, %rax
addq 0x10(%r15), %rax
addl $0x8, %ecx
movl %ecx, (%r15)
jmp 0x8234
movl (%r15), %ecx
cmpq $0x28, %rcx
ja 0x824d
movq %rcx, %rax
addq 0x10(%r15), %rax
addl $0x8, %ecx
movl %ecx, (%r15)
jmp 0x8259
movl (%r15), %ecx
cmpq $0x28, %rcx
ja 0x8274
movq %rcx, %rax
addq 0x10(%r15), %rax
addl $0x8, %ecx
movl %ecx, (%r15)
jmp 0x8280
movq 0x8(%r15), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r15)
movq (%rsp), %rdi
movsd (%rax), %xmm0
movl %r12d, %esi
callq 0x20b0
jmp 0x82af
movq 0x8(%r15), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r15)
movq (%rsp), %rdi
movq (%rax), %rdx
movl %r12d, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x21f0
jmp 0x82af
movq 0x8(%r15), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r15)
movq (%rax), %rdx
movl (%r15), %ecx
cmpq $0x28, %rcx
ja 0x8291
movq %rcx, %rax
addq 0x10(%r15), %rax
addl $0x8, %ecx
movl %ecx, (%r15)
jmp 0x829d
movq 0x8(%r15), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r15)
movq (%rsp), %rdi
movq (%rax), %rdx
movl %r12d, %esi
callq 0x2260
jmp 0x82af
movq 0x8(%r15), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r15)
movq (%rax), %rcx
movq (%rsp), %rdi
movl %r12d, %esi
xorl %r8d, %r8d
callq 0x23b0
movl %eax, %r13d
testl %r13d, %r13d
jne 0x82d7
cmpq 0x18(%rsp), %r12
setb %r14b
leaq (%r12,%rbp), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x816f
xorl %r13d, %r13d
movl %r13d, %ebp
testb $0x1, %r14b
jne 0x8322
cmpq $0x0, 0x8(%rsp)
sete %r14b
movq (%rsp), %rdi
callq 0x2350
movl %eax, %ebp
cmpl $0x64, %eax
setne %al
orb %r14b, %al
jne 0x8322
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movl $0x0, 0x8(%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
movq %rax, (%rsp)
movl $0x64, %ebp
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8330
callq 0x2410
movq %rbx, %rdi
callq 0x591d
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq