// File: /workspace/github_c_makefile_star2_O3/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), %rsi
movl 0x310(%rsi), %ecx
xorl %r13d, %r13d
testl %ecx, %ecx
je 0x23c63
movq %rdi, %r14
movl 0xa8(%rdi), %edx
testl %edx, %edx
je 0x23c63
decl %edx
movl 0x28(%rsi), %eax
testl %eax, %eax
movl %edx, %ebx
movq %rsi, -0x38(%rbp)
jle 0x23bf6
movq %r14, -0x40(%rbp)
xorl %r15d, %r15d
movl $0x8, %r12d
xorl %r13d, %r13d
movq 0x20(%rsi), %rcx
movq (%rcx,%r12), %r14
testq %r14, %r14
je 0x23bcb
cmpl $0x2, -0x2c(%rbp)
jne 0x23bac
movq %r14, %rdi
movl $0x2, %esi
movl %ebx, %edx
callq 0x242a8
movl %ebx, %edx
testl %eax, %eax
jne 0x23bbd
movq %r14, %rdi
movl $0x1, %esi
movl %ebx, %edx
callq 0x242a8
movl %ebx, %edx
testl %r13d, %r13d
cmovel %eax, %r13d
movq -0x38(%rbp), %rsi
movl 0x28(%rsi), %eax
incq %r15
movslq %eax, %rcx
addq $0x20, %r12
cmpq %rcx, %r15
jl 0x23b84
decl 0x310(%rsi)
movq -0x40(%rbp), %r14
movl $0x0, 0xa8(%r14)
testl %r13d, %r13d
jne 0x23c41
jmp 0x23c09
decl %ecx
movl %ecx, 0x310(%rsi)
movl $0x0, 0xa8(%r14)
cmpl $0x2, -0x2c(%rbp)
jne 0x23c2c
movq -0x38(%rbp), %rdi
movl $0x2, %esi
movl %ebx, %edx
callq 0x24305
movq -0x38(%rbp), %rsi
movl %ebx, %edx
movl %eax, %r13d
testl %eax, %eax
jne 0x23c47
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x24305
movq -0x38(%rbp), %rsi
movl %eax, %r13d
cmpl $0x2, -0x2c(%rbp)
jne 0x23c63
movq 0xd0(%r14), %rax
movq %rax, 0x318(%rsi)
movq 0xd8(%r14), %rax
movq %rax, 0x320(%rsi)
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq