// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
xorl %esi, %esi
callq 0x27bc77
movl %eax, %ecx
movl $0x5, %eax
testl %ecx, %ecx
jg 0x289066
movslq %r15d, %r13
movslq %ebp, %r15
cmpb $0x0, 0x178(%rbx)
je 0x288ebc
movq 0x1b8(%rbx), %rdi
callq 0x27c490
movq %r15, %r12
imulq %r13, %r12
andl $-0x8, %r13d
xorl %esi, %esi
cmpl $0x9, %r13d
cmovll %esi, %r13d
setl %al
testl %r15d, %r15d
setle %cl
orb %al, %cl
je 0x288ee3
xorl %r15d, %r15d
jmp 0x288f30
testq %r14, %r14
je 0x288ef0
movl %r13d, %esi
movq %r14, %r15
jmp 0x288f30
movq 0x240f51(%rip), %rax    # 0x4c9e48
testq %rax, %rax
je 0x288efe
callq *%rax
movq %r12, %rdi
callq 0x27c381
movq %rax, %r15
movq 0x240f40(%rip), %rax    # 0x4c9e50
testq %rax, %rax
je 0x288f17
callq *%rax
testq %r15, %r15
je 0x288f2a
movq %r15, %rdi
callq *0x23d773(%rip)         # 0x4c6698
movslq %eax, %r12
jmp 0x288f2d
xorl %r15d, %r15d
movl %r13d, %esi
cmpl $0x180, %esi            # imm = 0x180
jl 0x288f40
leal 0x180(%rsi), %ecx
jmp 0x288f52
cmpl $0x100, %esi            # imm = 0x100
jl 0x289075
leal 0x80(%rsi), %ecx
movq %r12, %rax
cqto
idivq %rcx
movl %esi, %ecx
imull %eax, %ecx
movslq %ecx, %rcx
movq %r12, %rdx
subq %rcx, %rdx
negq %rcx
addq %r12, %rcx
addq $0x7f, %rcx
testq %rdx, %rdx
cmovnsq %rdx, %rcx
shrq $0x7, %rcx
movq %r15, 0x1b8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x190(%rbx)
movw %si, 0x174(%rbx)
movw %si, 0x176(%rbx)
testq %r15, %r15
je 0x289026
testl %eax, %eax
jle 0x288fce
leaq 0x190(%rbx), %rdx
movslq %esi, %rsi
movq (%rdx), %r8
movl %eax, %edi
movq %r8, (%r15)
movq %r15, %r8
addq %rsi, %r15
decl %edi
jne 0x288fb8
movq %r15, %rdi
subq %rsi, %rdi
movq %rdi, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1a0(%rbx)
movq %r15, 0x1b0(%rbx)
testl %ecx, %ecx
jle 0x289007
leaq 0x1a0(%rbx), %rdx
movq (%rdx), %rdi
movl %ecx, %esi
movq %rdi, (%r15)
movq %r15, %rdi
addq $0x80, %r15
decl %esi
jne 0x288fef
leaq -0x80(%r15), %rsi
movq %rsi, (%rdx)
movq %r15, 0x1c0(%rbx)
movl $0x0, 0x170(%rbx)
testq %r14, %r14
sete 0x178(%rbx)
addl %eax, %ecx
jmp 0x28905e
movq %rbx, 0x1b8(%rbx)
movups %xmm0, 0x1a0(%rbx)
movq %rbx, 0x1b0(%rbx)
movq %rbx, 0x1c0(%rbx)
movl $0x1, 0x170(%rbx)
movw $0x0, 0x174(%rbx)
movb $0x0, 0x178(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x17c(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
testl %esi, %esi
jle 0x28908a
movl %esi, %edi
movq %r12, %rax
cqto
idivq %rdi
jmp 0x288f7d
xorl %eax, %eax
jmp 0x288f7d