// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rdi, -0x50(%rbp)
movq 0x8(%rdi), %rax
movq %rax, -0x30(%rbp)
movq (%rdx), %rdi
movl $0x1, %esi
callq 0xee49
movq %rax, %r15
movq 0x8(%rbx), %rdi
movl $0x1, %esi
callq 0xee49
movq %rax, %r14
movq 0x10(%rbx), %rdi
movl $0x1, %esi
callq 0xee49
movq %rax, -0x58(%rbp)
cmpb $0x0, (%r15)
movq %r15, -0x48(%rbp)
je 0x671aa
movq %r14, -0x70(%rbp)
incq %r14
movq %r14, -0x60(%rbp)
leaq -0x34(%rbp), %r14
movq $0x0, -0x40(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3590c
movl %eax, %r12d
cmpl $0x66, -0x34(%rbp)
jne 0x67196
movq %r15, %rbx
movslq %r12d, %r15
addq %rbx, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3590c
movl %eax, %r12d
cmpl $0x95, -0x34(%rbp)
je 0x67078
testq %rbx, %rbx
je 0x670cb
leal 0x1(%r12), %esi
movq -0x30(%rbp), %rdi
callq 0x115e9
movq %rax, %rbx
testq %rax, %rax
je 0x670cd
movslq %r12d, %r13
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x82f0
movb $0x0, (%rbx,%r13)
jmp 0x670cd
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x67191
movq %rbx, %rdi
callq 0x45e50
movq -0x70(%rbp), %rax
movb (%rax), %al
testb %al, %al
je 0x67114
movq -0x60(%rbp), %rdx
movq %rbx, %rcx
leaq 0xef6a(%rip), %r8       # 0x76060
movzbl %al, %esi
movb (%rsi,%r8), %sil
movzbl (%rcx), %edi
cmpb (%rdi,%r8), %sil
jne 0x6711e
incq %rcx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x670f6
jmp 0x6711e
movq %rbx, %rcx
leaq 0xef42(%rip), %r8       # 0x76060
movzbl %al, %eax
movb (%rax,%r8), %al
movzbl (%rcx), %ecx
cmpb (%rcx,%r8), %al
jne 0x67185
movq -0x40(%rbp), %r13
testq %r13, %r13
movq %r13, %rdx
leaq 0x17221(%rip), %rax     # 0x7e360
cmoveq %rax, %rdx
movq %r15, %rcx
movq -0x48(%rbp), %r8
subq %r8, %rcx
movq -0x30(%rbp), %rdi
leaq 0x15e9d(%rip), %rsi     # 0x7cff5
movq -0x58(%rbp), %r9
xorl %eax, %eax
callq 0x117e2
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x9c3a
movslq %r12d, %rax
addq %r15, %rax
movq %rax, -0x48(%rbp)
movq -0x68(%rbp), %r13
movq %r13, -0x40(%rbp)
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x9c3a
testq %rbx, %rbx
je 0x671b2
movslq %r12d, %rax
cmpb $0x0, (%r15,%rax)
leaq (%r15,%rax), %r15
jne 0x67060
jmp 0x671b2
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rbx
testq %rbx, %rbx
leaq 0x171a0(%rip), %rdx     # 0x7e360
cmovneq %rbx, %rdx
leaq 0x149c6(%rip), %rsi     # 0x7bb91
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq -0x48(%rbp), %rcx
xorl %eax, %eax
callq 0x117e2
leaq -0x5d910(%rip), %r8     # 0x98d4
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xef1b
movq %r14, %rdi
movq %rbx, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9c3a