// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: renameParentFunc
static void renameParentFunc(
  sqlite3_context *context,
  int NotUsed,
  sqlite3_value **argv
){
  sqlite3 *db = sqlite3_context_db_handle(context);
  char *zOutput = 0;
  char *zResult;
  unsigned char const *zInput = sqlite3_value_text(argv[0]);
  unsigned char const *zOld = sqlite3_value_text(argv[1]);
  unsigned char const *zNew = sqlite3_value_text(argv[2]);

  unsigned const char *z;         /* Pointer to token */
  int n;                          /* Length of token z */
  int token;                      /* Type of token */

  UNUSED_PARAMETER(NotUsed);
  for(z=zInput; *z; z=z+n){
    n = sqlite3GetToken(z, &token);
    if( token==TK_REFERENCES ){
      char *zParent;
      do {
        z += n;
        n = sqlite3GetToken(z, &token);
      }while( token==TK_SPACE );

      zParent = sqlite3DbStrNDup(db, (const char *)z, n);
      if( zParent==0 ) break;
      sqlite3Dequote(zParent);
      if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
        char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", 
            (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew
        );
        sqlite3DbFree(db, zOutput);
        zOutput = zOut;
        zInput = &z[n];
      }
      sqlite3DbFree(db, zParent);
    }
  }

  zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput), 
  sqlite3_result_text(context, zResult, -1, SQLITE_DYNAMIC);
  sqlite3DbFree(db, zOutput);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rdi, -0x50(%rbp)
movq 0x8(%rdi), %rax
movq %rax, -0x38(%rbp)
movq (%rdx), %rdi
movl $0x1, %esi
callq 0xef29
movq %rax, %r15
movq 0x8(%r14), %rdi
movl $0x1, %esi
callq 0xef29
movq %rax, %rbx
movq 0x10(%r14), %rdi
movl $0x1, %esi
callq 0xef29
movq %rax, -0x58(%rbp)
cmpb $0x0, (%r15)
movq %r15, -0x48(%rbp)
je 0x66f87
movq %rbx, -0x70(%rbp)
incq %rbx
movq %rbx, -0x60(%rbp)
leaq -0x3c(%rbp), %r14
leaq 0xf261(%rip), %rbx      # 0x760b0
movq $0x0, -0x30(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x35fcf
movl %eax, %r13d
cmpl $0x66, -0x3c(%rbp)
jne 0x66efe
movq %r15, %r12
movslq %r13d, %r15
addq %r12, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x35fcf
movl %eax, %r13d
cmpl $0x95, -0x3c(%rbp)
je 0x66e6f
testq %r12, %r12
je 0x66f8f
leal 0x1(%r13), %esi
movq -0x38(%rbp), %rdi
callq 0x11721
testq %rax, %rax
je 0x66f8f
movq %rax, %r12
movslq %r13d, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x82f0
movb $0x0, (%r12,%r13)
movq %r12, %rdi
callq 0x461c6
movq -0x70(%rbp), %rax
movb (%rax), %dl
testb %dl, %dl
je 0x66f03
movq -0x60(%rbp), %rcx
movq %r12, %rax
movzbl %dl, %edx
movb (%rdx,%rbx), %sil
movzbl (%rax), %edi
cmpb (%rdi,%rbx), %sil
jne 0x66f08
incq %rax
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0x66ee0
jmp 0x66f06
movslq %r13d, %r13
jmp 0x66f76
movq %r12, %rax
xorl %edx, %edx
movb (%rdx,%rbx), %cl
movzbl (%rax), %eax
cmpb (%rax,%rbx), %cl
movq -0x38(%rbp), %rdi
jne 0x66f6e
movq -0x30(%rbp), %rdx
movq %rdx, -0x30(%rbp)
testq %rdx, %rdx
leaq 0x17487(%rip), %rax     # 0x7e3b0
cmoveq %rax, %rdx
movq %r15, %rcx
movq -0x48(%rbp), %r8
subq %r8, %rcx
leaq 0x160b7(%rip), %rsi     # 0x7cff5
movq -0x58(%rbp), %r9
xorl %eax, %eax
callq 0x11900
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x9ca4
movq -0x38(%rbp), %rdi
leaq (%r15,%r13), %rax
movq %rax, -0x48(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x30(%rbp)
movq %r12, %rsi
callq 0x9ca4
cmpb $0x0, (%r15,%r13)
leaq (%r15,%r13), %r15
jne 0x66e57
jmp 0x66f8f
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %r14
testq %r14, %r14
leaq 0x17413(%rip), %rdx     # 0x7e3b0
cmovneq %r14, %rdx
leaq 0x14be9(%rip), %rsi     # 0x7bb91
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq -0x48(%rbp), %rcx
xorl %eax, %eax
callq 0x11900
leaq -0x5d6b1(%rip), %r8     # 0x9910
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xeffe
movq %rbx, %rdi
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9ca4