// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x459246
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x8c(%rax), %eax
cmpl $0x0, %eax
je 0x458e2b
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0x458e37
movq -0x38(%rbp), %rdi
callq 0x458950
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x458ebc
cmpl $0x1, -0x4c(%rbp)
jne 0x458e63
movq -0x40(%rbp), %rax
leaq 0x151933(%rip), %rcx    # 0x5aa790
cmpq %rcx, 0x38(%rax)
je 0x458e88
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %edx
movq -0x38(%rbp), %rax
movl 0x7c(%rax), %ecx
addl -0x4c(%rbp), %ecx
movl -0x1c(%rbp), %r8d
addl -0x4c(%rbp), %r8d
movl $0x59, %esi
callq 0x410130
jmp 0x458eaf
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edx
movq -0x38(%rbp), %rax
movl 0x7c(%rax), %ecx
addl -0x4c(%rbp), %ecx
movl -0x1c(%rbp), %r8d
addl -0x4c(%rbp), %r8d
movl $0x59, %esi
callq 0x410130
jmp 0x458eb1
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x458e44
movl -0x1c(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x84(%rax)
jne 0x458ffb
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x458ffb
movq -0x38(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x5a, %eax
je 0x458ffb
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl $0x32, %esi
callq 0x42ba70
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x458f8f
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x68(%rax), %edx
addl $0x1, %edx
movl $0x52, %esi
movl $0x1, %ecx
callq 0x410100
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movq -0x38(%rbp), %rax
movl 0x68(%rax), %ecx
movl $0x4e, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x68(%rax), %edx
movq -0x38(%rbp), %rax
movl 0x68(%rax), %r8d
addl $0x2, %r8d
movl $0x5b, %esi
movl $0x2, %ecx
callq 0x410130
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x64(%rax), %edx
movq -0x38(%rbp), %rax
movl 0x68(%rax), %ecx
addl $0x2, %ecx
movl $0x82, %esi
callq 0x410100
jmp 0x458fea
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x64(%rax), %edx
movl -0x44(%rbp), %r8d
movl $0x18, %esi
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x3cb970
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x64(%rax), %edx
movl $0x7a, %esi
callq 0x42ba70
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rdi
callq 0x430ae0
movq -0x88(%rbp), %rdi
movl %eax, %esi
subl $0x2, %esi
callq 0x429a70
movq -0x30(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x429a70
jmp 0x459233
movq -0x38(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x45902a
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x68(%rax), %edx
addl $0x1, %edx
subl -0x18(%rbp), %edx
movl $0x52, %esi
movl $0x1, %ecx
callq 0x410100
jmp 0x459231
movq -0x40(%rbp), %rax
leaq 0x21b(%rip), %rcx       # 0x459250
cmpq %rcx, 0x18(%rax)
je 0x45922f
movl $0x0, -0x54(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x4590a4
movq -0x28(%rbp), %rdi
callq 0x42f190
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %edx
movq -0x38(%rbp), %rax
movl 0x7c(%rax), %ecx
addl -0x48(%rbp), %ecx
movl -0x58(%rbp), %r8d
movl $0x59, %esi
callq 0x410130
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %edx
movl $0x14, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x410130
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x42e560
movq -0x38(%rbp), %rax
cmpb $0x0, 0x8c(%rax)
je 0x459163
movq -0x30(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x5c(%rbp)
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x42cb30
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rsi
movl -0x44(%rbp), %edx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x42cbc0
movq -0x30(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x429e10
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x429e10
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
ja 0x459161
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x59, %eax
jne 0x459151
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jne 0x459151
movl -0x14(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x459153
movq -0x68(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x68(%rbp)
jmp 0x459121
jmp 0x459163
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x4591b1
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x448820
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
movq -0x78(%rbp), %r9
movl $0x51, %esi
xorl %r8d, %r8d
movl %r8d, %edx
movl %r8d, %ecx
movl $0xfffffffe, (%rsp)     # imm = 0xFFFFFFFE
callq 0x429aa0
movq -0x30(%rbp), %rdi
movl -0x18(%rbp), %ecx
movl $0x9a, %esi
movl $0x99, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
movl -0x18(%rbp), %edx
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl 0x5c(%rax), %r8d
callq 0x410130
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0xfffffff8, %edx       # imm = 0xFFFFFFF8
callq 0x42a320
movq -0x30(%rbp), %rdi
movl -0x48(%rbp), %eax
movzbl %al, %eax
movzwl %ax, %esi
callq 0x3cb9f0
movq -0x38(%rbp), %rax
cmpb $0x0, 0x8c(%rax)
je 0x45921b
movq -0x28(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %edx
callq 0x42d0c0
cmpl $0x0, -0x54(%rbp)
je 0x45922d
movq -0x30(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x429a70
jmp 0x45922f
jmp 0x459231
jmp 0x459233
jmp 0x459235
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x458dfd
addq $0x90, %rsp
popq %rbp
retq
nop