// File: /workspace/github_c_makefile_star2_O2/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, -0x2c(%rbp)
movq (%rdi), %rcx
xorl %r13d, %r13d
cmpl $0x0, 0x310(%rcx)
je 0x20902
movl 0xa8(%rdi), %edx
testl %edx, %edx
je 0x20902
movq %rdi, -0x40(%rbp)
decl %edx
xorl %r15d, %r15d
pushq $0x8
popq %r12
xorl %r13d, %r13d
movl %edx, %ebx
movq %rcx, -0x38(%rbp)
movslq 0x28(%rcx), %rax
cmpq %rax, %r15
jge 0x20897
movq 0x20(%rcx), %rax
movq (%rax,%r12), %r14
testq %r14, %r14
je 0x2088e
cmpl $0x2, -0x2c(%rbp)
jne 0x20874
movq %r14, %rdi
pushq $0x2
popq %rsi
movl %ebx, %edx
callq 0x20ed1
movl %ebx, %edx
testl %eax, %eax
jne 0x20883
movq %r14, %rdi
pushq $0x1
popq %rsi
movl %ebx, %edx
callq 0x20ed1
movl %ebx, %edx
testl %r13d, %r13d
cmovel %eax, %r13d
movq -0x38(%rbp), %rcx
incq %r15
addq $0x20, %r12
jmp 0x20845
decl 0x310(%rcx)
movq -0x40(%rbp), %r14
andl $0x0, 0xa8(%r14)
testl %r13d, %r13d
jne 0x208e0
cmpl $0x2, -0x2c(%rbp)
jne 0x208ce
pushq $0x2
popq %rsi
movq %rcx, %rdi
movl %ebx, %edx
callq 0x20f35
movq -0x38(%rbp), %rcx
movl %ebx, %edx
movl %eax, %r13d
testl %eax, %eax
jne 0x208e6
pushq $0x1
popq %rsi
movq %rcx, %rdi
callq 0x20f35
movq -0x38(%rbp), %rcx
movl %eax, %r13d
cmpl $0x2, -0x2c(%rbp)
jne 0x20902
movq 0xd0(%r14), %rax
movq %rax, 0x318(%rcx)
movq 0xd8(%r14), %rax
movq %rax, 0x320(%rcx)
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq