// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %r14
cmpb $0x0, 0x50(%r14)
je 0x22e80
movl $0x7, 0x94(%rbx)
movq 0x118(%rbx), %rdi
testq %rdi, %rdi
je 0x22e9a
movslq 0x110(%rbx), %rdx
xorl %esi, %esi
callq 0x8200
movq 0xf0(%rbx), %rax
testq %rax, %rax
je 0x22eb7
movq %rax, %rdi
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x22ea6
callq 0x23c75
movq $0x0, 0xf0(%rbx)
movl $0x0, 0x100(%rbx)
cmpq $0x0, 0x70(%rbx)
je 0x22f0c
movl 0x4c(%rbx), %eax
testl %eax, %eax
jle 0x22f0c
xorl %r15d, %r15d
movq 0x70(%rbx), %rcx
movq (%rcx,%r15,8), %rsi
testq %rsi, %rsi
je 0x22f01
movq %rbx, %rdi
callq 0x23cd3
movq 0x70(%rbx), %rax
movq $0x0, (%rax,%r15,8)
movl 0x4c(%rbx), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x22edd
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x22f7b
addq $0x38, %rdi
movl 0x30(%rbx), %esi
callq 0x22c33
jmp 0x22f7b
movq 0x8(%r15), %rax
movq %rax, 0xf8(%rbx)
movslq 0x54(%r15), %rsi
cmpl $0x0, 0x58(%r15)
jle 0x22f64
imulq $0x38, %rsi, %rax
leaq (%r15,%rax), %r12
addq $0x60, %r12
xorl %r13d, %r13d
movq (%r15), %rdi
movq (%r12,%r13,8), %rsi
callq 0x23cd3
incq %r13
movslq 0x58(%r15), %rax
cmpq %rax, %r13
jl 0x22f48
movl 0x54(%r15), %esi
leaq 0x60(%r15), %rdi
callq 0x22c33
movq (%r15), %rax
movq (%rax), %rdi
movq %r15, %rsi
callq 0x9ca4
movq 0xf8(%rbx), %r15
testq %r15, %r15
jne 0x22f23
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x23e3c
cmpl $0xbdf20da3, 0x50(%rbx) # imm = 0xBDF20DA3
jne 0x232c1
cmpl $0x0, 0x90(%rbx)
js 0x23292
movzwl 0x9a(%rbx), %ecx
btl $0x9, %ecx
jae 0x2325a
movl 0x94(%rbx), %eax
xorl %r12d, %r12d
movb $0x1, %r13b
cmpb $0xd, %al
ja 0x23034
movzbl %al, %edx
movl $0x2680, %esi           # imm = 0x2680
btl %edx, %esi
jae 0x23034
movl %ecx, %esi
shrl $0x8, %esi
cmpb $0x9, %al
sete %dil
testb %dil, %sil
jne 0x23029
cmpb $0xd, %al
je 0x22ffa
cmpl $0x7, %edx
jne 0x22ffe
testb %cl, %cl
js 0x23039
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x23372
movq %r14, %rdi
callq 0x234b1
movb $0x1, 0x4e(%r14)
movl 0x94(%rbx), %eax
xorl %r15d, %r15d
movb $0x1, %r12b
movb $0x1, %r13b
jmp 0x23045
movb $0x1, %r13b
xorl %r15d, %r15d
movb $0x1, %r12b
jmp 0x23079
xorl %r15d, %r15d
jmp 0x23045
movl $0x2, %r15d
movb $0x1, %r12b
xorl %r13d, %r13d
testl %eax, %eax
jne 0x23079
cmpq $0x0, 0xc8(%rbx)
jle 0x23079
movq (%rbx), %rsi
movl $0x313, 0x94(%rbx)      # imm = 0x313
movb $0x2, 0x98(%rbx)
leaq 0x58(%rbx), %rdi
leaq 0x56818(%rip), %rdx     # 0x7988a
xorl %eax, %eax
callq 0x24129
cmpl $0x0, 0x1a4(%r14)
jle 0x23091
cmpq $0x0, 0x1c8(%r14)
je 0x23124
cmpb $0x0, 0x4e(%r14)
je 0x23124
xorl %eax, %eax
testb $0x1, 0x9b(%rbx)
sete %al
cmpl %eax, 0xa4(%r14)
jne 0x23124
cmpl $0x0, 0x94(%rbx)
je 0x230cd
cmpb $0x3, 0x98(%rbx)
setne %al
orb %al, %r12b
jne 0x231ae
movq (%rbx), %rsi
movq 0x320(%rsi), %rax
addq 0x318(%rsi), %rax
jle 0x23178
movl $0x313, 0x94(%rbx)      # imm = 0x313
movb $0x2, 0x98(%rbx)
leaq 0x58(%rbx), %rdi
leaq 0x5678a(%rip), %rdx     # 0x7988a
xorl %eax, %eax
callq 0x24129
movl $0x1, %r12d
movl $0x313, %eax            # imm = 0x313
testb $0x1, 0x9b(%rbx)
je 0x231a8
jmp 0x232c1
testb %r13b, %r13b
je 0x231c3
movl $0x1, %r15d
cmpl $0x0, 0x94(%rbx)
je 0x231c8
movzbl 0x98(%rbx), %eax
cmpl $0x3, %eax
je 0x231c8
cmpl $0x2, %eax
jne 0x23159
movl $0x2, %r15d
jmp 0x231c8
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x23372
movq %r14, %rdi
callq 0x234b1
movb $0x1, 0x4e(%r14)
jmp 0x23239
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2354c
testl %eax, %eax
je 0x232d3
cmpl $0x5, %eax
jne 0x231a8
movl $0x5, %eax
testb $0x1, 0x9b(%rbx)
movl $0x5, %r12d
jne 0x232c1
movl %eax, 0x94(%rbx)
movq %r14, %rdi
xorl %esi, %esi
callq 0x23372
movl $0x0, 0x310(%r14)
testl %r15d, %r15d
je 0x23239
movq %rbx, %rdi
movl %r15d, %esi
callq 0x23b28
testl %eax, %eax
je 0x23220
movl 0x94(%rbx), %ecx
testl %ecx, %ecx
setne %dl
cmpb $0x13, %cl
setne %cl
testb %cl, %dl
jne 0x23206
movl %eax, 0x94(%rbx)
movq 0x58(%rbx), %rsi
movq %r14, %rdi
callq 0x9ca4
movq $0x0, 0x58(%rbx)
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x23372
movq %r14, %rdi
callq 0x234b1
movb $0x1, 0x4e(%r14)
testb $0x10, 0x9a(%rbx)
je 0x2325a
cmpl $0x2, %r15d
jne 0x23242
movl $0x0, 0x60(%r14)
jmp 0x23250
testb $0x10, 0x9a(%rbx)
je 0x2325a
movl 0x9c(%rbx), %eax
movl %eax, 0x60(%r14)
addl %eax, 0x64(%r14)
movl $0x0, 0x9c(%rbx)
cmpl $0x0, 0x90(%rbx)
js 0x23292
decl 0x9c(%r14)
movzwl 0x9a(%rbx), %eax
btl $0x8, %eax
jb 0x23285
decl 0xa4(%r14)
movzwl 0x9a(%rbx), %eax
btl $0x9, %eax
jae 0x23292
decl 0xa0(%r14)
movl $0x519c2973, 0x50(%rbx) # imm = 0x519C2973
movq (%rbx), %rax
cmpb $0x0, 0x50(%rax)
je 0x232b1
movl $0x7, 0x94(%rbx)
xorl %r12d, %r12d
jmp 0x232c1
xorl %eax, %eax
cmpl $0x5, 0x94(%rbx)
sete %al
leal (%rax,%rax,4), %r12d
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
movups %xmm0, 0x318(%r14)
andl $0xfefffffd, 0x2c(%r14) # imm = 0xFEFFFFFD
jmp 0x231b8