// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walMergesort
static void walMergesort(
  const u32 *aContent,            /* Pages in wal */
  ht_slot *aBuffer,               /* Buffer of at least *pnList items to use */
  ht_slot *aList,                 /* IN/OUT: List to sort */
  int *pnList                     /* IN/OUT: Number of elements in aList[] */
){
  struct Sublist {
    int nList;                    /* Number of elements in aList */
    ht_slot *aList;               /* Pointer to sub-list content */
  };

  const int nList = *pnList;      /* Size of input list */
  int nMerge = 0;                 /* Number of elements in list aMerge */
  ht_slot *aMerge = 0;            /* List to be merged */
  int iList;                      /* Index into input list */
  int iSub = 0;                   /* Index into aSub array */
  struct Sublist aSub[13];        /* Array of sub-lists */

  memset(aSub, 0, sizeof(aSub));
  assert( nList<=HASHTABLE_NPAGE && nList>0 );
  assert( HASHTABLE_NPAGE==(1<<(ArraySize(aSub)-1)) );

  for(iList=0; iList<nList; iList++){
    nMerge = 1;
    aMerge = &aList[iList];
    for(iSub=0; iList & (1<<iSub); iSub++){
      struct Sublist *p = &aSub[iSub];
      assert( p->aList && p->nList<=(1<<iSub) );
      assert( p->aList==&aList[iList&~((2<<iSub)-1)] );
      walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
    }
    aSub[iSub].aList = aMerge;
    aSub[iSub].nList = nMerge;
  }

  for(iSub++; iSub<ArraySize(aSub); iSub++){
    if( nList & (1<<iSub) ){
      struct Sublist *p = &aSub[iSub];
      assert( p->nList<=(1<<iSub) );
      assert( p->aList==&aList[nList&~((2<<iSub)-1)] );
      walMerge(aContent, p->aList, p->nList, &aMerge, &nMerge, aBuffer);
    }
  }
  assert( aMerge==aList );
  *pnList = nMerge;

#ifdef SQLITE_DEBUG
  {
    int i;
    for(i=1; i<*pnList; i++){
      assert( aContent[aList[i]] > aContent[aList[i-1]] );
    }
  }
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0xd0, %edx
callq 0x8200
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x26412
movl $0x1, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl -0x38(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x263d3
movslq -0x38(%rbp), %rcx
leaq -0x110(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x118(%rbp)
movq -0x8(%rbp), %rdi
movq -0x118(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x118(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %r9
leaq -0x30(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0x264a0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x26370
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
leaq -0x110(%rbp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x28(%rbp), %ecx
movslq -0x38(%rbp), %rdx
leaq -0x110(%rbp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x26344
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0xd, -0x38(%rbp)
jge 0x26486
movl -0x24(%rbp), %eax
movl -0x38(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x26479
movslq -0x38(%rbp), %rcx
leaq -0x110(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x120(%rbp)
movq -0x8(%rbp), %rdi
movq -0x120(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x120(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %r9
leaq -0x30(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0x264a0
jmp 0x2647b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2641b
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax,%rax)