// File: /workspace/github_c_makefile_star2_O2/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
pushq %rbx
pushq %rax
movq %rdx, %rbx
movzbl 0x9(%rdi), %edx
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rax
leaq 0x1(%rdx), %r8
movzwl 0x1(%rax,%rdx), %edi
rolw $0x8, %di
movzwl %di, %r10d
movl 0x38(%rcx), %r9d
movl %r9d, %edi
subl %esi, %edi
movl %r10d, %ecx
cmpl %edi, %r10d
jg 0x248c0a
movl %ecx, %r10d
movzwl 0x2(%rax,%r10), %r11d
rolw $0x8, %r11w
movzwl %r11w, %ebp
movl %ebp, %r11d
subl %esi, %r11d
jns 0x248c1a
movzwl (%rax,%r10), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r10d
addl %ecx, %ebp
movl %ecx, %r8d
cmpl %ebp, %r10d
ja 0x248bc4
testl %r10d, %r10d
je 0x248c50
movl $0x10216, %edi          # imm = 0x10216
jmp 0x248c49
addl $-0x4, %r9d
cmpl %r9d, %ecx
jle 0x248c50
movl $0x1021d, %edi          # imm = 0x1021D
jmp 0x248c49
cmpl $0x3, %r11d
ja 0x248c3d
cmpb $0x39, 0x7(%rax,%rdx)
ja 0x248c50
movl %r8d, %esi
movzwl (%rax,%r10), %edi
movw %di, (%rax,%rsi)
addb %r11b, 0x7(%rax,%rdx)
addl %r11d, %ecx
jmp 0x248c64
addl %r11d, %ecx
cmpl %edi, %ecx
jbe 0x248c59
movl $0x10208, %edi          # imm = 0x10208
callq 0x232547
movl %eax, (%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
rolw $0x8, %r11w
movw %r11w, 0x2(%rax,%r10)
movl %ecx, %ecx
addq %rcx, %rax
jmp 0x248c52