// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: quoteFunc
static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {
      double r1, r2;
      char zBuf[50];
      r1 = sqlite3_value_double(argv[0]);
      sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1);
      sqlite3AtoF(zBuf, &r2, 20, SQLITE_UTF8);
      if( r1!=r2 ){
        sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.20e", r1);
      }
      sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
      break;
    }
    case SQLITE_INTEGER: {
      sqlite3_result_value(context, argv[0]);
      break;
    }
    case SQLITE_BLOB: {
      char *zText = 0;
      char const *zBlob = sqlite3_value_blob(argv[0]);
      int nBlob = sqlite3_value_bytes(argv[0]);
      assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
      zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4); 
      if( zText ){
        int i;
        for(i=0; i<nBlob; i++){
          zText[(i*2)+2] = hexdigits[(zBlob[i]>>4)&0x0F];
          zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F];
        }
        zText[(nBlob*2)+2] = '\'';
        zText[(nBlob*2)+3] = '\0';
        zText[0] = 'X';
        zText[1] = '\'';
        sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
        sqlite3_free(zText);
      }
      break;
    }
    case SQLITE_TEXT: {
      int i,j;
      u64 n;
      const unsigned char *zArg = sqlite3_value_text(argv[0]);
      char *z;

      if( zArg==0 ) return;
      for(i=0, n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
      z = contextMalloc(context, ((i64)i)+((i64)n)+3);
      if( z ){
        z[0] = '\'';
        for(i=0, j=1; zArg[i]; i++){
          z[j++] = zArg[i];
          if( zArg[i]=='\'' ){
            z[j++] = '\'';
          }
        }
        z[j++] = '\'';
        z[j] = 0;
        sqlite3_result_text(context, z, j, sqlite3_free);
      }
      break;
    }
    default: {
      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
      sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
      break;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq (%rdx), %rsi
movzbl 0x26(%rsi), %eax
decl %eax
cmpl $0x3, %eax
ja 0x58ee1
leaq 0xf157(%rip), %rcx      # 0x67eec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe4e0
movq %rsi, %rdi
callq 0xdf1e
testq %rax, %rax
je 0x58ed2
movq %rax, %r14
pushq $0x3
popq %rax
xorl %esi, %esi
movzbl -0x3(%r14,%rax), %ecx
cmpl $0x27, %ecx
je 0x58de5
testl %ecx, %ecx
jne 0x58de8
jmp 0x58ef5
incq %rsi
incq %rax
jmp 0x58dd1
movq %rdx, %r15
movq %rsi, %rdi
callq 0xde7e
movq %rax, %r14
movq (%r15), %rdi
callq 0xdf2d
movl %eax, %r12d
movslq %eax, %r13
leaq 0x4(,%r13,2), %rsi
movq %rbx, %rdi
callq 0x5959e
testq %rax, %rax
je 0x58ed2
movq %rax, %r15
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
leaq 0x125fb(%rip), %rcx     # 0x6b430
cmpq %rax, %r12
je 0x58f34
movzbl (%r14,%rax), %edx
shrl $0x4, %edx
movb (%rdx,%rcx), %dl
movb %dl, 0x2(%r15,%rax,2)
movzbl (%r14,%rax), %edx
andl $0xf, %edx
movb (%rdx,%rcx), %dl
movb %dl, 0x3(%r15,%rax,2)
incq %rax
jmp 0x58e35
movq %rsi, %rdi
callq 0xdf89
movsd %xmm0, -0x30(%rbp)
leaq 0x12a8b(%rip), %rdx     # 0x6b902
pushq $0x32
popq %rdi
leaq -0x70(%rbp), %r14
movq %r14, %rsi
movb $0x1, %al
callq 0xaf26
leaq -0x38(%rbp), %r15
pushq $0x14
popq %rdx
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x20fe3
movsd -0x30(%rbp), %xmm0
ucomisd (%r15), %xmm0
jne 0x58eab
jnp 0x58ec0
leaq 0x1603f(%rip), %rdx     # 0x6eef1
pushq $0x32
popq %rdi
leaq -0x70(%rbp), %rsi
movb $0x1, %al
callq 0xaf26
leaq -0x70(%rbp), %rsi
pushq $-0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rdi
callq 0xe48d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x155a7(%rip), %rsi     # 0x6e48f
pushq $0x4
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
jmp 0x58f7e
addq %rax, %rsi
movq %rbx, %rdi
callq 0x5959e
testq %rax, %rax
je 0x58ed2
movb $0x27, (%rax)
pushq $0x1
popq %rcx
movb (%r14), %dil
movslq %ecx, %rsi
leaq 0x1(%rsi), %rdx
testb %dil, %dil
je 0x58f69
movb %dil, (%rax,%rsi)
cmpb $0x27, (%r14)
jne 0x58f2d
addl $0x2, %ecx
movb $0x27, (%rax,%rdx)
movl %ecx, %edx
incq %r14
movl %edx, %ecx
jmp 0x58f0b
movw $0x27, 0x2(%r15,%r13,2)
movw $0x2758, (%r15)         # imm = 0x2758
pushq $-0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe48d
movq %r15, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9c7b
movb $0x27, (%rax,%rsi)
movb $0x0, (%rax,%rdx)
leaq -0x4f2fd(%rip), %rcx    # 0x9c7b
movq %rbx, %rdi
movq %rax, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe48d