// File: /workspace/github_c_makefile_star2_O3/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), %ecx
movq 0x48(%rdi), %rax
movq 0x50(%rdi), %rbx
leaq 0x1(%rcx), %rdi
movzwl 0x1(%rbx,%rcx), %edx
rolw $0x8, %dx
movzwl %dx, %r9d
movl 0x38(%rax), %r8d
movl %r8d, %edx
subl %esi, %edx
movl %r9d, %eax
cmpl %edx, %r9d
jg 0x2a2e5a
movl %eax, %r9d
movzwl 0x2(%rbx,%r9), %r10d
rolw $0x8, %r10w
movzwl %r10w, %r11d
movl %r11d, %r10d
subl %esi, %r10d
jns 0x2a2e86
movzwl (%rbx,%r9), %edi
rolw $0x8, %di
movzwl %di, %r9d
addl %eax, %r11d
movl %eax, %edi
cmpl %r11d, %r9d
ja 0x2a2df9
testl %r9d, %r9d
je 0x2a2e93
leaq 0x132d8d(%rip), %rsi    # 0x3d5bcb
leaq 0x132e97(%rip), %rdx    # 0x3d5cdc
leaq 0x132be5(%rip), %r8     # 0x3d5a31
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x10216, %ecx          # imm = 0x10216
jmp 0x2a2ebf
addl $-0x4, %r8d
cmpl %r8d, %eax
jle 0x2a2e93
leaq 0x132d61(%rip), %rsi    # 0x3d5bcb
leaq 0x132e6b(%rip), %rdx    # 0x3d5cdc
leaq 0x132bb9(%rip), %r8     # 0x3d5a31
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x1021d, %ecx          # imm = 0x1021D
jmp 0x2a2ebf
cmpl $0x3, %r10d
ja 0x2a2e97
cmpb $0x39, 0x7(%rbx,%rcx)
jbe 0x2a2ecf
xorl %ebx, %ebx
jmp 0x2a2ef4
addl %r10d, %eax
cmpl %edx, %eax
jbe 0x2a2ee4
leaq 0x132d26(%rip), %rsi    # 0x3d5bcb
leaq 0x132e30(%rip), %rdx    # 0x3d5cdc
leaq 0x132b7e(%rip), %r8     # 0x3d5a31
xorl %ebx, %ebx
movl $0xb, %edi
movl $0x10208, %ecx          # imm = 0x10208
xorl %eax, %eax
callq 0x274d08
movl $0xb, (%r14)
jmp 0x2a2ef4
movl %edi, %edx
movzwl (%rbx,%r9), %esi
movw %si, (%rbx,%rdx)
addb %r10b, 0x7(%rbx,%rcx)
addl %r10d, %eax
jmp 0x2a2eef
rolw $0x8, %r10w
movw %r10w, 0x2(%rbx,%r9)
movl %eax, %eax
addq %rax, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq