// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3VdbeCloseStatement
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
  sqlite3 *const db = p->db;
  int rc = SQLITE_OK;

  /* If p->iStatement is greater than zero, then this Vdbe opened a 
  ** statement transaction that should be closed here. The only exception
  ** is that an IO error may have occurred, causing an emergency rollback.
  ** In this case (db->nStatement==0), and there is nothing to do.
  */
  if( db->nStatement && p->iStatement ){
    int i;
    const int iSavepoint = p->iStatement-1;

    assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
    assert( db->nStatement>0 );
    assert( p->iStatement==(db->nStatement+db->nSavepoint) );

    for(i=0; i<db->nDb; i++){ 
      int rc2 = SQLITE_OK;
      Btree *pBt = db->aDb[i].pBt;
      if( pBt ){
        if( eOp==SAVEPOINT_ROLLBACK ){
          rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
        }
        if( rc2==SQLITE_OK ){
          rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
        }
        if( rc==SQLITE_OK ){
          rc = rc2;
        }
      }
    }
    db->nStatement--;
    p->iStatement = 0;

    if( rc==SQLITE_OK ){
      if( eOp==SAVEPOINT_ROLLBACK ){
        rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
      }
      if( rc==SQLITE_OK ){
        rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
      }
    }

    /* If the statement transaction is being rolled back, also restore the 
    ** database handles deferred constraint counter to the value it had when 
    ** the statement transaction was opened.  */
    if( eOp==SAVEPOINT_ROLLBACK ){
      db->nDeferredCons = p->nStmtDefCons;
      db->nDeferredImmCons = p->nStmtDefImmCons;
    }
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, -0x30(%rbp)
movq (%rdi), %rbx
xorl %r13d, %r13d
cmpl $0x0, 0x310(%rbx)
je 0x2414e
movl 0xa8(%rdi), %edx
testl %edx, %edx
je 0x2414e
movq %rdi, -0x38(%rbp)
decl %edx
cmpl $0x0, 0x28(%rbx)
movl %edx, -0x2c(%rbp)
jle 0x240db
xorl %r15d, %r15d
movl $0x8, %r12d
xorl %r13d, %r13d
movq 0x20(%rbx), %rax
movq (%rax,%r12), %r14
testq %r14, %r14
je 0x240c9
xorl %eax, %eax
cmpl $0x2, -0x30(%rbp)
jne 0x240ab
movq %r14, %rdi
movl $0x2, %esi
movl -0x2c(%rbp), %edx
callq 0x24795
movl -0x2c(%rbp), %edx
testl %eax, %eax
jne 0x240c2
movq %r14, %rdi
movl $0x1, %esi
movl -0x2c(%rbp), %edx
callq 0x24795
movl -0x2c(%rbp), %edx
testl %r13d, %r13d
cmovel %eax, %r13d
incq %r15
movslq 0x28(%rbx), %rax
addq $0x20, %r12
cmpq %rax, %r15
jl 0x24083
jmp 0x240de
xorl %r13d, %r13d
decl 0x310(%rbx)
movq -0x38(%rbp), %r14
movl $0x0, 0xa8(%r14)
testl %r13d, %r13d
jne 0x2412c
xorl %r13d, %r13d
cmpl $0x2, -0x30(%rbp)
jne 0x24117
movq %rbx, %rdi
movl $0x2, %esi
movl -0x2c(%rbp), %edx
callq 0x247f2
movl -0x2c(%rbp), %edx
movl %eax, %r13d
testl %r13d, %r13d
jne 0x2412c
movq %rbx, %rdi
movl $0x1, %esi
callq 0x247f2
movl %eax, %r13d
cmpl $0x2, -0x30(%rbp)
jne 0x2414e
movq 0xd0(%r14), %rax
movq %rax, 0x318(%rbx)
movq 0xd8(%r14), %rax
movq %rax, 0x320(%rbx)
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq