// File: /workspace/github_c_makefile_star2_O1/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 0x64935
leaq 0x1176b(%rip), %rcx     # 0x75ef8
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 0xf373
movq %rsi, %rdi
movl $0x1, %esi
callq 0xee49
testq %rax, %rax
je 0x64926
movq %rax, %r14
movl $0x3, %eax
xorl %esi, %esi
movzbl -0x3(%r14,%rax), %ecx
cmpl $0x27, %ecx
je 0x647e4
testl %ecx, %ecx
jne 0x647e7
jmp 0x6494e
incq %rsi
incq %rax
jmp 0x647d0
movq %rdx, %r15
movq %rsi, %rdi
callq 0xec61
movq %rax, %r14
movq (%r15), %rdi
movl $0x1, %esi
callq 0xed28
movl %eax, %r12d
movslq %eax, %r13
leaq 0x4(,%r13,2), %rsi
movq %rbx, %rdi
callq 0x65256
testq %rax, %rax
je 0x64926
movq %rax, %r15
testl %r12d, %r12d
jle 0x64864
movl %r12d, %eax
xorl %ecx, %ecx
leaq 0x14bd6(%rip), %rdx     # 0x79410
movzbl (%r14,%rcx), %esi
shrl $0x4, %esi
movb (%rsi,%rdx), %sil
movb %sil, 0x2(%r15,%rcx,2)
movzbl (%r14,%rcx), %esi
andl $0xf, %esi
movb (%rsi,%rdx), %sil
movb %sil, 0x3(%r15,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x6483a
movw $0x27, 0x2(%r15,%r13,2)
movw $0x2758, (%r15)         # imm = 0x2758
movq %rbx, %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xef1b
movq %r15, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa2e8
movq %rsi, %rdi
callq 0xed72
movsd %xmm0, -0x30(%rbp)
leaq 0x1502a(%rip), %rdx     # 0x798e2
leaq -0x70(%rbp), %r14
movl $0x32, %edi
movq %r14, %rsi
movb $0x1, %al
callq 0xb859
leaq -0x38(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
movl $0x14, %edx
movl $0x1, %ecx
callq 0x248aa
movsd -0x30(%rbp), %xmm0
ucomisd (%r15), %xmm0
jne 0x648f2
jnp 0x64909
leaq 0x185d8(%rip), %rdx     # 0x7ced1
leaq -0x70(%rbp), %rsi
movl $0x32, %edi
movb $0x1, %al
callq 0xb859
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xef1b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17b33(%rip), %rsi     # 0x7c46f
movq %rbx, %rdi
movl $0x4, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
jmp 0x649ba
addq %rax, %rsi
movq %rbx, %rdi
callq 0x65256
testq %rax, %rax
je 0x64926
movb $0x27, (%rax)
movb (%r14), %dl
testb %dl, %dl
je 0x64997
incq %r14
movl $0x1, %esi
movslq %esi, %rcx
movb %dl, (%rax,%rcx)
incq %rcx
cmpb $0x27, -0x1(%r14)
jne 0x64989
addl $0x2, %esi
movb $0x27, (%rax,%rcx)
movl %esi, %ecx
movb (%r14), %dl
incq %r14
movl %ecx, %esi
testb %dl, %dl
jne 0x64970
jmp 0x6499c
movl $0x1, %ecx
movslq %ecx, %rcx
leal 0x1(%rcx), %edx
movw $0x27, (%rax,%rcx)
leaq -0x5a6c7(%rip), %r8     # 0xa2e8
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %ecx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xef1b