// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pageFindSlot
static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
  const int hdr = pPg->hdrOffset;            /* Offset to page header */
  u8 * const aData = pPg->aData;             /* Page data */
  int iAddr = hdr + 1;                       /* Address of ptr to pc */
  int pc = get2byte(&aData[iAddr]);          /* Address of a free slot */
  int x;                                     /* Excess size of the slot */
  int maxPC = pPg->pBt->usableSize - nByte;  /* Max address for a usable slot */
  int size;                                  /* Size of the free slot */

  assert( pc>0 );
  while( pc<=maxPC ){
    /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
    ** freeblock form a big-endian integer which is the size of the freeblock
    ** in bytes, including the 4-byte header. */
    size = get2byte(&aData[pc+2]);
    if( (x = size - nByte)>=0 ){
      testcase( x==4 );
      testcase( x==3 );
      if( x<4 ){
        /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
        ** number of bytes in fragments may not exceed 60. */
        if( aData[hdr+7]>57 ) return 0;

        /* Remove the slot from the free-list. Update the number of
        ** fragmented bytes within the page. */
        memcpy(&aData[iAddr], &aData[pc], 2);
        aData[hdr+7] += (u8)x;
      }else if( x+pc > maxPC ){
        /* This slot extends off the end of the usable part of the page */
        *pRc = SQLITE_CORRUPT_PAGE(pPg);
        return 0;
      }else{
        /* The slot remains on the free-list. Reduce its size to account
        ** for the portion used by the new allocation. */
        put2byte(&aData[pc+2], x);
      }
      return &aData[pc + x];
    }
    iAddr = pc;
    pc = get2byte(&aData[pc]);
    if( pc<=iAddr+size ){
      if( pc ){
        /* The next slot in the chain is not past the end of the current slot */
        *pRc = SQLITE_CORRUPT_PAGE(pPg);
      }
      return 0;
    }
  }
  if( pc>maxPC+nByte-4 ){
    /* The free slot chain extends off the end of the page */
    *pRc = SQLITE_CORRUPT_PAGE(pPg);
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x38(%rax), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x404eeb
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movl -0x38(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jl 0x404e90
cmpl $0x4, -0x3c(%rbp)
jge 0x404e1d
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jle 0x404de7
movq $0x0, -0x8(%rbp)
jmp 0x404f15
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq -0x30(%rbp), %rdx
movslq -0x38(%rbp), %rsi
movw (%rdx,%rsi), %dx
movw %dx, (%rax,%rcx)
movl -0x3c(%rbp), %eax
movzbl %al, %esi
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x404e77
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x404e47
movl $0x10208, %edi          # imm = 0x10208
callq 0x3dff80
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x404f15
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
jmp 0x404e77
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x404f15
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
addl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jg 0x404ee6
cmpl $0x0, -0x38(%rbp)
je 0x404edc
movl $0x10216, %edi          # imm = 0x10216
callq 0x3dff80
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x404f15
jmp 0x404d75
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
addl -0x14(%rbp), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
jle 0x404f0d
movl $0x1021d, %edi          # imm = 0x1021D
callq 0x3dff80
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop