// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
callq 0x56c6
movq %rax, %rbx
testq %r14, %r14
je 0x7dd8
movq $0x0, (%r14)
movq %r14, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0x7246(%rip), %r14      # 0xf02d
movl $0x8021, %r15d          # imm = 0x8021
movzbl (%r12), %eax
cmpl $0x3f, %eax
je 0x7e00
testl %eax, %eax
je 0x7e66
movq %r12, %rbp
jmp 0x7e4b
movzbl 0x1(%r12), %eax
movl %eax, %ecx
addl $-0x64, %ecx
cmpl $0xf, %ecx
ja 0x7e21
btl %ecx, %r15d
jae 0x7e21
cmpl $0x20, %r13d
jne 0x7e38
jmp 0x7ebd
movl $0x1, %ebp
cmpb $0x62, %al
jne 0x7ec2
cmpl $0x20, %r13d
je 0x7ec2
movq %r12, %rbp
incq %rbp
movslq %r13d, %rcx
incl %r13d
movb %al, 0x20(%rsp,%rcx)
movq %r14, %r12
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5f26
movq %rax, %rbx
incq %rbp
movq %rbp, %r12
jmp 0x7ded
movq %fs:-0x8, %rdi
leaq 0x8(%rsp), %rcx
movq %rbx, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x2230
testl %eax, %eax
je 0x7eea
movl %eax, %ebp
cmpl $0x0, 0xd423(%rip)      # 0x152b4
je 0x7ec2
movq %fs:-0x8, %r14
movq %r14, %rdi
callq 0x2250
leaq 0x6a33(%rip), %rdi      # 0xe8de
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
jmp 0x7ec2
movl $0x1, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x7ed1
callq 0x2420
movq %rbx, %rdi
callq 0x5775
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r13d, %r13d
jle 0x806f
movl %r13d, %r12d
xorl %r13d, %r13d
movzbl 0x20(%rsp,%r13), %eax
cmpl $0x68, %eax
jg 0x7f39
cmpl $0x62, %eax
je 0x7f69
cmpl $0x64, %eax
jne 0x8063
movq 0x10(%rsp), %rdx
movl 0x4(%rdx), %ecx
cmpq $0xa0, %rcx
ja 0x7fc4
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x10, %ecx
movl %ecx, 0x4(%rdx)
jmp 0x7fd0
cmpl $0x69, %eax
je 0x7fa2
cmpl $0x73, %eax
jne 0x8063
movq 0x10(%rsp), %rdx
movl (%rdx), %ecx
cmpq $0x28, %rcx
ja 0x7fe4
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x8, %ecx
movl %ecx, (%rdx)
jmp 0x7ff0
movq 0x10(%rsp), %rsi
movl (%rsi), %ecx
cmpq $0x29, %rcx
jae 0x800b
movq 0x10(%rsi), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%rsi)
movq (%rdx,%rcx), %rdx
cmpl $0x20, %ecx
ja 0x801a
addq 0x10(%rsi), %rax
addl $0x10, %ecx
movl %ecx, (%rsi)
jmp 0x8026
movq 0x10(%rsp), %rdx
movl (%rdx), %ecx
cmpq $0x28, %rcx
ja 0x803c
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x8, %ecx
movl %ecx, (%rdx)
jmp 0x8048
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movq 0x8(%rsp), %rdi
movsd (%rax), %xmm0
leal 0x1(%r13), %esi
callq 0x20b0
jmp 0x8059
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movq 0x8(%rsp), %rdi
movq (%rax), %rdx
leal 0x1(%r13), %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x2200
jmp 0x8059
movq 0x8(%rsi), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsi)
movq (%rax), %rdx
movq 0x8(%rsi), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsi)
movq (%rax), %rcx
movq 0x8(%rsp), %rdi
leal 0x1(%r13), %esi
xorl %r8d, %r8d
callq 0x23c0
jmp 0x8059
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movq 0x8(%rsp), %rdi
movq (%rax), %rdx
leal 0x1(%r13), %esi
callq 0x2270
movl %eax, %ebp
testl %eax, %eax
jne 0x7ec2
incq %r13
cmpq %r13, %r12
jne 0x7ef9
cmpq $0x0, 0x18(%rsp)
sete %r14b
movq 0x8(%rsp), %rdi
callq 0x2360
movl %eax, %ebp
cmpl $0x64, %eax
setne %al
orb %r14b, %al
jne 0x7ec2
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl $0x0, 0x8(%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
movq %rax, 0x8(%rsp)
movl $0x64, %ebp
jmp 0x7ed1