// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: windowAggStep
static void windowAggStep(
  WindowCodeArg *p,
  Window *pMWin,                  /* Linked list of window functions */
  int csr,                        /* Read arguments from this cursor */
  int bInverse,                   /* True to invoke xInverse instead of xStep */
  int reg                         /* Array of registers */
){
  Parse *pParse = p->pParse;
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    FuncDef *pFunc = pWin->pFunc;
    int regArg;
    int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
    int i;

    assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED );

    /* All OVER clauses in the same window function aggregate step must
    ** be the same. */
    assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 );

    for(i=0; i<nArg; i++){
      if( i!=1 || pFunc->zName!=nth_valueName ){
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
      }else{
        sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
      }
    }
    regArg = reg;

    if( pMWin->regStartRowid==0
     && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
     && (pWin->eStart!=TK_UNBOUNDED)
    ){
      int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
      VdbeCoverage(v);
      if( bInverse==0 ){
        sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
        sqlite3VdbeAddOp2(v, OP_SCopy, regArg, pWin->regApp);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, pWin->regApp, 2, pWin->regApp+2);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, pWin->csrApp, pWin->regApp+2);
      }else{
        sqlite3VdbeAddOp4Int(v, OP_SeekGE, pWin->csrApp, 0, regArg, 1);
        VdbeCoverageNeverTaken(v);
        sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
        sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      }
      sqlite3VdbeJumpHere(v, addrIsNull);
    }else if( pWin->regApp ){
      assert( pFunc->zName==nth_valueName
           || pFunc->zName==first_valueName
      );
      assert( bInverse==0 || bInverse==1 );
      sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
    }else if( pFunc->xSFunc!=noopStepFunc ){
      int addrIf = 0;
      if( pWin->pFilter ){
        int regTmp;
        assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
        assert( pWin->bExprArgs || nArg  ||pWin->pOwner->x.pList==0 );
        regTmp = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
        addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
        VdbeCoverage(v);
        sqlite3ReleaseTempReg(pParse, regTmp);
      }

      if( pWin->bExprArgs ){
        int iStart = sqlite3VdbeCurrentAddr(v);
        VdbeOp *pOp, *pEnd;

        nArg = pWin->pOwner->x.pList->nExpr;
        regArg = sqlite3GetTempRange(pParse, nArg);
        sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);

        pEnd = sqlite3VdbeGetOp(v, -1);
        for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){
          if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){
            pOp->p1 = csr;
          }
        }
      }
      if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
        CollSeq *pColl;
        assert( nArg>0 );
        pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
        sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
      }
      sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
                        bInverse, regArg, pWin->regAccum);
      sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
      sqlite3VdbeChangeP5(v, (u8)nArg);
      if( pWin->bExprArgs ){
        sqlite3ReleaseTempRange(pParse, regArg, nArg);
      }
      if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebx
