// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: setupLookaside
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
  void *pStart;
  if( db->lookaside.nOut ){
    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( sz*cnt );  /* IMP: R-61949-35727 */
    sqlite3EndBenignMalloc();
    if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
  }else{
    pStart = pBuf;
  }
  db->lookaside.pStart = pStart;
  db->lookaside.pFree = 0;
  db->lookaside.sz = (u16)sz;
  if( pStart ){
    int i;
    LookasideSlot *p;
    assert( sz > (int)sizeof(LookasideSlot*) );
    p = (LookasideSlot*)pStart;
    for(i=cnt-1; i>=0; i--){
      p->pNext = db->lookaside.pFree;
      db->lookaside.pFree = p;
      p = (LookasideSlot*)&((u8*)p)[sz];
    }
    db->lookaside.pEnd = p;
    db->lookaside.bEnabled = 1;
    db->lookaside.bMalloced = pBuf==0 ?1:0;
  }else{
    db->lookaside.pEnd = 0;
    db->lookaside.bEnabled = 0;
    db->lookaside.bMalloced = 0;
  }
  return SQLITE_OK;
}

// Assembly:
movl $0x5, %eax
cmpl $0x0, 0x154(%rdi)
je 0x14c1c
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movl %edx, %r13d
movq %rdi, %rbx
cmpb $0x0, 0x153(%rdi)
je 0x14c4e
movq 0x170(%rbx), %rdi
movq %rsi, %r14
callq 0xa2e8
movq %r14, %rsi
andl $-0x8, %r13d
xorl %eax, %eax
cmpl $0x9, %r13d
setl %cl
movl %r13d, %r14d
cmovll %eax, %r14d
testl %r15d, %r15d
cmovlel %eax, %r15d
setle %dl
orb %cl, %dl
je 0x14c75
xorl %r12d, %r12d
jmp 0x14cd2
testq %rsi, %rsi
je 0x14c82
movl %r14d, %eax
movq %rsi, %r12
jmp 0x14cd2
movq %rsi, -0x30(%rbp)
movq 0x812d3(%rip), %rax     # 0x95f60
testq %rax, %rax
je 0x14c94
callq *%rax
movl %r14d, %edi
imull %r15d, %edi
callq 0xa2a2
movq %rax, %r12
movq 0x812be(%rip), %rax     # 0x95f68
testq %rax, %rax
je 0x14cb1
callq *%rax
testq %r12, %r12
je 0x14cc8
movq %r12, %rdi
callq *0x7f779(%rip)          # 0x94438
cltd
idivl %r13d
movl %eax, %r15d
jmp 0x14ccb
xorl %r12d, %r12d
movl %r14d, %eax
movq -0x30(%rbp), %rsi
movq %r12, 0x170(%rbx)
movq $0x0, 0x168(%rbx)
movw %ax, 0x150(%rbx)
testq %r12, %r12
je 0x14d37
testl %r15d, %r15d
jle 0x14d21
cltq
movq 0x168(%rbx), %rcx
incl %r15d
movq %rcx, (%r12)
movq %r12, %rcx
addq %rax, %r12
decl %r15d
cmpl $0x1, %r15d
jg 0x14d01
movq %r12, %rcx
subq %rax, %rcx
movq %rcx, 0x168(%rbx)
movq %r12, 0x178(%rbx)
movb $0x1, 0x152(%rbx)
testq %rsi, %rsi
sete %al
jmp 0x14d4b
movq $0x0, 0x178(%rbx)
movb $0x0, 0x152(%rbx)
xorl %eax, %eax
movb %al, 0x153(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq