// File: /workspace/github_c_makefile_star2_O1/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 %rdi, %r14
movq 0x28(%rsi), %rax
movq 0x70(%rsi), %r13
movq 0x30(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax), %ebp
callq 0x2c5ddf
movq %rax, %rbx
movl 0x58(%r13), %edx
movq %rax, %rdi
movl $0x64, %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x58(%r13), %ecx
leal 0x1(%rcx), %edx
movq %rbx, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2b200c
movl 0x58(%r13), %ecx
leal 0x2(%rcx), %edx
movq %rbx, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2b200c
movl 0x58(%r13), %ecx
leal 0x3(%rcx), %edx
movq %rbx, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2b200c
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x2d78b5
movl 0x38(%r14), %r8d
leal 0x1(%r8), %ecx
addl (%rax), %r8d
movl %ecx, 0x6c(%r13)
movl %r8d, 0x38(%r14)
movq %rbx, %rdi
movl $0x48, %esi
xorl %edx, %edx
callq 0x2b200c
movl 0x38(%r14), %ecx
incl %ecx
movl %ecx, 0x38(%r14)
movl %ecx, 0x80(%r13)
movq %rbx, %rdi
movl $0x45, %esi
movl $0x1, %edx
xorl %r8d, %r8d
callq 0x2b200c
cmpb $0x0, 0x24(%r13)
je 0x2d7969
movl 0x38(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x38(%r14)
movl %ecx, 0x84(%r13)
addl $0x2, %eax
movl %eax, 0x38(%r14)
movl %eax, 0x88(%r13)
movl 0x34(%r14), %eax
leal 0x1(%rax), %edx
movl %edx, 0x34(%r14)
movl %eax, 0x64(%r13)
movq %rbx, %rdi
movl $0x45, %esi
movl $0x1, %edx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x88(%r13), %ecx
movq %rbx, %rdi
movl $0x45, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x58(%r13), %ecx
movl 0x64(%r13), %edx
movq %rbx, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b200c
testq %r13, %r13
je 0x2d7af6
leaq 0x107082(%rip), %r15    # 0x3de9fb
leaq 0x107085(%rip), %rbp    # 0x3dea05
movq %r13, %r12
movq 0x50(%r12), %rax
testb $0x10, 0x5(%rax)
je 0x2d799a
cmpb $0x5a, 0x21(%r12)
jne 0x2d7a1e
movq 0x38(%rax), %rax
cmpq %r15, %rax
setne %cl
cmpq %rbp, %rax
setne %dl
testb %dl, %cl
jne 0x2d79d3
movl 0x38(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x68(%r12)
movl 0x34(%r14), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x34(%r14)
movl %edx, 0x64(%r12)
addl $0x2, %eax
movl %eax, 0x38(%r14)
jmp 0x2d7a05
leaq 0x107018(%rip), %rcx    # 0x3de9f2
cmpq %rcx, %rax
setne %cl
leaq 0x107010(%rip), %rdx    # 0x3de9f7
cmpq %rdx, %rax
setne %al
testb %al, %cl
jne 0x2d7ae8
movl 0x34(%r14), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r14)
movl %edx, 0x64(%r12)
movl 0x58(%r13), %ecx
movq %rbx, %rdi
movl $0x62, %esi
xorl %r8d, %r8d
callq 0x2b200c
jmp 0x2d7ae8
movq %r15, %rbp
movq 0x70(%r12), %rax
movq 0x20(%rax), %rsi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2d7619
movq %rax, %r15
movl 0x34(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x34(%r14)
movl %eax, 0x64(%r12)
movl 0x38(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x68(%r12)
addl $0x3, %eax
movl %eax, 0x38(%r14)
testq %r15, %r15
je 0x2d7a77
movq 0x50(%r12), %rax
movq 0x38(%rax), %rax
cmpb $0x69, 0x1(%rax)
jne 0x2d7a77
movq 0x18(%r15), %rax
movb $0x1, (%rax)
movl 0x64(%r12), %edx
movq %rbx, %rdi
movl $0x64, %esi
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq (%rbx), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x2d7aa9
movl $0xfffffff7, %esi       # imm = 0xFFFFFFF7
movq %r15, %rdx
callq 0x29991d
jmp 0x2d7ac5
movq 0x88(%rbx), %rax
movslq 0x90(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x9, -0x17(%rax,%rcx,8)
movq %r15, -0x8(%rax,%rcx,8)
movl 0x68(%r12), %ecx
incl %ecx
movq %rbx, %rdi
movl $0x45, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2b200c
movq %rbp, %r15
leaq 0x106f1d(%rip), %rbp    # 0x3dea05
movq 0x40(%r12), %r12
testq %r12, %r12
jne 0x2d7983
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq