// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movl %edx, %r14d
movq %rsi, %rbx
movq (%rdi), %r15
movq %r15, %rdi
callq 0x2bc630
movq %rbx, 0x20(%rsp)
testq %rbx, %rbx
je 0x2dfd41
movq %rax, %r13
movq 0x18(%rsp), %rax
incl %eax
movl %eax, 0x34(%rsp)
leaq 0xd4(%r15), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
cmpl $0x1, 0x10(%rsp)
adcl $0x99, %eax
movl %eax, 0x30(%rsp)
leaq 0x2c(%r15), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rbx
movq %r15, (%rsp)
movq 0x50(%rbx), %r12
cmpb $0x0, 0x8c(%rbx)
movl $0x0, %ebp
je 0x2df89f
movq 0x20(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0x2df86b
testb $0x10, 0x5(%r12)
je 0x2df86b
cmpb $0x5a, 0x21(%rbx)
jne 0x2df956
movl 0x68(%rbx), %edx
testl %edx, %edx
je 0x2df90e
subl 0x10(%rsp), %edx
incl %edx
movq %r13, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x40(%rbx), %rbx
testq %rbx, %rbx
jne 0x2df839
jmp 0x2dfd41
movq 0x70(%rbx), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x2df84b
movl (%rax), %ebp
testl %ebp, %ebp
jle 0x2df84b
xorl %r15d, %r15d
cmpl $0x1, %r15d
jne 0x2df8c9
leaq 0xf59b9(%rip), %rax     # 0x3d527b
cmpq %rax, 0x38(%r12)
je 0x2df8f2
movl 0x7c(%rbx), %ecx
addl %r15d, %ecx
movq 0x18(%rsp), %rax
leal (%rax,%r15), %r8d
movq %r13, %rdi
movl $0x59, %esi
movl %r14d, %edx
callq 0x2a83e1
incl %r15d
cmpl %r15d, %ebp
jne 0x2df8b5
jmp 0x2df94d
movq 0x20(%rsp), %rax
movl 0x58(%rax), %edx
movl 0x7c(%rbx), %ecx
incl %ecx
movq %r13, %rdi
movl $0x59, %esi
movl 0x34(%rsp), %r8d
jmp 0x2df8e3
leaq 0x43b(%rip), %rax       # 0x2dfd50
cmpq %rax, 0x18(%r12)
je 0x2df891
cmpq $0x0, 0x48(%rbx)
je 0x2dfa0f
movb 0x1f(%r15), %al
testb %al, %al
je 0x2dfa19
decb %al
movb %al, 0x1f(%r15)
movzbl %al, %eax
movl 0xd4(%r15,%rax,4), %r15d
jmp 0x2dfa27
movq (%rsp), %r15
jmp 0x2df84b
movq %r13, %rdi
movl $0x32, %esi
movq 0x18(%rsp), %r15
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, %ebp
cmpl $0x0, 0x10(%rsp)
je 0x2dfc97
movl 0x64(%rbx), %edx
movq %r13, %rdi
movl $0x18, %esi
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0x2a83e1
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2df9b6
movq 0x88(%r13), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x1, 0x10(%rcx,%rax,8)
movl 0x64(%rbx), %edx
movq %r13, %rdi
movl $0x7a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r13), %eax
movq (%r13), %rcx
movb 0x61(%rcx), %cl
leaq 0x1df4a8(%rip), %rdx    # 0x4bee88
testb %cl, %cl
movq (%rsp), %r15
jne 0x2dfa07
xorl %edx, %edx
cmpl $0x2, %eax
setl %dl
orl $-0x2, %edx
addl %eax, %edx
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x88(%r13), %rdx
movl %eax, 0x8(%rdx)
jmp 0x2dfd0b
movl $0x0, 0x14(%rsp)
jmp 0x2dfa85
movq %r15, %rax
movl 0x38(%r15), %r15d
incl %r15d
movl %r15d, 0x38(%rax)
movl 0x7c(%rbx), %ecx
addl %ebp, %ecx
movq %r13, %rdi
movl $0x59, %esi
movl %r14d, %edx
movl %r15d, %r8d
callq 0x2a83e1
movq %r13, %rdi
movl $0x14, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x2a83e1
movl %eax, 0x14(%rsp)
testl %r15d, %r15d
je 0x2dfa81
movq (%rsp), %rdx
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2dfa7c
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xd4(%rdx,%rax,4)
movq %rdx, %r15
jmp 0x2dfa85
movq (%rsp), %r15
cmpb $0x0, 0x8c(%rbx)
movq 0x18(%rsp), %rax
movl %eax, 0xc(%rsp)
je 0x2dfb41
movl 0x90(%r13), %eax
movl %eax, 0x2c(%rsp)
movq 0x70(%rbx), %rax
movq 0x20(%rax), %rax
movl (%rax), %ebp
movq %r15, %rdi
movl %ebp, %esi
callq 0x2beb15
movl %eax, %edx
movq 0x70(%rbx), %rax
movq 0x20(%rax), %rsi
movq %r15, %rdi
movl %edx, 0xc(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2beb59
movq (%r13), %rax
cmpb $0x0, 0x61(%rax)
leaq 0x1df3a4(%rip), %rax    # 0x4bee88
movq %rax, %rcx
jne 0x2dfb23
movslq 0x90(%r13), %rdx
movq %rdx, %rax
decq %rax
movl 0x2c(%rsp), %esi
testl %esi, %esi
movl %eax, %ecx
cmovnsl %esi, %ecx
cmpl %edx, %ecx
jge 0x2dfd38
movq 0x88(%r13), %rdx
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movq (%rsp), %r15
cmpb $0x59, (%rcx)
jne 0x2dfb38
movl 0x4(%rcx), %edx
cmpl 0x58(%rbx), %edx
jne 0x2dfb38
movl %r14d, 0x4(%rcx)
addq $0x18, %rcx
cmpq %rax, %rcx
jbe 0x2dfb27
testb $0x20, 0x4(%r12)
je 0x2dfb9a
movq 0x70(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x2a9678
movq %rax, %r15
testq %rax, %rax
jne 0x2dfb70
movq (%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r15
movq %r13, %rdi
movl $0x51, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r13, %rdi
movl %eax, %esi
movq %r15, %rdx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x27b778
movq (%rsp), %r15
movl 0x5c(%rbx), %r8d
movq %r13, %rdi
movl 0x30(%rsp), %esi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
callq 0x2a83e1
movq (%r13), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x2dfbce
testb $0x10, 0x4(%r12)
je 0x2dfbea
movq %r12, %rsi
callq 0x282904
jmp 0x2dfbea
movq 0x88(%r13), %rax
movslq 0x90(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x8, -0x17(%rax,%rcx,8)
movq %r12, -0x8(%rax,%rcx,8)
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x2dfc0a
movzbl %bpl, %ecx
movq 0x88(%r13), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
cmpb $0x0, 0x8c(%rbx)
je 0x2dfc51
cmpl $0x1, %ebp
jne 0x2dfc3c
cmpl $0x0, 0xc(%rsp)
je 0x2dfc51
movzbl 0x1f(%r15), %eax
cmpq $0x7, %rax
ja 0x2dfc51
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r15)
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
jmp 0x2dfc4b
cmpl %ebp, 0x28(%r15)
jge 0x2dfc51
movl %ebp, 0x28(%r15)
movq 0x40(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x2df891
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x1df215(%rip), %rcx    # 0x4bee88
jne 0x2dfc8f
leal -0x1(%rax), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
movl %eax, 0x8(%rcx)
jmp 0x2df891
movl 0x68(%rbx), %edx
incl %edx
movq %r13, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x68(%rbx), %ecx
movq %r13, %rdi
movl $0x4e, %esi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x68(%rbx), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
movl $0x5b, %esi
movl $0x2, %ecx
callq 0x2a83e1
movl 0x64(%rbx), %edx
movl 0x68(%rbx), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x82, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r13), %eax
movq (%r13), %rcx
movb 0x61(%rcx), %cl
movq (%rsp), %r15
leaq 0x1df176(%rip), %rdx    # 0x4bee88
testb %cl, %cl
jne 0x2dfd30
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x88(%r13), %rdx
movl %eax, 0x8(%rdx)
jmp 0x2df891
movq (%rsp), %r15
jmp 0x2dfb41
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq