// File: /workspace/github_c_makefile_star2_O1/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, 0x4(%rsp)
movl %edx, %r14d
movq %rsi, %rbx
movq (%rdi), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2c5ddf
movq %rbx, 0x20(%rsp)
testq %rbx, %rbx
je 0x2e8fbc
movq %rax, %r13
movq 0x18(%rsp), %rax
incl %eax
movl %eax, 0x34(%rsp)
xorl %eax, %eax
cmpl $0x1, 0x4(%rsp)
adcl $0x99, %eax
movl %eax, 0x30(%rsp)
movq 0x8(%rsp), %rax
leaq 0x2c(%rax), %rcx
movq %rcx, 0x40(%rsp)
addq $0xd4, %rax
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %r15
cmpb $0x0, 0x8c(%r15)
movl $0x0, %r12d
jne 0x2e8b03
movq 0x70(%r15), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x2e8b03
movl (%rax), %r12d
movq 0x50(%r15), %rbp
testl %r12d, %r12d
jle 0x2e8b65
xorl %ebx, %ebx
cmpl $0x1, %ebx
jne 0x2e8b20
leaq 0xf5ee1(%rip), %rax     # 0x3de9fb
cmpq %rax, 0x38(%rbp)
je 0x2e8b48
movl 0x7c(%r15), %ecx
addl %ebx, %ecx
movq 0x18(%rsp), %rax
leal (%rax,%rbx), %r8d
movq %r13, %rdi
movl $0x59, %esi
movl %r14d, %edx
callq 0x2b200c
incl %ebx
cmpl %ebx, %r12d
jne 0x2e8b0e
jmp 0x2e8b65
movq 0x20(%rsp), %rax
movl 0x58(%rax), %edx
movl 0x7c(%r15), %ecx
incl %ecx
movq %r13, %rdi
movl $0x59, %esi
movl 0x34(%rsp), %r8d
jmp 0x2e8b3a
movq 0x20(%rsp), %rax
cmpl $0x0, 0x84(%rax)
jne 0x2e8b80
testb $0x10, 0x5(%rbp)
je 0x2e8b80
cmpb $0x5a, 0x21(%r15)
jne 0x2e8be8
movl 0x68(%r15), %edx
testl %edx, %edx
je 0x2e8ba8
subl 0x4(%rsp), %edx
incl %edx
movq %r13, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2b200c
jmp 0x2e8faf
leaq 0x41c(%rip), %rax       # 0x2e8fcb
cmpq %rax, 0x18(%rbp)
je 0x2e8faf
cmpq $0x0, 0x48(%r15)
je 0x2e8ca0
movq 0x8(%rsp), %rcx
movb 0x1f(%rcx), %al
testb %al, %al
je 0x2e8ca4
decb %al
movb %al, 0x1f(%rcx)
movzbl %al, %eax
movl 0xd4(%rcx,%rax,4), %ebx
jmp 0x2e8cac
movq %r13, %rdi
movl $0x32, %esi
movq 0x18(%rsp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl %eax, %ebp
cmpl $0x0, 0x4(%rsp)
je 0x2e8f11
movl 0x64(%r15), %edx
movq %r13, %rdi
movl $0x18, %esi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x2b200c
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x1e1255(%rip), %rbx    # 0x4c9e88
jne 0x2e8c4f
movq 0x88(%r13), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x1, 0x10(%rcx,%rax,8)
movl 0x64(%r15), %edx
movq %r13, %rdi
movl $0x7a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
movq %rbx, %rcx
jne 0x2e8c98
xorl %ecx, %ecx
cmpl $0x2, %eax
setl %cl
orl $-0x2, %ecx
addl %eax, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
movl %eax, 0x8(%rcx)
jmp 0x2e8f7e
xorl %ebx, %ebx
jmp 0x2e8d01
movl 0x38(%rcx), %ebx
incl %ebx
movl %ebx, 0x38(%rcx)
movl 0x7c(%r15), %ecx
addl %r12d, %ecx
movq %r13, %rdi
movl $0x59, %esi
movl %r14d, %edx
movl %ebx, %r8d
callq 0x2b200c
movq %r13, %rdi
movl $0x14, %esi
movl %ebx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x2b200c
movl %ebx, %esi
movl %eax, %ebx
testl %esi, %esi
je 0x2e8d01
movq 0x8(%rsp), %rdx
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2e8d01
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %esi, 0xd4(%rdx,%rax,4)
cmpb $0x0, 0x8c(%r15)
movq 0x18(%rsp), %rax
movl %eax, (%rsp)
movl %ebx, 0x14(%rsp)
je 0x2e8dcf
movl 0x90(%r13), %eax
movl %eax, 0x2c(%rsp)
movq 0x70(%r15), %rax
movq 0x20(%rax), %rax
movl (%rax), %r12d
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2c8275
movl %eax, %edx
movq 0x70(%r15), %rax
movq 0x20(%rax), %rsi
movq %rbx, %rdi
movl %edx, (%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2c82b9
movslq 0x90(%r13), %rdx
decq %rdx
movq (%r13), %rax
movb 0x61(%rax), %sil
leaq 0x1e1114(%rip), %rcx    # 0x4c9e88
movq %rcx, %rax
testb %sil, %sil
jne 0x2e8d8b
leaq (%rdx,%rdx,2), %rax
shlq $0x3, %rax
addq 0x88(%r13), %rax
testb %sil, %sil
jne 0x2e8dab
movl 0x2c(%rsp), %ecx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movslq %edx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
cmpq %rax, %rcx
movl 0x14(%rsp), %ebx
ja 0x2e8dcf
cmpb $0x59, (%rcx)
jne 0x2e8dc6
movl 0x4(%rcx), %edx
cmpl 0x58(%r15), %edx
jne 0x2e8dc6
movl %r14d, 0x4(%rcx)
addq $0x18, %rcx
cmpq %rax, %rcx
jbe 0x2e8db4
testb $0x20, 0x4(%rbp)
je 0x2e8e29
movq 0x70(%r15), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x2b32a0
movq %rax, %rbx
testq %rax, %rax
jne 0x2e8dff
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rbx
movq %r13, %rdi
movl $0x51, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r13, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x285198
movl 0x14(%rsp), %ebx
movl 0x5c(%r15), %r8d
movq %r13, %rdi
movl 0x30(%rsp), %esi
movl 0x4(%rsp), %edx
movl (%rsp), %ecx
callq 0x2b200c
movq (%r13), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x2e8e5a
testb $0x10, 0x4(%rbp)
je 0x2e8e76
movq %rbp, %rsi
callq 0x28c3e7
jmp 0x2e8e76
movq 0x88(%r13), %rax
movslq 0x90(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x8, -0x17(%rax,%rcx,8)
movq %rbp, -0x8(%rax,%rcx,8)
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x2e8e96
movzbl %r12b, %ecx
movq 0x88(%r13), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
cmpb $0x0, 0x8c(%r15)
movq 0x8(%rsp), %rdx
je 0x2e8ee0
cmpl $0x1, %r12d
jne 0x2e8ecc
cmpl $0x0, (%rsp)
je 0x2e8ee0
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2e8ee0
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
jmp 0x2e8edb
cmpl %r12d, 0x28(%rdx)
jge 0x2e8ee0
movl %r12d, 0x28(%rdx)
movq 0x40(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
testl %ebx, %ebx
je 0x2e8faf
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x1e0f8a(%rip), %rcx    # 0x4c9e88
jne 0x2e8fac
leal -0x1(%rax), %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
jmp 0x2e8f9a
movl 0x68(%r15), %edx
incl %edx
movq %r13, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x68(%r15), %ecx
movq %r13, %rdi
movl $0x4e, %esi
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x68(%r15), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
movl $0x5b, %esi
movl $0x2, %ecx
callq 0x2b200c
movl 0x64(%r15), %edx
movl 0x68(%r15), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x82, %esi
xorl %r8d, %r8d
callq 0x2b200c
leaq 0x1e0f0a(%rip), %rbx    # 0x4c9e88
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
movq %rbx, %rcx
jne 0x2e8fac
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
movl %eax, 0x8(%rcx)
movq 0x40(%r15), %r15
testq %r15, %r15
jne 0x2e8ae3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq