// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: setupLookaside
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
#ifndef SQLITE_OMIT_LOOKASIDE
  void *pStart;
  sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
  int nBig;   /* Number of full-size slots */
  int nSm;    /* Number smaller LOOKASIDE_SMALL-byte slots */

  if( sqlite3LookasideUsed(db,0)>0 ){
    return SQLITE_BUSY;
  }
  /* Free any existing lookaside buffer for this handle before
  ** allocating a new one so we don't have to have space for
  ** both at the same time.
  */
  if( db->lookaside.bMalloced ){
    sqlite3_free(db->lookaside.pStart);
  }
  /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
  ** than a pointer to be useful.
  */
  sz = ROUNDDOWN8(sz);  /* IMP: R-33038-09382 */
  if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
  if( cnt<0 ) cnt = 0;
  if( sz==0 || cnt==0 ){
    sz = 0;
    pStart = 0;
  }else if( pBuf==0 ){
    sqlite3BeginBenignMalloc();
    pStart = sqlite3Malloc( szAlloc );  /* IMP: R-61949-35727 */
    sqlite3EndBenignMalloc();
    if( pStart ) szAlloc = sqlite3MallocSize(pStart);
  }else{
    pStart = pBuf;
  }
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
  if( sz>=LOOKASIDE_SMALL*3 ){
    nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
    nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
  }else if( sz>=LOOKASIDE_SMALL*2 ){
    nBig = szAlloc/(LOOKASIDE_SMALL+sz);
    nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
  }else
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
  if( sz>0 ){
    nBig = szAlloc/sz;
    nSm = 0;
  }else{
    nBig = nSm = 0;
  }
  db->lookaside.pStart = pStart;
  db->lookaside.pInit = 0;
  db->lookaside.pFree = 0;
  db->lookaside.sz = (u16)sz;
  db->lookaside.szTrue = (u16)sz;
  if( pStart ){
    int i;
    LookasideSlot *p;
    assert( sz > (int)sizeof(LookasideSlot*) );
    p = (LookasideSlot*)pStart;
    for(i=0; i<nBig; i++){
      p->pNext = db->lookaside.pInit;
      db->lookaside.pInit = p;
      p = (LookasideSlot*)&((u8*)p)[sz];
    }
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
    db->lookaside.pSmallInit = 0;
    db->lookaside.pSmallFree = 0;
    db->lookaside.pMiddle = p;
    for(i=0; i<nSm; i++){
      p->pNext = db->lookaside.pSmallInit;
      db->lookaside.pSmallInit = p;
      p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL];
    }
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
    assert( ((uptr)p)<=szAlloc + (uptr)pStart );
    db->lookaside.pEnd = p;
    db->lookaside.bDisable = 0;
    db->lookaside.bMalloced = pBuf==0 ?1:0;
    db->lookaside.nSlot = nBig+nSm;
  }else{
    db->lookaside.pStart = db;
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
    db->lookaside.pSmallInit = 0;
    db->lookaside.pSmallFree = 0;
    db->lookaside.pMiddle = db;
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
    db->lookaside.pEnd = db;
    db->lookaside.bDisable = 1;
    db->lookaside.sz = 0;
    db->lookaside.bMalloced = 0;
    db->lookaside.nSlot = 0;
  }
  assert( sqlite3LookasideUsed(db,0)==0 );
#endif /* SQLITE_OMIT_LOOKASIDE */
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r12d
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %rbx
xorl %esi, %esi
callq 0x21f06e
testl %eax, %eax
jle 0x22a3c4
pushq $0x5
popq %rax
jmp 0x22a5ac
cmpb $0x0, 0x178(%rbx)
je 0x22a3d9
movq 0x1b8(%rbx), %rdi
callq 0x21f7f9
movl %ebp, %r15d
andl $-0x8, %r15d
xorl %r8d, %r8d
cmpl $0x9, %r15d
movl %r15d, %r14d
cmovll %r8d, %r14d
setl %al
testl %r12d, %r12d
setle %cl
orb %al, %cl
je 0x22a408
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ecx, %ecx
jmp 0x22a4bc
movslq %ebp, %rax
movq %r13, %rcx
movslq %r12d, %r13
imulq %rax, %r13
testq %rcx, %rcx
movq %rcx, (%rsp)
je 0x22a423
movq %rcx, %r12
jmp 0x22a463
movq 0x2139ce(%rip), %rax    # 0x43ddf8
testq %rax, %rax
je 0x22a431
callq *%rax
movq %r13, %rdi
callq 0x21f6df
movq %rax, %r12
movq 0x2139bd(%rip), %rax    # 0x43de00
testq %rax, %rax
je 0x22a44a
callq *%rax
testq %r12, %r12
je 0x22a45d
movq %r12, %rdi
callq *0x2101f0(%rip)         # 0x43a648
movslq %eax, %r13
jmp 0x22a460
xorl %r12d, %r12d
xorl %r8d, %r8d
cmpl $0x180, %ebp            # imm = 0x180
jb 0x22a474
leal 0x180(%r15), %ecx
jmp 0x22a483
cmpl $0x100, %ebp            # imm = 0x100
jb 0x22a4aa
leal 0x80(%r15), %ecx
movq %r13, %rax
cqto
idivq %rcx
movq %rax, %rcx
imull %ecx, %r15d
movslq %r15d, %rax
subq %rax, %r13
movl $0x80, %esi
movq %r13, %rax
cqto
idivq %rsi
movq %rax, %r8
jmp 0x22a4b8
movl %r15d, %ecx
movq %r13, %rax
cqto
idivq %rcx
movq %rax, %rcx
movq (%rsp), %r13
movq %r12, 0x1b8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x190(%rbx)
movw %r14w, 0x174(%rbx)
movw %r14w, 0x176(%rbx)
testq %r12, %r12
je 0x22a56b
leaq 0x190(%rbx), %rax
movl %r14d, %edx
xorl %edi, %edi
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
subl $0x1, %esi
jb 0x22a510
movq %rdi, (%r12)
movq %r12, (%rax)
movq %r12, %rdi
addq %rdx, %r12
jmp 0x22a4fc
leaq 0x1a0(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x1a0(%rbx)
movq %r12, 0x1b0(%rbx)
xorl %esi, %esi
testl %r8d, %r8d
movl $0x0, %edx
cmovgl %r8d, %edx
subl $0x1, %edx
jb 0x22a54e
movq %rsi, (%r12)
movq %r12, (%rax)
movq %r12, %rsi
addq $0x80, %r12
jmp 0x22a536
movq %r12, 0x1c0(%rbx)
andl $0x0, 0x170(%rbx)
testq %r13, %r13
sete 0x178(%rbx)
addl %ecx, %r8d
jmp 0x22a5a3
movq %rbx, 0x1b8(%rbx)
movups %xmm0, 0x1a0(%rbx)
movq %rbx, 0x1b0(%rbx)
movq %rbx, 0x1c0(%rbx)
movl $0x1, 0x170(%rbx)
andw $0x0, 0x174(%rbx)
movb $0x0, 0x178(%rbx)
xorl %r8d, %r8d
movl %r8d, 0x17c(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq