// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x154(%rax)
je 0x1832f
movl $0x5, -0x4(%rbp)
jmp 0x184c2
movq -0x10(%rbp), %rax
cmpb $0x0, 0x153(%rax)
je 0x1834c
movq -0x10(%rbp), %rax
movq 0x170(%rax), %rdi
callq 0xa420
movl -0x1c(%rbp), %eax
andl $-0x8, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jg 0x18362
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x1836f
movl $0x0, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1837b
cmpl $0x0, -0x20(%rbp)
jne 0x1838c
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
jmp 0x183d0
cmpq $0x0, -0x18(%rbp)
jne 0x183c6
callq 0x241b0
movl -0x1c(%rbp), %edi
imull -0x20(%rbp), %edi
callq 0xa3c0
movq %rax, -0x28(%rbp)
callq 0x24200
cmpq $0x0, -0x28(%rbp)
je 0x183c4
movq -0x28(%rbp), %rdi
callq 0x9990
cltd
idivl -0x1c(%rbp)
movl %eax, -0x20(%rbp)
jmp 0x183ce
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x183d0
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x170(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x168(%rax)
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x150(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x18496
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x1845c
movq -0x10(%rbp), %rax
movq 0x168(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x168(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1841b
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x178(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x152(%rax)
movq -0x18(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovel %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x153(%rax)
jmp 0x184bb
movq -0x10(%rbp), %rax
movq $0x0, 0x178(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x152(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x153(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)