// File: /workspace/github_c_makefile_star2_O1/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: pageFindSlot
static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
  const int hdr = pPg->hdrOffset;
  u8 * const aData = pPg->aData;
  int iAddr = hdr + 1;
  int pc = get2byte(&aData[iAddr]);
  int x;
  int usableSize = pPg->pBt->usableSize;

  assert( pc>0 );
  do{
    int size;            /* Size of the free slot */
    /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
    ** increasing offset. */
    if( pc>usableSize-4 || pc<iAddr+4 ){
      *pRc = SQLITE_CORRUPT_BKPT;
      return 0;
    }
    /* 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( pc < pPg->cellOffset+2*pPg->nCell || size+pc > usableSize ){
        *pRc = SQLITE_CORRUPT_BKPT;
        return 0;
      }else 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{
        /* 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]);
  }while( pc );

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
movzbl 0x6(%rdi), %ecx
movq 0x48(%rdi), %rax
movq %rdi, -0x50(%rbp)
movq 0x50(%rdi), %r13
leaq 0x1(%rcx), %rbx
movq %rcx, -0x40(%rbp)
movzwl 0x1(%r13,%rcx), %ecx
rolw $0x8, %cx
movzwl %cx, %r15d
movl 0x34(%rax), %eax
movq %rax, -0x48(%rbp)
leal -0x4(%rax), %r14d
cmpl %r14d, %r15d
jg 0x3aaf2
leal 0x4(%rbx), %eax
cmpl %eax, %r15d
jl 0x3aaf2
movl %r15d, %ecx
movzwl 0x2(%r13,%rcx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
movl %edx, %eax
subl -0x2c(%rbp), %eax
js 0x3ab08
movq -0x50(%rbp), %rdi
movzwl 0xe(%rdi), %esi
movzwl 0x12(%rdi), %edi
leal (%rsi,%rdi,2), %esi
cmpl %esi, %r15d
jl 0x3ab1c
addl %r15d, %edx
cmpl -0x48(%rbp), %edx
jg 0x3ab1c
cmpl $0x3, %eax
jg 0x3ab5e
movq -0x40(%rbp), %rsi
cmpb $0x39, 0x7(%r13,%rsi)
jbe 0x3ab6c
xorl %r12d, %r12d
jmp 0x3ab48
xorl %r12d, %r12d
movl $0xb, %edi
leaq 0x429d7(%rip), %rsi     # 0x7d4d8
movl $0xdce9, %edx           # imm = 0xDCE9
jmp 0x3ab30
movzwl (%r13,%rcx), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
movb $0x1, %dl
movl %r15d, %ebx
jmp 0x3ab4d
xorl %r12d, %r12d
movl $0xb, %edi
leaq 0x429ad(%rip), %rsi     # 0x7d4d8
movl $0xdcf4, %edx           # imm = 0xDCF4
leaq 0x42646(%rip), %rcx     # 0x7d17d
xorl %eax, %eax
callq 0xa4b0
movq -0x38(%rbp), %rax
movl $0xb, (%rax)
movl %r15d, %ecx
xorl %edx, %edx
testb %dl, %dl
je 0x3ab92
movl %ecx, %r15d
testl %ecx, %ecx
jne 0x3aa9c
jmp 0x3ab8f
movl %eax, %edx
rolw $0x8, %dx
movw %dx, 0x2(%r13,%rcx)
jmp 0x3ab7f
movl %ebx, %edx
movzwl (%r13,%rcx), %ecx
movw %cx, (%r13,%rdx)
addb %al, 0x7(%r13,%rsi)
addl %r15d, %eax
addq %r13, %rax
xorl %edx, %edx
movl %r15d, %ecx
movq %rax, %r12
jmp 0x3ab4d
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq