// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: renameTriggerFunc
static void renameTriggerFunc(
  sqlite3_context *context,
  int NotUsed,
  sqlite3_value **argv
){
  unsigned char const *zSql = sqlite3_value_text(argv[0]);
  unsigned char const *zTableName = sqlite3_value_text(argv[1]);

  int token;
  Token tname;
  int dist = 3;
  unsigned char const *zCsr = zSql;
  int len = 0;
  char *zRet;
  sqlite3 *db = sqlite3_context_db_handle(context);

  UNUSED_PARAMETER(NotUsed);

  /* The principle used to locate the table name in the CREATE TRIGGER 
  ** statement is that the table name is the first token that is immediatedly
  ** preceded by either TK_ON or TK_DOT and immediatedly followed by one
  ** of TK_WHEN, TK_BEGIN or TK_FOR.
  */
  if( zSql ){
    do {

      if( !*zCsr ){
        /* Ran out of input before finding the table name. Return NULL. */
        return;
      }

      /* Store the token that zCsr points to in tname. */
      tname.z = (char*)zCsr;
      tname.n = len;

      /* Advance zCsr to the next token. Store that token type in 'token',
      ** and its length in 'len' (to be used next iteration of this loop).
      */
      do {
        zCsr += len;
        len = sqlite3GetToken(zCsr, &token);
      }while( token==TK_SPACE );
      assert( len>0 );

      /* Variable 'dist' stores the number of tokens read since the most
      ** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN 
      ** token is read and 'dist' equals 2, the condition stated above
      ** to be met.
      **
      ** Note that ON cannot be a database, table or column name, so
      ** there is no need to worry about syntax like 
      ** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
      */
      dist++;
      if( token==TK_DOT || token==TK_ON ){
        dist = 0;
      }
    } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );

    /* Variable tname now contains the token that is the old table-name
    ** in the CREATE TRIGGER statement.
    */
    zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql, 
       zTableName, tname.z+tname.n);
    sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10350
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x10350
movq %rax, -0x28(%rbp)
movl $0x3, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x8(%rbp), %rdi
callq 0x117b0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x89c13
jmp 0x89b24
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x89b32
jmp 0x89c13
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x54(%rbp), %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x49ae0
movl %eax, -0x54(%rbp)
cmpl $0x95, -0x2c(%rbp)
je 0x89b40
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x76, -0x2c(%rbp)
je 0x89b7f
cmpl $0x68, -0x2c(%rbp)
jne 0x89b86
movl $0x0, -0x44(%rbp)
jmp 0x89b88
movb $0x1, %al
cmpl $0x2, -0x44(%rbp)
movb %al, -0x69(%rbp)
jne 0x89bbc
xorl %eax, %eax
cmpl $0x87, -0x2c(%rbp)
movb %al, -0x6a(%rbp)
je 0x89bb6
xorl %eax, %eax
cmpl $0x2d, -0x2c(%rbp)
movb %al, -0x6a(%rbp)
je 0x89bb6
cmpl $0x5, -0x2c(%rbp)
setne %al
movb %al, -0x6a(%rbp)
movb -0x6a(%rbp), %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x89b24
movq -0x68(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
subq %rax, %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x40(%rbp), %r9
movl -0x38(%rbp), %eax
addq %rax, %r9
leaq 0x27f04(%rip), %rsi     # 0xb1af3
movb $0x0, %al
callq 0x137f0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x8027e(%rip), %rcx    # 0x9990
callq 0x10d80
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)