// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x58(%rax), %edx
movl -0x14(%rbp), %ecx
movl $0x64, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x58(%rax), %edx
addl $0x1, %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x58(%rax), %edx
addl $0x2, %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x58(%rax), %edx
addl $0x3, %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x4412d0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x6c(%rax), %r8d
addl -0x34(%rbp), %r8d
subl $0x1, %r8d
movl $0x48, %esi
xorl %edx, %edx
callq 0x410130
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x80(%rax), %ecx
movl $0x45, %esi
movl $0x1, %edx
callq 0x410100
movq -0x20(%rbp), %rax
cmpb $0x0, 0x24(%rax)
je 0x4413ae
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x84(%rax), %ecx
movl $0x45, %esi
movl $0x1, %edx
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x88(%rax), %ecx
movl $0x45, %esi
xorl %edx, %edx
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
jmp 0x44159d
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x44159d
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x4414be
movq -0x28(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x5a, %eax
je 0x4414be
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x440f30
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rax)
movq -0x28(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x3, %ecx
movl %ecx, 0x38(%rax)
cmpq $0x0, -0x50(%rbp)
je 0x441473
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x38(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x69, %eax
jne 0x441473
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movb $0x1, (%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x64(%rax), %edx
movl $0x64, %esi
movl $0x2, %ecx
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0xfffffff7, %edx       # imm = 0xFFFFFFF7
callq 0x42a320
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x68(%rax), %ecx
addl $0x1, %ecx
movl $0x45, %esi
xorl %edx, %edx
callq 0x410100
jmp 0x44158a
movq -0x40(%rbp), %rax
leaq 0x1692c7(%rip), %rcx    # 0x5aa790
cmpq %rcx, 0x38(%rax)
je 0x4414e0
movq -0x40(%rbp), %rax
leaq 0x1692c0(%rip), %rcx    # 0x5aa79a
cmpq %rcx, 0x38(%rax)
jne 0x441532
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rax)
movq -0x28(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0x38(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
jmp 0x441588
movq -0x40(%rbp), %rax
leaq 0x16921d(%rip), %rcx    # 0x5aa75a
cmpq %rcx, 0x38(%rax)
je 0x441554
movq -0x40(%rbp), %rax
leaq 0x169211(%rip), %rcx    # 0x5aa75f
cmpq %rcx, 0x38(%rax)
jne 0x441586
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rax)
movq -0x28(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movl $0x62, %esi
callq 0x410100
jmp 0x441588
jmp 0x44158a
jmp 0x44158c
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x4413b6
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)