// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3WindowCodeInit
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
  int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr;
  Window *pMWin = pSelect->pWin;
  Window *pWin;
  Vdbe *v = sqlite3GetVdbe(pParse);

  sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr);
  sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
  sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
  sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);

  /* Allocate registers to use for PARTITION BY values, if any. Initialize
  ** said registers to NULL.  */
  if( pMWin->pPartition ){
    int nExpr = pMWin->pPartition->nExpr;
    pMWin->regPart = pParse->nMem+1;
    pParse->nMem += nExpr;
    sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
  }

  pMWin->regOne = ++pParse->nMem;
  sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regOne);

  if( pMWin->eExclude ){
    pMWin->regStartRowid = ++pParse->nMem;
    pMWin->regEndRowid = ++pParse->nMem;
    pMWin->csrApp = pParse->nTab++;
    sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
    sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
    sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr);
    return;
  }

  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *p = pWin->pFunc;
    if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
      /* The inline versions of min() and max() require a single ephemeral
      ** table and 3 registers. The registers are used as follows:
      **
      **   regApp+0: slot to copy min()/max() argument to for MakeRecord
      **   regApp+1: integer value used to ensure keys are unique
      **   regApp+2: output of MakeRecord
      */
      ExprList *pList = pWin->pOwner->x.pList;
      KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
      pWin->csrApp = pParse->nTab++;
      pWin->regApp = pParse->nMem+1;
      pParse->nMem += 3;
      if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
        assert( pKeyInfo->aSortFlags[0]==0 );
        pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
      }
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2);
      sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
    }
    else if( p->zName==nth_valueName || p->zName==first_valueName ){
      /* Allocate two registers at pWin->regApp. These will be used to
      ** store the start and end index of the current frame.  */
      pWin->regApp = pParse->nMem+1;
      pWin->csrApp = pParse->nTab++;
      pParse->nMem += 2;
      sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
    }
    else if( p->zName==leadName || p->zName==lagName ){
      pWin->csrApp = pParse->nTab++;
      sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r15
callq 0x2bc630
movq %rax, %r14
movl 0x58(%r13), %edx
movq %rax, %rdi
movl $0x64, %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x58(%r13), %ecx
leal 0x1(%rcx), %edx
movq %r14, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x58(%r13), %ecx
leal 0x2(%rcx), %edx
movq %r14, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x58(%r13), %ecx
leal 0x3(%rcx), %edx
movq %r14, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x2ce09c
movl 0x38(%r15), %r8d
leal 0x1(%r8), %ecx
addl (%rax), %r8d
movl %ecx, 0x6c(%r13)
movl %r8d, 0x38(%r15)
movq %r14, %rdi
movl $0x48, %esi
xorl %edx, %edx
callq 0x2a83e1
movl 0x38(%r15), %ecx
incl %ecx
movl %ecx, 0x38(%r15)
movl %ecx, 0x80(%r13)
movq %r14, %rdi
movl $0x45, %esi
movl $0x1, %edx
xorl %r8d, %r8d
callq 0x2a83e1
cmpb $0x0, 0x24(%r13)
je 0x2ce148
movl 0x38(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x84(%r13)
addl $0x2, %eax
movl %eax, 0x38(%r15)
movl %eax, 0x88(%r13)
movl 0x34(%r15), %eax
leal 0x1(%rax), %edx
movl %edx, 0x34(%r15)
movl %eax, 0x64(%r13)
movq %r14, %rdi
movl $0x45, %esi
movl $0x1, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x88(%r13), %ecx
movq %r14, %rdi
movl $0x45, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x58(%r13), %ecx
movl 0x64(%r13), %edx
movq %r14, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a83e1
leaq 0x10712c(%rip), %r12    # 0x3d527b
leaq 0x10712f(%rip), %rbp    # 0x3d5285
movq %r13, %rbx
movq 0x50(%rbx), %rax
testb $0x10, 0x5(%rax)
je 0x2ce169
cmpb $0x5a, 0x21(%rbx)
jne 0x2ce1e7
movq 0x38(%rax), %rax
cmpq %r12, %rax
setne %cl
cmpq %rbp, %rax
setne %dl
testb %dl, %cl
jne 0x2ce19e
movl 0x38(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x68(%rbx)
movl 0x34(%r15), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x34(%r15)
movl %edx, 0x64(%rbx)
addl $0x2, %eax
movl %eax, 0x38(%r15)
jmp 0x2ce1ce
leaq 0x1070cd(%rip), %rcx    # 0x3d5272
cmpq %rcx, %rax
setne %cl
leaq 0x1070c5(%rip), %rdx    # 0x3d5277
cmpq %rdx, %rax
setne %al
testb %al, %cl
jne 0x2ce2a8
movl 0x34(%r15), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r15)
movl %edx, 0x64(%rbx)
movl 0x58(%r13), %ecx
movq %r14, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2a83e1
jmp 0x2ce2a8
movq %r12, %rbp
movq 0x70(%rbx), %rax
movq 0x20(%rax), %rsi
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cde19
movq %rax, %r12
movl 0x34(%r15), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r15)
movl %edx, 0x64(%rbx)
movl 0x38(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x68(%rbx)
addl $0x3, %eax
movl %eax, 0x38(%r15)
testq %r12, %r12
je 0x2ce23e
movq 0x50(%rbx), %rax
movq 0x38(%rax), %rax
cmpb $0x69, 0x1(%rax)
jne 0x2ce23e
movq 0x18(%r12), %rax
movb $0x1, (%rax)
movl 0x64(%rbx), %edx
movq %r14, %rdi
movl $0x64, %esi
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq (%r14), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x2ce26b
movl $0xfffffff7, %esi       # imm = 0xFFFFFFF7
movq %r12, %rdx
callq 0x28fb69
jmp 0x2ce287
movq 0x88(%r14), %rax
movslq 0x90(%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x9, -0x17(%rax,%rcx,8)
movq %r12, -0x8(%rax,%rcx,8)
movl 0x68(%rbx), %ecx
incl %ecx
movq %r14, %rdi
movl $0x45, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbp, %r12
leaq 0x106fdd(%rip), %rbp    # 0x3d5285
movq 0x40(%rbx), %rbx
testq %rbx, %rbx
jne 0x2ce159
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq