// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: renameEditSql
static int renameEditSql(
  sqlite3_context *pCtx,          /* Return result here */
  RenameCtx *pRename,             /* Rename context */
  const char *zSql,               /* SQL statement to edit */
  const char *zNew,               /* New token text */
  int bQuote                      /* True to always quote token */
){
  int nNew = sqlite3Strlen30(zNew);
  int nSql = sqlite3Strlen30(zSql);
  sqlite3 *db = sqlite3_context_db_handle(pCtx);
  int rc = SQLITE_OK;
  char *zQuot;
  char *zOut;
  int nQuot;

  /* Set zQuot to point to a buffer containing a quoted copy of the
  ** identifier zNew. If the corresponding identifier in the original
  ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to
  ** point to zQuot so that all substitutions are made using the
  ** quoted version of the new column name.  */
  zQuot = sqlite3MPrintf(db, "\"%w\"", zNew);
  if( zQuot==0 ){
    return SQLITE_NOMEM;
  }else{
    nQuot = sqlite3Strlen30(zQuot);
  }
  if( bQuote ){
    zNew = zQuot;
    nNew = nQuot;
  }

  /* At this point pRename->pList contains a list of RenameToken objects
  ** corresponding to all tokens in the input SQL that must be replaced
  ** with the new column name. All that remains is to construct and
  ** return the edited SQL string. */
  assert( nQuot>=nNew );
  zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1);
  if( zOut ){
    int nOut = nSql;
    memcpy(zOut, zSql, nSql);
    while( pRename->pList ){
      int iOff;                   /* Offset of token to replace in zOut */
      RenameToken *pBest = renameColumnTokenNext(pRename);

      u32 nReplace;
      const char *zReplace;
      if( sqlite3IsIdChar(*pBest->t.z) ){
        nReplace = nNew;
        zReplace = zNew;
      }else{
        nReplace = nQuot;
        zReplace = zQuot;
      }

      iOff = pBest->t.z - zSql;
      if( pBest->t.n!=nReplace ){
        memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n],
            nOut - (iOff + pBest->t.n)
        );
        nOut += nReplace - pBest->t.n;
        zOut[nOut] = '\0';
      }
      memcpy(&zOut[iOff], zReplace, nReplace);
      sqlite3DbFree(db, pBest);
    }

    sqlite3_result_text(pCtx, zOut, -1, SQLITE_TRANSIENT);
    sqlite3DbFree(db, zOut);
  }else{
    rc = SQLITE_NOMEM;
  }

  sqlite3_free(zQuot);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3c3400
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3c3400
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3c9230
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x1431f0(%rip), %rsi    # 0x5ad01a
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x469e48
movl $0x7, -0x4(%rbp)
jmp 0x469fd8
movq -0x50(%rbp), %rdi
callq 0x3c3400
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x469e68
movq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
imull -0x5c(%rbp), %ecx
addl %ecx, %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x3c9520
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x469fc2
movl -0x34(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x34(%rbp), %rdx
callq 0x19610
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x469f9a
movq -0x18(%rbp), %rdi
callq 0x46a1a0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %edi
callq 0x3d5ac0
cmpl $0x0, %eax
je 0x469eed
movl -0x30(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x469efb
movl -0x5c(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x64(%rbp)
movq -0x70(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x74(%rbp), %eax
je 0x469f6f
movq -0x58(%rbp), %rdi
movl -0x64(%rbp), %eax
addl -0x74(%rbp), %eax
movl %eax, %eax
addq %rax, %rdi
movq -0x58(%rbp), %rsi
movl -0x64(%rbp), %eax
movq -0x70(%rbp), %rcx
addl 0x10(%rcx), %eax
movl %eax, %eax
addq %rax, %rsi
movl -0x60(%rbp), %eax
movl -0x64(%rbp), %ecx
movq -0x70(%rbp), %rdx
addl 0x10(%rdx), %ecx
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x19bf0
movl -0x74(%rbp), %eax
movq -0x70(%rbp), %rcx
subl 0x10(%rcx), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movslq -0x60(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x58(%rbp), %rdi
movslq -0x64(%rbp), %rax
addq %rax, %rdi
movq -0x80(%rbp), %rsi
movl -0x74(%rbp), %eax
movl %eax, %edx
callq 0x19610
movq -0x40(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x3c00a0
jmp 0x469ead
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq $-0x1, %rcx
callq 0x3c86c0
movq -0x40(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x3c00a0
jmp 0x469fc9
movl $0x7, -0x44(%rbp)
movq -0x50(%rbp), %rdi
callq 0x3c0800
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)