// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3VdbeHalt
SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *p){
  int rc;                         /* Used to store transient return codes */
  sqlite3 *db = p->db;

  /* This function contains the logic that determines if a statement or
  ** transaction will be committed or rolled back as a result of the
  ** execution of this virtual machine. 
  **
  ** If any of the following errors occur:
  **
  **     SQLITE_NOMEM
  **     SQLITE_IOERR
  **     SQLITE_FULL
  **     SQLITE_INTERRUPT
  **
  ** Then the internal cache might have been left in an inconsistent
  ** state.  We need to rollback the statement transaction, if there is
  ** one, or the complete transaction if there is no statement transaction.
  */

  if( p->db->mallocFailed ){
    p->rc = SQLITE_NOMEM;
  }
  if( p->aOnceFlag ) memset(p->aOnceFlag, 0, p->nOnceFlag);
  closeAllCursors(p);
  if( p->magic!=VDBE_MAGIC_RUN ){
    return SQLITE_OK;
  }
  checkActiveVdbeCnt(db);

  /* No commit or rollback needed if the program never started or if the
  ** SQL statement does not read or write a database file.  */
  if( p->pc>=0 && p->bIsReader ){
    int mrc;   /* Primary error code from p->rc */
    int eStatementOp = 0;
    int isSpecialError;            /* Set to true if a 'special' error */

    /* Lock all btrees used by the statement */
    sqlite3VdbeEnter(p);

    /* Check for one of the special errors */
    mrc = p->rc & 0xff;
    assert( p->rc!=SQLITE_IOERR_BLOCKED );  /* This error no longer exists */
    isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
                     || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
    if( isSpecialError ){
      /* If the query was read-only and the error code is SQLITE_INTERRUPT, 
      ** no rollback is necessary. Otherwise, at least a savepoint 
      ** transaction must be rolled back to restore the database to a 
      ** consistent state.
      **
      ** Even if the statement is read-only, it is important to perform
      ** a statement or transaction rollback operation. If the error 
      ** occurred while writing to the journal, sub-journal or database
      ** file as part of an effort to free up cache space (see function
      ** pagerStress() in pager.c), the rollback is required to restore 
      ** the pager to a consistent state.
      */
      if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
        if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && p->usesStmtJournal ){
          eStatementOp = SAVEPOINT_ROLLBACK;
        }else{
          /* We are forced to roll back the active transaction. Before doing
          ** so, abort any other statements this handle currently has active.
          */
          sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
          sqlite3CloseSavepoints(db);
          db->autoCommit = 1;
        }
      }
    }

    /* Check for immediate foreign key violations. */
    if( p->rc==SQLITE_OK ){
      sqlite3VdbeCheckFk(p, 0);
    }
  
    /* If the auto-commit flag is set and this is the only active writer 
    ** VM, then we do either a commit or rollback of the current transaction. 
    **
    ** Note: This block also runs if one of the special errors handled 
    ** above has occurred. 
    */
    if( !sqlite3VtabInSync(db) 
     && db->autoCommit 
     && db->nVdbeWrite==(p->readOnly==0) 
    ){
      if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
        rc = sqlite3VdbeCheckFk(p, 1);
        if( rc!=SQLITE_OK ){
          if( NEVER(p->readOnly) ){
            sqlite3VdbeLeave(p);
            return SQLITE_ERROR;
          }
          rc = SQLITE_CONSTRAINT_FOREIGNKEY;
        }else{ 
          /* The auto-commit flag is true, the vdbe program was successful 
          ** or hit an 'OR FAIL' constraint and there are no deferred foreign
          ** key constraints to hold up the transaction. This means a commit 
          ** is required. */
          rc = vdbeCommit(db, p);
        }
        if( rc==SQLITE_BUSY && p->readOnly ){
          sqlite3VdbeLeave(p);
          return SQLITE_BUSY;
        }else if( rc!=SQLITE_OK ){
          p->rc = rc;
          sqlite3RollbackAll(db, SQLITE_OK);
        }else{
          db->nDeferredCons = 0;
          db->nDeferredImmCons = 0;
          db->flags &= ~SQLITE_DeferFKs;
          sqlite3CommitInternalChanges(db);
        }
      }else{
        sqlite3RollbackAll(db, SQLITE_OK);
      }
      db->nStatement = 0;
    }else if( eStatementOp==0 ){
      if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
        eStatementOp = SAVEPOINT_RELEASE;
      }else if( p->errorAction==OE_Abort ){
        eStatementOp = SAVEPOINT_ROLLBACK;
      }else{
        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
        sqlite3CloseSavepoints(db);
        db->autoCommit = 1;
      }
    }
  
    /* If eStatementOp is non-zero, then a statement transaction needs to
    ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
    ** do so. If this operation returns an error, and the current statement
    ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
    ** current statement error code.
    */
    if( eStatementOp ){
      rc = sqlite3VdbeCloseStatement(p, eStatementOp);
      if( rc ){
        if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){
          p->rc = rc;
          sqlite3DbFree(db, p->zErrMsg);
          p->zErrMsg = 0;
        }
        sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
        sqlite3CloseSavepoints(db);
        db->autoCommit = 1;
      }
    }
  
    /* If this was an INSERT, UPDATE or DELETE and no statement transaction
    ** has been rolled back, update the database connection change-counter. 
    */
    if( p->changeCntOn ){
      if( eStatementOp!=SAVEPOINT_ROLLBACK ){
        sqlite3VdbeSetChanges(db, p->nChange);
      }else{
        sqlite3VdbeSetChanges(db, 0);
      }
      p->nChange = 0;
    }

    /* Release the locks */
    sqlite3VdbeLeave(p);
  }

  /* We have successfully halted and closed the VM.  Record this fact. */
  if( p->pc>=0 ){
    db->nVdbeActive--;
    if( !p->readOnly ) db->nVdbeWrite--;
    if( p->bIsReader ) db->nVdbeRead--;
    assert( db->nVdbeActive>=db->nVdbeRead );
    assert( db->nVdbeRead>=db->nVdbeWrite );
    assert( db->nVdbeWrite>=0 );
  }
  p->magic = VDBE_MAGIC_HALT;
  checkActiveVdbeCnt(db);
  if( p->db->mallocFailed ){
    p->rc = SQLITE_NOMEM;
  }

  /* If the auto-commit flag is set to true, then any locks that were held
  ** by connection db have now been released. Call sqlite3ConnectionUnlocked() 
  ** to invoke any required unlock-notify callbacks.
  */
  if( db->autoCommit ){
    sqlite3ConnectionUnlocked(db);
  }

  assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
  return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x50(%rax)
