// File: /workspace/github_c_makefile_star2_O2/ukontainer[P]sqlite-bench/sqlite3.c
// Function: windowAggStep
static void windowAggStep(
  Parse *pParse, 
  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 */
  int regPartSize                 /* Register containing size of partition */
){
  Vdbe *v = sqlite3GetVdbe(pParse);
  Window *pWin;
  for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
    int flags = pWin->pFunc->funcFlags;
    int regArg;
    int nArg = windowArgCount(pWin);

    if( csr>=0 ){
      int i;
      for(i=0; i<nArg; i++){
        sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
      }
      regArg = reg;
      if( flags & SQLITE_FUNC_WINDOW_SIZE ){
        if( nArg==0 ){
          regArg = regPartSize;
        }else{
          sqlite3VdbeAddOp2(v, OP_SCopy, regPartSize, reg+nArg);
        }
        nArg++;
      }
    }else{
      assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
      regArg = reg + pWin->iArgCol;
    }

    if( (pWin->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( pWin->pFunc->zName==nth_valueName
           || pWin->pFunc->zName==first_valueName
      );
      assert( bInverse==0 || bInverse==1 );
      sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
    }else if( pWin->pFunc->zName==leadName
           || pWin->pFunc->zName==lagName
    ){
      /* no-op */
    }else{
      int addrIf = 0;
      if( pWin->pFilter ){
        int regTmp;
        assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
        assert( nArg || pWin->pOwner->x.pList==0 );
        if( csr>0 ){
          regTmp = sqlite3GetTempReg(pParse);
          sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
        }else{
          regTmp = regArg + nArg;
        }
        addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
        VdbeCoverage(v);
        if( csr>0 ){
          sqlite3ReleaseTempReg(pParse, regTmp);
        }
      }
      if( pWin->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, pWin->pFunc, P4_FUNCDEF);
      sqlite3VdbeChangeP5(v, (u8)nArg);
      if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, %r14d
movl %ecx, %ebx
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
callq 0x44856b
movq %rax, %r13
xorl %eax, %eax
movl %ebx, 0xc(%rsp)
cmpl $0x1, %ebx
adcl $0x9a, %eax
movl %eax, 0x20(%rsp)
testq %r12, %r12
je 0x45ecad
movq 0x60(%r12), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x45e9e4
movl (%rax), %ebx
jmp 0x45e9e6
xorl %ebx, %ebx
testl %r15d, %r15d
js 0x45ea3e
movq 0x40(%r12), %rax
movl 0x4(%rax), %eax
movl %eax, 0x8(%rsp)
xorl %ebp, %ebp
testl %ebx, %ebx
movq %rbx, %rax
movl $0x0, %ebx
movq %rax, 0x10(%rsp)
cmovgl %eax, %ebx
cmpl %ebp, %ebx
je 0x45ea2c
movl 0x6c(%r12), %ecx
addl %ebp, %ecx
leal (%r14,%rbp), %r8d
movq %r13, %rdi
pushq $0x5a
popq %rsi
movl %r15d, %edx
callq 0x432a44
incl %ebp
jmp 0x45ea0b
btl $0x11, 0x8(%rsp)
jb 0x45ea48
movl %r14d, %ebp
movq 0x10(%rsp), %rbx
jmp 0x45ea6b
movl 0x6c(%r12), %ebp
addl %r14d, %ebp
jmp 0x45ea6b
movl 0x24(%rsp), %edx
movl %edx, %ebp
movq 0x10(%rsp), %rbx
testl %ebx, %ebx
je 0x45ea69
leal (%rbx,%r14), %ecx
movq %r13, %rdi
pushq $0x4f
popq %rsi
callq 0x432a3f
movl %r14d, %ebp
incl %ebx
movq 0x40(%r12), %rax
testb $0x10, 0x5(%rax)
je 0x45ea82
cmpb $0x57, 0x19(%r12)
jne 0x45eb0e
movl 0x58(%r12), %edx
testl %edx, %edx
je 0x45eaa4
subl 0xc(%rsp), %edx
incl %edx
movq %r13, %rdi
pushq $0x53
popq %rsi
pushq $0x1
popq %rcx
callq 0x432a3f
jmp 0x45eca3
movq 0x38(%rax), %rax
leaq 0xdf489(%rip), %rcx     # 0x53df38
cmpq %rcx, %rax
sete %cl
leaq 0xdf481(%rip), %rdx     # 0x53df3d
cmpq %rdx, %rax
sete %al
orb %cl, %al
jne 0x45eca3
cmpq $0x0, 0x38(%r12)
je 0x45ebc3
testl %r15d, %r15d
movq 0x18(%rsp), %rdi
jle 0x45ebcd
callq 0x44b9b3
movl %eax, 0x8(%rsp)
movl 0x6c(%r12), %ecx
addl %ebx, %ecx
movq %r13, %rdi
pushq $0x5a
popq %rsi
movl %r15d, %edx
movl %eax, %r8d
callq 0x432a44
movl 0x8(%rsp), %edx
jmp 0x45ebd0
movq %r13, %rdi
pushq $0x32
popq %rsi
movl %ebp, %edx
callq 0x449fcc
movl %eax, %ebx
cmpl $0x0, 0xc(%rsp)
je 0x45eb61
movl 0x54(%r12), %edx
movq %r13, %rdi
pushq $0x18
popq %rsi
xorl %ecx, %ecx
movl %ebp, %r8d
pushq $0x1
popq %r9
callq 0x40c85b
movl 0x54(%r12), %edx
movq %r13, %rdi
pushq $0x7c
popq %rsi
callq 0x449fcc
movl 0xb8(%r13), %esi
addl $-0x2, %esi
movq %r13, %rdi
callq 0x4485a5
jmp 0x45ebb9
movl 0x58(%r12), %edx
incl %edx
movq %r13, %rdi
pushq $0x53
popq %rsi
pushq $0x1
popq %rcx
callq 0x432a3f
movl 0x58(%r12), %ecx
movq %r13, %rdi
pushq $0x4f
popq %rsi
movl %ebp, %edx
callq 0x432a3f
movl 0x58(%r12), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
pushq $0x66
popq %rsi
pushq $0x2
popq %rcx
callq 0x432a44
movl 0x54(%r12), %edx
movl 0x58(%r12), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x85, %esi
callq 0x432a3f
movq %r13, %rdi
movl %ebx, %esi
jmp 0x45ec9e
movl $0x0, 0x10(%rsp)
jmp 0x45ec12
leal (%rbx,%rbp), %edx
movl %edx, 0x8(%rsp)
movq %r13, %rdi
pushq $0x14
popq %rsi
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x432a44
testl %r15d, %r15d
movl %eax, 0x10(%rsp)
jle 0x45ec12
movl 0x8(%rsp), %esi
testl %esi, %esi
movq 0x18(%rsp), %rdx
je 0x45ec12
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x45ec12
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %esi, 0xc4(%rdx,%rax,4)
movq 0x40(%r12), %rax
testb $0x20, 0x4(%rax)
je 0x45ec50
movq 0x60(%r12), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x18(%rsp), %rdi
callq 0x45832e
movl $0xfffffffe, (%rsp)     # imm = 0xFFFFFFFE
movq %r13, %rdi
pushq $0x52
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x4485b6
movl 0x4c(%r12), %r8d
movq %r13, %rdi
movl 0x20(%rsp), %esi
movl 0xc(%rsp), %edx
movl %ebp, %ecx
callq 0x432a44
movq 0x40(%r12), %rsi
movq %r13, %rdi
pushq $-0x8
popq %rdx
callq 0x448919
movslq 0xb8(%r13), %rax
testq %rax, %rax
jle 0x45ec93
movzbl %bl, %ecx
movq 0x68(%r13), %rdx
imulq $0x18, %rax, %rax
movw %cx, -0x16(%rdx,%rax)
movl 0x10(%rsp), %esi
testl %esi, %esi
je 0x45eca3
movq %r13, %rdi
callq 0x4485a5
movq 0x30(%r12), %r12
jmp 0x45e9c9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq