// File: /workspace/github_c_makefile_star2_O1/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 0x232e5
movl $0x7, 0x94(%rbx)
movq 0x118(%rbx), %rdi
testq %rdi, %rdi
je 0x232ff
movslq 0x110(%rbx), %rdx
xorl %esi, %esi
callq 0x8200
movq 0xf0(%rbx), %rax
testq %rax, %rax
je 0x2331c
movq %rax, %rdi
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x2330b
callq 0x24160
movq $0x0, 0xf0(%rbx)
movl $0x0, 0x100(%rbx)
cmpq $0x0, 0x70(%rbx)
je 0x2336e
cmpl $0x0, 0x4c(%rbx)
jle 0x2336e
xorl %r15d, %r15d
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x23362
movq %rbx, %rdi
callq 0x241be
movq 0x70(%rbx), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
movslq 0x4c(%rbx), %rax
cmpq %rax, %r15
jl 0x23341
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x233dd
addq $0x38, %rdi
movl 0x30(%rbx), %esi
callq 0x2309b
jmp 0x233dd
movq 0x8(%r15), %rax
movq %rax, 0xf8(%rbx)
cmpl $0x0, 0x58(%r15)
jle 0x233c2
movslq 0x54(%r15), %rax
imulq $0x38, %rax, %rax
leaq (%r15,%rax), %r12
addq $0x60, %r12
xorl %r13d, %r13d
movq (%r15), %rdi
movq (%r12,%r13,8), %rsi
callq 0x241be
incq %r13
movslq 0x58(%r15), %rax
cmpq %rax, %r13
jl 0x233aa
leaq 0x60(%r15), %rdi
movl 0x54(%r15), %esi
callq 0x2309b
movq (%r15), %rax
movq (%rax), %rdi
movq %r15, %rsi
callq 0x9c3a
movq 0xf8(%rbx), %r15
testq %r15, %r15
jne 0x23385
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x24325
cmpl $0xbdf20da3, 0x50(%rbx) # imm = 0xBDF20DA3
jne 0x23715
cmpl $0x0, 0x90(%rbx)
js 0x236bb
movzwl 0x9a(%rbx), %eax
btl $0x9, %eax
jae 0x236bb
movl 0x94(%rbx), %ecx
cmpb $0xe, %cl
setb %dl
movl $0x2680, %r12d          # imm = 0x2680
shrl %cl, %r12d
andb %dl, %r12b
xorl %r15d, %r15d
movb $0x1, %r13b
cmpb $0x1, %r12b
jne 0x23495
movl %ecx, %edx
andl $0xf, %edx
movl %eax, %esi
shrl $0x8, %esi
cmpl $0x9, %edx
sete %dl
testb %dl, %sil
jne 0x23495
cmpb $0xd, %cl
je 0x2346c
movzbl %cl, %ecx
cmpl $0x7, %ecx
jne 0x23470
testb %al, %al
js 0x2348c
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x237b9
movq %r14, %rdi
callq 0x238ef
movb $0x1, 0x4e(%r14)
jmp 0x23495
movl $0x2, %r15d
xorl %r13d, %r13d
cmpl $0x0, 0x94(%rbx)
jne 0x234ce
cmpq $0x0, 0xc8(%rbx)
jle 0x234ce
movq (%rbx), %rsi
movl $0x313, 0x94(%rbx)      # imm = 0x313
movb $0x2, 0x98(%rbx)
leaq 0x58(%rbx), %rdi
leaq 0x563c3(%rip), %rdx     # 0x7988a
xorl %eax, %eax
callq 0x24616
cmpl $0x0, 0x1a4(%r14)
jle 0x234e6
cmpq $0x0, 0x1c8(%r14)
je 0x23578
cmpb $0x0, 0x4e(%r14)
je 0x23578
xorl %eax, %eax
testb $0x1, 0x9b(%rbx)
sete %al
cmpl %eax, 0xa4(%r14)
jne 0x23578
cmpl $0x0, 0x94(%rbx)
je 0x23522
cmpb $0x3, 0x98(%rbx)
setne %al
orb %al, %r12b
jne 0x235fb
movq (%rbx), %rsi
movq 0x320(%rsi), %rax
addq 0x318(%rsi), %rax
jle 0x235d0
movl $0x313, 0x94(%rbx)      # imm = 0x313
movb $0x2, 0x98(%rbx)
leaq 0x58(%rbx), %rdi
leaq 0x56335(%rip), %rdx     # 0x7988a
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x24616
movl $0x1, %r12d
movl $0x313, %eax            # imm = 0x313
testb $0x1, 0x9b(%rbx)
je 0x235db
jmp 0x236b6
testb %r13b, %r13b
je 0x23625
movl $0x1, %r15d
cmpl $0x0, 0x94(%rbx)
je 0x23625
movzbl 0x98(%rbx), %eax
cmpl $0x3, %eax
je 0x23625
cmpl $0x2, %eax
jne 0x235b1
movl $0x2, %r15d
jmp 0x23625
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x237b9
movq %r14, %rdi
callq 0x238ef
movb $0x1, 0x4e(%r14)
xorl %r15d, %r15d
jmp 0x23625
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2398a
testl %eax, %eax
je 0x23607
cmpl $0x5, %eax
jne 0x235f5
testb $0x1, 0x9b(%rbx)
jne 0x23727
testl %eax, %eax
je 0x23607
movl %eax, 0x94(%rbx)
movq %r14, %rdi
xorl %esi, %esi
callq 0x237b9
jmp 0x2361a
xorps %xmm0, %xmm0
movups %xmm0, 0x318(%r14)
andl $0xfefffffd, 0x2c(%r14) # imm = 0xFEFFFFFD
movl $0x0, 0x310(%r14)
testl %r15d, %r15d
je 0x23682
movq %rbx, %rdi
movl %r15d, %esi
callq 0x24033
testl %eax, %eax
je 0x23682
movl 0x94(%rbx), %ecx
testl %ecx, %ecx
setne %dl
cmpb $0x13, %cl
setne %cl
testb %cl, %dl
jne 0x23668
movl %eax, 0x94(%rbx)
movq 0x58(%rbx), %rsi
movq %r14, %rdi
callq 0x9c3a
movq $0x0, 0x58(%rbx)
movq %r14, %rdi
movl $0x204, %esi            # imm = 0x204
callq 0x237b9
movq %r14, %rdi
callq 0x238ef
movb $0x1, 0x4e(%r14)
movb $0x1, %r13b
testb $0x10, 0x9a(%rbx)
je 0x236b6
cmpl $0x2, %r15d
jne 0x2369e
movl $0x0, 0x60(%r14)
jmp 0x236ac
movl 0x9c(%rbx), %eax
movl %eax, 0x60(%r14)
addl %eax, 0x64(%r14)
movl $0x0, 0x9c(%rbx)
testb %r13b, %r13b
je 0x23715
cmpl $0x0, 0x90(%rbx)
js 0x236eb
decl 0x9c(%r14)
testb $0x1, 0x9b(%rbx)
jne 0x236db
decl 0xa4(%r14)
testb $0x2, 0x9b(%rbx)
je 0x236eb
decl 0xa0(%r14)
movl $0x519c2973, 0x50(%rbx) # imm = 0x519C2973
movq (%rbx), %rax
cmpb $0x0, 0x50(%rax)
je 0x23705
movl $0x7, 0x94(%rbx)
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
movl $0x5, %r12d
xorl %r13d, %r13d
jmp 0x236b6