// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
xorl %esi, %esi
callq 0x27234a
movl %eax, %ecx
movl $0x5, %eax
testl %ecx, %ecx
jg 0x27f49a
cmpb $0x0, 0x178(%rbx)
je 0x27f295
movq 0x1b8(%rbx), %rdi
callq 0x272c00
movl %ebp, %r13d
andl $-0x8, %r13d
xorl %r14d, %r14d
cmpl $0x9, %r13d
cmovgel %r13d, %r14d
setge %al
testl %r15d, %r15d
setg %cl
testb %cl, %al
jne 0x27f2cc
movw $0x0, 0x176(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x190(%rbx)
jmp 0x27f45a
movslq %ebp, %rax
movq %r12, %rcx
movslq %r15d, %r12
imulq %rax, %r12
testq %rcx, %rcx
movq %rcx, (%rsp)
je 0x27f2e7
movq %rcx, %r15
jmp 0x27f324
movq 0x23fb5a(%rip), %rax    # 0x4bee48
testq %rax, %rax
je 0x27f2f5
callq *%rax
movq %r12, %rdi
callq 0x272ae6
movq %rax, %r15
movq 0x23fb49(%rip), %rax    # 0x4bee50
testq %rax, %rax
je 0x27f30e
callq *%rax
testq %r15, %r15
je 0x27f321
movq %r15, %rdi
callq *0x23c37c(%rip)         # 0x4bb698
movslq %eax, %r12
jmp 0x27f324
xorl %r15d, %r15d
cmpl $0x180, %ebp            # imm = 0x180
jb 0x27f361
leal 0x180(%r13), %ecx
movq %r12, %rax
cqto
idivq %rcx
movl %r13d, %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
jmp 0x27f3ac
cmpl $0x100, %ebp            # imm = 0x100
jb 0x27f39c
leal 0x80(%r13), %ecx
movq %r12, %rax
cqto
idivq %rcx
imull %eax, %r13d
movslq %r13d, %rcx
movq %r12, %rdx
subq %rcx, %rdx
negq %rcx
addq %r12, %rcx
addq $0x7f, %rcx
testq %rdx, %rdx
cmovnsq %rdx, %rcx
shrq $0x7, %rcx
jmp 0x27f3a9
movl %r13d, %ecx
movq %r12, %rax
cqto
idivq %rcx
xorl %ecx, %ecx
movl %r14d, %r13d
movq %r15, 0x1b8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x190(%rbx)
movw %r13w, 0x174(%rbx)
movw %r13w, 0x176(%rbx)
testq %r15, %r15
movq (%rsp), %r9
je 0x27f45a
testl %eax, %eax
jle 0x27f403
leaq 0x190(%rbx), %rdx
movl %r13d, %esi
xorl %r8d, %r8d
movl %eax, %edi
movq %r8, (%r15)
movq %r15, %r8
addq %rsi, %r15
decl %edi
jne 0x27f3ed
movq %r15, %rdi
subq %rsi, %rdi
movq %rdi, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1a0(%rbx)
movq %r15, 0x1b0(%rbx)
testl %ecx, %ecx
jle 0x27f43b
leaq 0x1a0(%rbx), %rdx
xorl %edi, %edi
movl %ecx, %esi
movq %rdi, (%r15)
movq %r15, %rdi
addq $0x80, %r15
decl %esi
jne 0x27f423
leaq -0x80(%r15), %rsi
movq %rsi, (%rdx)
testq %r9, %r9
movq %r15, 0x1c0(%rbx)
movl $0x0, 0x170(%rbx)
sete 0x178(%rbx)
addl %eax, %ecx
jmp 0x27f492
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