movl %ecx, %ebp
movl %edx, 0x14(%rsp)
movq %rsi, %r14
movq (%rdi), %rdi
movq %rdi, 0x18(%rsp)
callq 0x2645be
movq %rax, %r13
leal 0x1(%rbx), %eax
movl %eax, 0x2c(%rsp)
xorl %eax, %eax
movl %ebp, 0x10(%rsp)
cmpl $0x1, %ebp
adcl $0x99, %eax
movl %eax, 0x20(%rsp)
movq %r14, 0x30(%rsp)
movq %r14, %rbp
testq %rbp, %rbp
je 0x27dfec
movq %rbx, %r14
xorl %r15d, %r15d
cmpb $0x0, 0x8c(%rbp)
movl $0x0, %ecx
jne 0x27dccd
movq 0x70(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x27dccd
movl (%rax), %ecx
movq 0x50(%rbp), %r12
testl %ecx, %ecx
movl $0x0, %ebx
movl %ecx, 0x8(%rsp)
cmovgl %ecx, %ebx
cmpl %r15d, %ebx
je 0x27dd30
cmpl $0x1, %r15d
jne 0x27dcf8
leaq 0xf799a(%rip), %rax     # 0x37568b
cmpq %rax, 0x38(%r12)
je 0x27dd16
movl 0x7c(%rbp), %ecx
addl %r15d, %ecx
leal (%r14,%r15), %r8d
movq %r13, %rdi
pushq $0x59
popq %rsi
movl 0x14(%rsp), %edx
callq 0x24d51f
incl %r15d
jmp 0x27dcdf
movq 0x30(%rsp), %rax
movl 0x58(%rax), %edx
movl 0x7c(%rbp), %ecx
incl %ecx
movq %r13, %rdi
pushq $0x59
popq %rsi
movl 0x2c(%rsp), %r8d
jmp 0x27dd0c
movq 0x30(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0x27dd50
testb $0x10, 0x5(%r12)
je 0x27dd50
cmpb $0x5a, 0x21(%rbp)
jne 0x27ddf3
movl 0x68(%rbp), %edx
testl %edx, %edx
movq %r14, %rbx
je 0x27dd73
subl 0x10(%rsp), %edx
incl %edx
movq %r13, %rdi
pushq $0x52
popq %rsi
pushq $0x1
popq %rcx
callq 0x24d51a
jmp 0x27dfe3
leaq 0x281(%rip), %rax       # 0x27dffb
cmpq %rax, 0x18(%r12)
je 0x27dfe3
cmpq $0x0, 0x48(%rbp)
je 0x27de4d
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x267d61
movl %eax, %r15d
movl 0x7c(%rbp), %ecx
addl 0x8(%rsp), %ecx
movq %r13, %rdi
pushq $0x59
popq %rsi
movl 0x14(%rsp), %edx
movl %eax, %r8d
callq 0x24d51f
movq %r13, %rdi
pushq $0x14
popq %rsi
movl %r15d, %edx
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x24d51f
movl %r15d, %edx
movl %eax, %r15d
testl %edx, %edx
je 0x27de55
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x27de55
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r14)
movl %edx, 0xd4(%r14,%rax,4)
jmp 0x27de55
movq %r13, %rdi
pushq $0x32
popq %rsi
movq %r14, %rbx
movl %ebx, %edx
callq 0x265d5c
movl %eax, %r12d
cmpl $0x0, 0x10(%rsp)
je 0x27df8a
movl 0x64(%rbp), %edx
movq %r13, %rdi
pushq $0x18
popq %rsi
xorl %ecx, %ecx
movl %ebx, %r8d
pushq $0x1
popq %r9
callq 0x226fc2
movl 0x64(%rbp), %edx
movq %r13, %rdi
pushq $0x7a
popq %rsi
callq 0x265d5c
movl 0x90(%r13), %esi
addl $-0x2, %esi
movq %r13, %rdi
callq 0x2645f8
jmp 0x27dfd8
xorl %r15d, %r15d
movq 0x18(%rsp), %r14
cmpb $0x0, 0x8c(%rbp)
movl %ebx, 0xc(%rsp)
je 0x27dee1
movl %r15d, 0x28(%rsp)
movl 0x90(%r13), %eax
movl %eax, 0x24(%rsp)
movq 0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %esi
movq %r14, %rdi
movl %esi, 0x8(%rsp)
callq 0x266492
movl %eax, %edx
movq 0x70(%rbp), %rax
movq 0x20(%rax), %rsi
movq %r14, %rdi
movl %edx, 0xc(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2664ba
movq %r13, %rdi
pushq $-0x1
popq %rsi
callq 0x26468f
movq %rax, %r15
movq %r13, %rdi
movl 0x24(%rsp), %esi
callq 0x26468f
cmpq %r15, %rax
ja 0x27dedc
cmpb $0x59, (%rax)
jne 0x27ded6
movl 0x4(%rax), %ecx
cmpl 0x58(%rbp), %ecx
jne 0x27ded6
movl 0x14(%rsp), %ecx
movl %ecx, 0x4(%rax)
addq $0x18, %rax
jmp 0x27debd
movl 0x28(%rsp), %r15d
testb $0x20, 0x4(%r12)
je 0x27df1b
movq 0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x18(%rsp), %rdi
callq 0x2765b9
movl $0xfffffffe, (%rsp)     # imm = 0xFFFFFFFE
movq %r13, %rdi
pushq $0x51
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x264609
movl 0x5c(%rbp), %r8d
movq %r13, %rdi
movl 0x20(%rsp), %esi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
callq 0x24d51f
movq %r13, %rdi
movq %r12, %rsi
pushq $-0x8
popq %rdx
callq 0x26495f
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x27df62
movzbl 0x8(%rsp), %ecx
movq 0x88(%r13), %rdx
imulq $0x18, %rax, %rax
movw %cx, -0x16(%rdx,%rax)
cmpb $0x0, 0x8c(%rbp)
je 0x27df7d
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
callq 0x2666df
testl %r15d, %r15d
je 0x27dfe3
movq %r13, %rdi
movl %r15d, %esi
jmp 0x27dfde
movl 0x68(%rbp), %edx
incl %edx
movq %r13, %rdi
pushq $0x52
popq %rsi
pushq $0x1
popq %rcx
callq 0x24d51a
movl 0x68(%rbp), %ecx
movq %r13, %rdi
pushq $0x4e
popq %rsi
movl %ebx, %edx
callq 0x24d51a
movl 0x68(%rbp), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
pushq $0x5b
popq %rsi
pushq $0x2
popq %rcx
callq 0x24d51f
movl 0x64(%rbp), %edx
movl 0x68(%rbp), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x82, %esi
callq 0x24d51a
movq %r13, %rdi
movl %r12d, %esi
callq 0x2645f8
movq 0x40(%rbp), %rbp
jmp 0x27dca1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq