// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walMerge
static void walMerge(
  const u32 *aContent,            /* Pages in wal - keys for the sort */
  ht_slot *aLeft,                 /* IN: Left hand input list */
  int nLeft,                      /* IN: Elements in array *paLeft */
  ht_slot **paRight,              /* IN/OUT: Right hand input list */
  int *pnRight,                   /* IN/OUT: Elements in *paRight */
  ht_slot *aTmp                   /* Temporary buffer */
){
  int iLeft = 0;                  /* Current index in aLeft */
  int iRight = 0;                 /* Current index in aRight */
  int iOut = 0;                   /* Current index in output buffer */
  int nRight = *pnRight;
  ht_slot *aRight = *paRight;

  assert( nLeft>0 && nRight>0 );
  while( iRight<nRight || iLeft<nLeft ){
    ht_slot logpage;
    Pgno dbpage;

    if( (iLeft<nLeft) 
     && (iRight>=nRight || aContent[aLeft[iLeft]]<aContent[aRight[iRight]])
    ){
      logpage = aLeft[iLeft++];
    }else{
      logpage = aRight[iRight++];
    }
    dbpage = aContent[logpage];

    aTmp[iOut++] = logpage;
    if( iLeft<nLeft && aContent[aLeft[iLeft]]==dbpage ) iLeft++;

    assert( iLeft>=nLeft || aContent[aLeft[iLeft]]>dbpage );
    assert( iRight>=nRight || aContent[aRight[iRight]]>dbpage );
  }

  *paRight = aLeft;
  *pnRight = iOut;
  memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %ecx
movb $0x1, %al
cmpl -0x40(%rbp), %ecx
movb %al, -0x51(%rbp)
jl 0x26501
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
setl %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x2650d
jmp 0x265d1
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x26561
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x26545
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq -0x48(%rbp), %rdx
movslq -0x38(%rbp), %rsi
movzwl (%rdx,%rsi,2), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x26561
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x4a(%rbp)
jmp 0x2657b
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x4a(%rbp)
movq -0x8(%rbp), %rax
movzwl -0x4a(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movw -0x4a(%rbp), %dx
movq -0x30(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x265cc
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x50(%rbp), %eax
jne 0x265cc
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x264e8
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
shlq %rdx
callq 0x82f0
addq $0x60, %rsp
popq %rbp
retq
nop