// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdx, %r14
movq %rdi, -0x48(%rbp)
movq 0x8(%rdi), %rax
movq %rax, -0x38(%rbp)
movq (%rdx), %rdi
callq 0xdf1e
movq %rax, %r15
movq 0x8(%r14), %rdi
callq 0xdf1e
movq %rax, -0x60(%rbp)
movq 0x10(%r14), %rdi
callq 0xdf1e
movq %rax, -0x50(%rbp)
leaq -0x2c(%rbp), %r14
movq %r15, -0x40(%rbp)
xorl %ebx, %ebx
cmpb $0x0, (%r15)
je 0x5afbc
movq %r15, %rdi
movq %r14, %rsi
callq 0x30a47
movl %eax, %r12d
cmpl $0x66, -0x2c(%rbp)
jne 0x5afb1
movslq %r12d, %rax
addq %rax, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x30a47
movl %eax, %r12d
cmpl $0x95, -0x2c(%rbp)
je 0x5af04
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x310c8
testq %rax, %rax
je 0x5afbc
movq %rax, %r13
movq %rax, %rdi
callq 0x4221d
movq -0x60(%rbp), %rdi
movq %r13, %rsi
callq 0xb1bf
testl %eax, %eax
jne 0x5afa5
movq %rbx, -0x58(%rbp)
testq %rbx, %rbx
movq %rbx, %rdx
leaq 0x153e0(%rip), %rax     # 0x70345
cmoveq %rax, %rdx
movq %r15, %rcx
movq -0x40(%rbp), %r8
subq %r8, %rcx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq 0x14094(%rip), %rsi     # 0x6f015
movq -0x50(%rbp), %r9
xorl %eax, %eax
callq 0x10594
movq %rbx, %rdi
movq %rax, %rbx
movq -0x58(%rbp), %rsi
callq 0x968b
movslq %r12d, %rax
addq %r15, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x968b
movslq %r12d, %rax
addq %rax, %r15
jmp 0x5aee2
testq %rbx, %rbx
leaq 0x1537f(%rip), %rdx     # 0x70345
cmovneq %rbx, %rdx
leaq 0x12be0(%rip), %rsi     # 0x6dbb1
movq -0x38(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rcx
xorl %eax, %eax
callq 0x10594
leaq -0x51c73(%rip), %rcx    # 0x9377
pushq $-0x1
popq %rdx
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0xe48d
movq %r14, %rdi
movq %rbx, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x968b