je 0x2e852
movq -0x10(%rbp), %rax
movl $0x7, 0x94(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x118(%rax)
je 0x2e87d
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x110(%rax), %rdx
xorl %esi, %esi
callq 0x8200
movq -0x10(%rbp), %rdi
callq 0x2ee50
movq -0x10(%rbp), %rax
cmpl $0xbdf20da3, 0x50(%rax) # imm = 0xBDF20DA3
je 0x2e89f
movl $0x0, -0x4(%rbp)
jmp 0x2ed49
movq -0x10(%rbp), %rax
cmpl $0x0, 0x90(%rax)
jl 0x2ec7f
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x9, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2ec7f
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x94(%rax), %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movb $0x1, %al
cmpl $0x7, -0x24(%rbp)
movb %al, -0x2d(%rbp)
je 0x2e913
movb $0x1, %al
cmpl $0xa, -0x24(%rbp)
movb %al, -0x2d(%rbp)
je 0x2e913
movb $0x1, %al
cmpl $0x9, -0x24(%rbp)
movb %al, -0x2d(%rbp)
je 0x2e913
cmpl $0xd, -0x24(%rbp)
sete %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x2e998
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x8, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2e945
cmpl $0x9, -0x24(%rbp)
je 0x2e996
cmpl $0x7, -0x24(%rbp)
je 0x2e951
cmpl $0xd, -0x24(%rbp)
jne 0x2e975
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x7, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2e975
movl $0x2, -0x28(%rbp)
jmp 0x2e994
movq -0x20(%rbp), %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x2efa0
movq -0x20(%rbp), %rdi
callq 0x2f0d0
movq -0x20(%rbp), %rax
movb $0x1, 0x4e(%rax)
jmp 0x2e996
jmp 0x2e998
movq -0x10(%rbp), %rax
cmpl $0x0, 0x94(%rax)
jne 0x2e9b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2f150
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
jle 0x2e9cf
movq -0x20(%rbp), %rax
cmpq $0x0, 0x1c8(%rax)
je 0x2eb39
movq -0x20(%rbp), %rax
movzbl 0x4e(%rax), %eax
cmpl $0x0, %eax
je 0x2eb39
movq -0x20(%rbp), %rax
movl 0xa4(%rax), %eax
movq -0x10(%rbp), %rcx
movw 0x9a(%rcx), %cx
shrw $0x8, %cx
andw $0x1, %cx
movzwl %cx, %ecx
cmpl $0x0, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x2eb39
movq -0x10(%rbp), %rax
cmpl $0x0, 0x94(%rax)
je 0x2ea3f
movq -0x10(%rbp), %rax
movzbl 0x98(%rax), %eax
cmpl $0x3, %eax
jne 0x2eb1e
cmpl $0x0, -0x2c(%rbp)
jne 0x2eb1e
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2f150
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x2ea86
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x8, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2ea7d
movl $0x1, -0x4(%rbp)
jmp 0x2ed49
movl $0x313, -0x14(%rbp)     # imm = 0x313
jmp 0x2ea96
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2f1f0
movl %eax, -0x14(%rbp)
cmpl $0x5, -0x14(%rbp)
jne 0x2eac3
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x8, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2eac3
movl $0x5, -0x4(%rbp)
jmp 0x2ed49
cmpl $0x0, -0x14(%rbp)
je 0x2eae3
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x94(%rax)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x2efa0
jmp 0x2eb1a
movq -0x20(%rbp), %rax
movq $0x0, 0x318(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x320(%rax)
movq -0x20(%rbp), %rax
movl 0x2c(%rax), %ecx
andl $0xfeffffff, %ecx       # imm = 0xFEFFFFFF
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rdi
callq 0x2f8e0
jmp 0x2eb1c
jmp 0x2eb29
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x2efa0
movq -0x20(%rbp), %rax
movl $0x0, 0x310(%rax)
jmp 0x2eba3
cmpl $0x0, -0x28(%rbp)
jne 0x2eba1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x94(%rax)
je 0x2eb5c
movq -0x10(%rbp), %rax
movzbl 0x98(%rax), %eax
cmpl $0x3, %eax
jne 0x2eb65
movl $0x1, -0x28(%rbp)
jmp 0x2eb9f
movq -0x10(%rbp), %rax
movzbl 0x98(%rax), %eax
cmpl $0x2, %eax
jne 0x2eb7e
movl $0x2, -0x28(%rbp)
jmp 0x2eb9d
movq -0x20(%rbp), %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x2efa0
movq -0x20(%rbp), %rdi
callq 0x2f0d0
movq -0x20(%rbp), %rax
movb $0x1, 0x4e(%rax)
jmp 0x2eb9f
jmp 0x2eba1
jmp 0x2eba3
cmpl $0x0, -0x28(%rbp)
je 0x2ec2e
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x2f900
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x2ec2c
movq -0x10(%rbp), %rax
cmpl $0x0, 0x94(%rax)
je 0x2ebe3
movq -0x10(%rbp), %rax
movl 0x94(%rax), %eax
andl $0xff, %eax
cmpl $0x13, %eax
jne 0x2ec0d
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x94(%rax)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x9cd0
movq -0x10(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x20(%rbp), %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x2efa0
movq -0x20(%rbp), %rdi
callq 0x2f0d0
movq -0x20(%rbp), %rax
movb $0x1, 0x4e(%rax)
jmp 0x2ec2e
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x4, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2ec7d
cmpl $0x2, -0x28(%rbp)
je 0x2ec64
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x9c(%rax), %esi
callq 0x2fa80
jmp 0x2ec6f
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x2fa80
movq -0x10(%rbp), %rax
movl $0x0, 0x9c(%rax)
jmp 0x2ec7f
movq -0x10(%rbp), %rax
cmpl $0x0, 0x90(%rax)
jl 0x2ecfd
movq -0x20(%rbp), %rax
movl 0x9c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x9c(%rax)
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x8, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x2eccd
movq -0x20(%rbp), %rax
movl 0xa4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0xa4(%rax)
movq -0x10(%rbp), %rax
movw 0x9a(%rax), %ax
shrw $0x9, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2ecfb
movq -0x20(%rbp), %rax
movl 0xa0(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0xa0(%rax)
jmp 0x2ecfd
movq -0x10(%rbp), %rax
movl $0x519c2973, 0x50(%rax) # imm = 0x519C2973
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x50(%rax)
je 0x2ed23
movq -0x10(%rbp), %rax
movl $0x7, 0x94(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x4e(%rax)
je 0x2ed2f
jmp 0x2ed2f
movq -0x10(%rbp), %rax
movl 0x94(%rax), %edx
xorl %eax, %eax
movl $0x5, %ecx
cmpl $0x5, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)