// File: /workspace/github_c_makefile_star2_O1/ukontainer[P]sqlite-bench/sqlite3.c
// Function: windowPartitionCache
static void windowPartitionCache(
  Parse *pParse,
  Select *p,                      /* The rewritten SELECT statement */
  WhereInfo *pWInfo,              /* WhereInfo to call WhereEnd() on */
  int regFlushPart,               /* Register to use with Gosub lblFlushPart */
  int lblFlushPart,               /* Subroutine to Gosub to */
  int *pRegSize                   /* OUT: Register containing partition size */
){
  Window *pMWin = p->pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int iSubCsr = p->pSrc->a[0].iCursor;
  int nSub = p->pSrc->a[0].pTab->nCol;
  int k;

  int reg = pParse->nMem+1;
  int regRecord = reg+nSub;
  int regRowid = regRecord+1;

  *pRegSize = regRowid;
  pParse->nMem += nSub + 2;

  /* Load the column values for the row returned by the sub-select
  ** into an array of registers starting at reg. */
  for(k=0; k<nSub; k++){
    sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
  }
  sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, nSub, regRecord);

  /* Check if this is the start of a new partition. If so, call the
  ** flush_partition sub-routine.  */
  if( pMWin->pPartition ){
    int addr;
    ExprList *pPart = pMWin->pPartition;
    int nPart = pPart->nExpr;
    int regNewPart = reg + pMWin->nBufferCol;
    KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);

    addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
    sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
    sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
    VdbeCoverageEqNe(v);
    sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
    sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
    VdbeComment((v, "call flush_partition"));
  }

  /* Buffer the current row in the ephemeral table. */
  sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
  sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);

  /* End of the input loop */
  sqlite3WhereEnd(pWInfo);

  /* Invoke "flush_partition" to deal with the final (or only) partition */
  sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
  VdbeComment((v, "call flush_partition"));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r13
movl %r8d, 0x14(%rsp)
movl %ecx, 0x8(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq 0x70(%rsi), %rax
movq %rax, 0x18(%rsp)
callq 0x44e8aa
movq %rax, %r15
movq 0x28(%r14), %rax
movl 0x48(%rax), %r12d
movq 0x28(%rax), %rax
movswl 0x46(%rax), %ebp
movl 0x38(%rbx), %eax
leal 0x1(%rax), %r14d
leal 0x1(%rax,%rbp), %ecx
movl %ecx, 0xc(%rsp)
leal 0x2(%rax,%rbp), %eax
movl %eax, 0x10(%rsp)
movl %eax, (%r13)
movl 0x38(%rbx), %eax
addl %ebp, %eax
addl $0x2, %eax
movl %eax, 0x38(%rbx)
testl %ebp, %ebp
jle 0x46c9c7
xorl %r13d, %r13d
leal (%r14,%r13), %r8d
movq %r15, %rdi
movl $0x5a, %esi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x43bae0
incl %r13d
cmpl %r13d, %ebp
jne 0x46c9a8
movq %r15, %rdi
movl $0x66, %esi
movl %r14d, %edx
movl %ebp, %ecx
movl 0xc(%rsp), %r8d
callq 0x43bae0
movq 0x18(%rsp), %r12
movq 0x8(%r12), %rsi
testq %rsi, %rsi
movl 0x14(%rsp), %r13d
je 0x46caa6
movl (%rsi), %ebp
addl 0x68(%r12), %r14d
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x45d7eb
movq %r12, %rcx
movq %rax, %r12
movl 0x5c(%rcx), %ecx
movq %r15, %rdi
movl $0x57, %esi
movl %r14d, %edx
movl %ebp, %r8d
callq 0x43bae0
movl %eax, %ebx
movq (%r15), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x46ca3f
movl $0xfffffff7, %esi       # imm = 0xFFFFFFF7
movq %r12, %rdx
callq 0x423499
jmp 0x46ca58
movq 0x68(%r15), %rax
movslq 0xb8(%r15), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x9, -0x17(%rax,%rcx,8)
movq %r12, -0x8(%rax,%rcx,8)
leal 0x2(%rbx), %edx
addl $0x4, %ebx
movq %r15, %rdi
movl $0x10, %esi
movl %ebx, %ecx
movl %edx, %r8d
callq 0x43bae0
movq 0x18(%rsp), %r12
movl 0x5c(%r12), %ecx
decl %ebp
movq %r15, %rdi
movl $0x4e, %esi
movl %r14d, %edx
movl %ebp, %r8d
callq 0x43bae0
movq %r15, %rdi
movl $0xc, %esi
movl 0x8(%rsp), %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl 0x48(%r12), %edx
movq %r15, %rdi
movl $0x79, %esi
movl 0x10(%rsp), %ebx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl 0x48(%r12), %edx
movq %r15, %rdi
movl $0x7a, %esi
movl 0xc(%rsp), %ecx
movl %ebx, %r8d
callq 0x43bae0
movq 0x20(%rsp), %rdi
callq 0x460b22
movq %r15, %rdi
movl $0xc, %esi
movl 0x8(%rsp), %edx
movl %r13d, %ecx
xorl %r8d, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x43bae0