// File: /workspace/github_c_makefile_star2_O0/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
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10770
decl %eax
movl %eax, %ecx
movq %rcx, -0xa0(%rbp)
subl $0x3, %eax
ja 0x869b1
movq -0xa0(%rbp), %rax
leaq 0x24074(%rip), %rcx     # 0xaa6e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10430
movsd %xmm0, -0x20(%rbp)
leaq -0x60(%rbp), %rsi
movsd -0x20(%rbp), %xmm0
movl $0x32, %edi
leaq 0x27d36(%rip), %rdx     # 0xae3d9
movb $0x1, %al
callq 0xc540
leaq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x14, %edx
movl $0x1, %ecx
callq 0x308d0
movsd -0x20(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jne 0x866d1
jp 0x866d1
jmp 0x866ed
leaq -0x60(%rbp), %rsi
movsd -0x20(%rbp), %xmm0
movl $0x32, %edi
leaq 0x2b2e7(%rip), %rdx     # 0xb19cd
movb $0x1, %al
callq 0xc540
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq $-0x1, %rcx
callq 0x10d80
jmp 0x869ca
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x10e80
jmp 0x869ca
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10200
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10370
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x74(%rbp), %rsi
shlq %rsi
addq $0x4, %rsi
callq 0x873e0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x8683a
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x867e3
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
movsbl (%rax,%rcx), %eax
sarl $0x4, %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0x2704b(%rip), %rax     # 0xad7e0
movb (%rax,%rcx), %dl
movq -0x68(%rbp), %rax
movl -0x78(%rbp), %ecx
shll %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0x2701d(%rip), %rax     # 0xad7e0
movb (%rax,%rcx), %dl
movq -0x68(%rbp), %rax
movl -0x78(%rbp), %ecx
shll %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x86771
movq -0x68(%rbp), %rax
movl -0x74(%rbp), %ecx
shll %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb $0x27, (%rax,%rcx)
movq -0x68(%rbp), %rax
movl -0x74(%rbp), %ecx
shll %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x68(%rbp), %rax
movb $0x58, (%rax)
movq -0x68(%rbp), %rax
movb $0x27, 0x1(%rax)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq $-0x1, %rcx
callq 0x10d80
movq -0x68(%rbp), %rdi
callq 0xa420
jmp 0x869ca
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10350
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x86861
jmp 0x869ca
movl $0x0, -0x7c(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x868b7
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x27, %eax
jne 0x868aa
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x868ac
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x86873
movq -0x8(%rbp), %rdi
movslq -0x7c(%rbp), %rsi
addq -0x88(%rbp), %rsi
addq $0x3, %rsi
callq 0x873e0
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x869af
movq -0x98(%rbp), %rax
movb $0x27, (%rax)
movl $0x0, -0x7c(%rbp)
movl $0x1, -0x80(%rbp)
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x8696d
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x98(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x80(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x27, %eax
jne 0x86960
movq -0x98(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x80(%rbp)
movslq %ecx, %rcx
movb $0x27, (%rax,%rcx)
jmp 0x86962
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x868fc
movq -0x98(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x80(%rbp)
movslq %ecx, %rcx
movb $0x27, (%rax,%rcx)
movq -0x98(%rbp), %rax
movslq -0x80(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movl -0x80(%rbp), %edx
leaq -0x7c58a(%rip), %rcx    # 0xa420
callq 0x10d80
jmp 0x869ca
movq -0x8(%rbp), %rdi
leaq 0x2a5af(%rip), %rsi     # 0xb0f6b
movl $0x4, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x10d80
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)