// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movzbl 0x9(%rdi), %eax
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rbx
leaq 0x1(%rax), %rdi
movzwl 0x1(%rbx,%rax), %edx
rolw $0x8, %dx
movzwl %dx, %r9d
movl 0x38(%rcx), %r8d
movl %r8d, %edx
subl %esi, %edx
movl %r9d, %ecx
cmpl %edx, %r9d
jg 0x2ac9d1
movl %ecx, %r10d
movzwl 0x2(%rbx,%r10), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r11d
movl %r11d, %r9d
subl %esi, %r9d
jns 0x2ac9fd
movzwl (%rbx,%r10), %edi
rolw $0x8, %di
movzwl %di, %r9d
addl %ecx, %r11d
movl %ecx, %edi
cmpl %r11d, %r9d
jg 0x2ac970
testl %r9d, %r9d
je 0x2aca0a
leaq 0x13296a(%rip), %rsi    # 0x3df31f
leaq 0x132a74(%rip), %rdx    # 0x3df430
leaq 0x1327c2(%rip), %r8     # 0x3df185
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x10216, %ecx          # imm = 0x10216
jmp 0x2aca37
addl $-0x4, %r8d
cmpl %r8d, %ecx
jle 0x2aca0a
leaq 0x13293e(%rip), %rsi    # 0x3df31f
leaq 0x132a48(%rip), %rdx    # 0x3df430
leaq 0x132796(%rip), %r8     # 0x3df185
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x1021d, %ecx          # imm = 0x1021D
jmp 0x2aca37
cmpl $0x3, %r9d
jg 0x2aca0e
cmpb $0x39, 0x7(%rbx,%rax)
jbe 0x2aca47
xorl %ebx, %ebx
jmp 0x2aca6c
leal (%r9,%rcx), %eax
cmpl %edx, %eax
jle 0x2aca59
leaq 0x132902(%rip), %rsi    # 0x3df31f
leaq 0x132a0c(%rip), %rdx    # 0x3df430
leaq 0x13275a(%rip), %r8     # 0x3df185
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x10208, %ecx          # imm = 0x10208
xorl %eax, %eax
callq 0x27e637
movl $0xb, (%r14)
jmp 0x2aca6c
movl %edi, %edx
movzwl (%rbx,%r10), %esi
movw %si, (%rbx,%rdx)
addb %r9b, 0x7(%rbx,%rax)
jmp 0x2aca66
movl %r9d, %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbx,%r10)
addl %ecx, %r9d
addq %r9, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq