// File: /workspace/github_c_makefile_star2_O1/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, 0x4(%rsp)
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
callq 0x44e8aa
testq %r12, %r12
je 0x46d16c
movq %rax, %r13
xorl %eax, %eax
cmpl $0x1, 0x4(%rsp)
adcl $0x9a, %eax
movl %eax, 0x20(%rsp)
movq 0x60(%r12), %rax
movq 0x20(%rax), %rax
movl $0x0, %ebp
testq %rax, %rax
je 0x46cd86
movl (%rax), %ebp
testl %r15d, %r15d
js 0x46cdcb
movq 0x40(%r12), %rax
movl 0x4(%rax), %eax
movl %eax, 0x8(%rsp)
testl %ebp, %ebp
jle 0x46cdbe
xorl %ebx, %ebx
movl 0x6c(%r12), %ecx
addl %ebx, %ecx
leal (%r14,%rbx), %r8d
movq %r13, %rdi
movl $0x5a, %esi
movl %r15d, %edx
callq 0x43bae0
incl %ebx
cmpl %ebx, %ebp
jne 0x46cd9d
btl $0x11, 0x8(%rsp)
jb 0x46cdd5
movl %r14d, %ebx
jmp 0x46cdf8
movl 0x6c(%r12), %ebx
addl %r14d, %ebx
jmp 0x46cdf8
movl 0x24(%rsp), %edx
movl %edx, %ebx
testl %ebp, %ebp
je 0x46cdf6
leal (%r14,%rbp), %ecx
movq %r13, %rdi
movl $0x4f, %esi
xorl %r8d, %r8d
callq 0x43bae0
movl %r14d, %ebx
incl %ebp
movq 0x40(%r12), %rax
testb $0x10, 0x5(%rax)
je 0x46ce0f
cmpb $0x57, 0x19(%r12)
jne 0x46ce97
movl 0x58(%r12), %edx
testl %edx, %edx
je 0x46ce38
subl 0x4(%rsp), %edx
incl %edx
movq %r13, %rdi
movl $0x53, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x43bae0
jmp 0x46d15e
movq 0x38(%rax), %rax
leaq 0xe3125(%rip), %rcx     # 0x54ff68
cmpq %rcx, %rax
sete %cl
leaq 0xe311d(%rip), %rdx     # 0x54ff6d
cmpq %rdx, %rax
sete %al
orb %cl, %al
jne 0x46d15e
cmpq $0x0, 0x38(%r12)
je 0x46cfd4
testl %r15d, %r15d
movq 0x10(%rsp), %rcx
jle 0x46cfe1
movb 0x1f(%rcx), %al
testb %al, %al
je 0x46cfe6
decb %al
movb %al, 0x1f(%rcx)
movzbl %al, %eax
movl 0xc4(%rcx,%rax,4), %eax
jmp 0x46cfee
movq %r13, %rdi
movl $0x32, %esi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl %eax, %ebp
cmpl $0x0, 0x4(%rsp)
je 0x46cf40
movl 0x54(%r12), %edx
movq %r13, %rdi
movl $0x18, %esi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x43bae0
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x46cef0
movq 0x68(%r13), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x1, 0x10(%rcx,%rax,8)
movl 0x54(%r12), %edx
movq %r13, %rdi
movl $0x7c, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl 0xb8(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x137eeb(%rip), %rcx    # 0x5a4e08
jne 0x46cf3b
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 0x68(%r13), %rcx
movl %eax, 0x8(%rcx)
jmp 0x46cfab
movl 0x58(%r12), %edx
incl %edx
movq %r13, %rdi
movl $0x53, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movl 0x58(%r12), %ecx
movq %r13, %rdi
movl $0x4f, %esi
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x43bae0
movl 0x58(%r12), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
movl $0x66, %esi
movl $0x2, %ecx
callq 0x43bae0
movl 0x54(%r12), %edx
movl 0x58(%r12), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x85, %esi
xorl %r8d, %r8d
callq 0x43bae0
movl 0xb8(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x137e47(%rip), %rcx    # 0x5a4e08
jne 0x46d15b
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
jmp 0x46d14c
movl $0x0, 0x1c(%rsp)
jmp 0x46d062
leal (%rbx,%rbp), %edx
jmp 0x46d012
movl 0x38(%rcx), %eax
incl %eax
movl %eax, 0x38(%rcx)
movl %eax, 0x8(%rsp)
movl 0x6c(%r12), %ecx
addl %ebp, %ecx
movq %r13, %rdi
movl $0x5a, %esi
movl %r15d, %edx
movl 0x8(%rsp), %r8d
callq 0x43bae0
movl 0x8(%rsp), %edx
movl %edx, 0x8(%rsp)
movq %r13, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x43bae0
testl %r15d, %r15d
movl %eax, 0x1c(%rsp)
jle 0x46d062
movl 0x8(%rsp), %edi
testl %edi, %edi
movq 0x10(%rsp), %rcx
je 0x46d062
movzbl 0x1f(%rcx), %esi
cmpq $0x7, %rsi
ja 0x46d062
leal 0x1(%rsi), %ecx
movq 0x10(%rsp), %rdx
movb %cl, 0x1f(%rdx)
movq 0x10(%rsp), %rcx
movl %edi, 0xc4(%rcx,%rsi,4)
movq 0x40(%r12), %rax
testb $0x20, 0x4(%rax)
je 0x46d0c2
movq 0x60(%r12), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x43cd2e
testq %rax, %rax
jne 0x46d095
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
movl $0x52, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43bae0
movq %r13, %rdi
movl %eax, %esi
movq 0x8(%rsp), %rdx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x40e507
movl 0x4c(%r12), %r8d
movq %r13, %rdi
movl 0x20(%rsp), %esi
movl 0x4(%rsp), %edx
movl %ebx, %ecx
callq 0x43bae0
movq 0x40(%r12), %rsi
movq (%r13), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x46d0f5
testb $0x10, 0x4(%rsi)
je 0x46d10e
callq 0x415dca
jmp 0x46d10e
movq 0x68(%r13), %rax
movslq 0xb8(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x8, -0x17(%rax,%rcx,8)
movq %rsi, -0x8(%rax,%rcx,8)
movslq 0xb8(%r13), %rax
testq %rax, %rax
jle 0x46d12b
movzbl %bpl, %ecx
movq 0x68(%r13), %rdx
leaq (%rax,%rax,2), %rsi
movw %cx, -0x16(%rdx,%rsi,8)
movl 0x1c(%rsp), %edx
testl %edx, %edx
je 0x46d15e
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x137cc6(%rip), %rcx    # 0x5a4e08
jne 0x46d15b
leal -0x1(%rax), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x68(%r13), %rcx
movl %eax, 0x8(%rcx)
movq 0x30(%r12), %r12
testq %r12, %r12
jne 0x46cd71
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq