// File: /workspace/github_c_makefile_star2_O3/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, 0xc(%rsp)
movl %r8d, %r14d
movl %ecx, %r15d
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
callq 0x44dbe5
testq %r12, %r12
je 0x46ca38
movl %ebx, %r9d
movq %rax, %r13
xorl %eax, %eax
cmpl $0x1, %r15d
adcl $0x9a, %eax
movl %eax, 0x1c(%rsp)
movl %ebx, (%rsp)
movl %r15d, 0x4(%rsp)
movq %r14, 0x20(%rsp)
movq 0x40(%r12), %rax
movq 0x60(%r12), %rcx
movl 0x4(%rax), %ebx
movq 0x20(%rcx), %rax
testq %rax, %rax
je 0x46c636
movl (%rax), %ebp
testl %r9d, %r9d
js 0x46c689
testl %ebp, %ebp
movq %r14, %r15
jle 0x46c623
xorl %r14d, %r14d
movl 0x6c(%r12), %ecx
addl %r14d, %ecx
leal (%r15,%r14), %r8d
movq %r13, %rdi
movl $0x5a, %esi
movl %r9d, %edx
callq 0x43a65f
movl (%rsp), %r9d
incl %r14d
cmpl %r14d, %ebp
jne 0x46c5fb
btl $0x11, %ebx
jb 0x46c654
movq %r15, %r14
movl %r14d, %ebx
movl 0x4(%rsp), %r15d
jmp 0x46c691
testl %r9d, %r9d
js 0x46c687
andl $0x20000, %ebx          # imm = 0x20000
movl %ebx, %ebp
shrl $0x11, %ebp
testl %ebx, %ebx
movl 0xc(%rsp), %eax
movl %eax, %ebx
cmovel %r14d, %ebx
jmp 0x46c691
testl %ebp, %ebp
movq %r15, %r14
movl 0x4(%rsp), %r15d
je 0x46c883
leal (%r14,%rbp), %ecx
movq %r13, %rdi
movl $0x4f, %esi
movl 0xc(%rsp), %edx
xorl %r8d, %r8d
callq 0x43a65f
movl (%rsp), %r9d
incl %ebp
movl %r14d, %ebx
jmp 0x46c691
xorl %ebp, %ebp
movl 0x6c(%r12), %ebx
addl %r14d, %ebx
movq 0x40(%r12), %rax
testb $0x10, 0x5(%rax)
je 0x46c6a8
cmpb $0x57, 0x19(%r12)
jne 0x46c734
movl 0x58(%r12), %edx
testl %edx, %edx
je 0x46c6d4
subl %r15d, %edx
incl %edx
movq %r13, %rdi
movl $0x53, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x43a65f
movl (%rsp), %r9d
jmp 0x46ca2a
movq 0x38(%rax), %rax
leaq 0xe3859(%rip), %rcx     # 0x54ff38
cmpq %rcx, %rax
sete %cl
leaq 0xe3851(%rip), %rdx     # 0x54ff3d
cmpq %rdx, %rax
sete %al
orb %cl, %al
jne 0x46ca2a
cmpq $0x0, 0x38(%r12)
je 0x46c893
testl %r9d, %r9d
jle 0x46c8a0
movq 0x10(%rsp), %rcx
movb 0x1f(%rcx), %al
testb %al, %al
je 0x46c8be
decb %al
movb %al, 0x1f(%rcx)
movzbl %al, %eax
movl 0xc4(%rcx,%rax,4), %r15d
jmp 0x46c8c9
movq %r13, %rdi
movl $0x32, %esi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43a65f
movl %eax, %ebp
testl %r15d, %r15d
je 0x46c7dc
movl 0x54(%r12), %edx
movq %r13, %rdi
movl $0x18, %esi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x43a65f
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x46c78b
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 0x43a65f
movl 0xb8(%r13), %eax
movq (%r13), %rcx
movb 0x61(%rcx), %cl
leaq 0x138651(%rip), %rdx    # 0x5a4e08
testb %cl, %cl
jne 0x46c7d7
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 0x68(%r13), %rdx
movl %eax, 0x8(%rdx)
jmp 0x46c855
movl 0x58(%r12), %edx
incl %edx
movq %r13, %rdi
movl $0x53, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x43a65f
movl 0x58(%r12), %ecx
movq %r13, %rdi
movl $0x4f, %esi
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x43a65f
movl 0x58(%r12), %edx
leal 0x2(%rdx), %r8d
movq %r13, %rdi
movl $0x66, %esi
movl $0x2, %ecx
callq 0x43a65f
movl 0x54(%r12), %edx
movl 0x58(%r12), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0x85, %esi
xorl %r8d, %r8d
callq 0x43a65f
movl 0xb8(%r13), %eax
movq (%r13), %rcx
movb 0x61(%rcx), %cl
movl (%rsp), %r9d
leaq 0x1385a8(%rip), %rdx    # 0x5a4e08
testb %cl, %cl
jne 0x46c87b
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x68(%r13), %rdx
movl %eax, 0x8(%rdx)
jmp 0x46ca2a
movl $0x1, %ebp
movl 0xc(%rsp), %eax
movl %eax, %ebx
jmp 0x46c691
movl $0x0, 0x8(%rsp)
jmp 0x46c926
leal (%rbx,%rbp), %edx
movq %r13, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x43a65f
movl %eax, 0x8(%rsp)
jmp 0x46c926
movl 0x38(%rcx), %r15d
incl %r15d
movl %r15d, 0x38(%rcx)
movl 0x6c(%r12), %ecx
addl %ebp, %ecx
movq %r13, %rdi
movl $0x5a, %esi
movl %r9d, %edx
movl %r15d, %r8d
callq 0x43a65f
movq %r13, %rdi
movl $0x14, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x43a65f
testl %r15d, %r15d
movl %eax, 0x8(%rsp)
je 0x46c921
movq 0x10(%rsp), %rdx
movzbl 0x1f(%rdx), %esi
cmpq $0x7, %rsi
ja 0x46c921
leal 0x1(%rsi), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xc4(%rdx,%rsi,4)
movl 0x4(%rsp), %r15d
movq 0x40(%r12), %rax
testb $0x20, 0x4(%rax)
je 0x46c987
movq 0x60(%r12), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x43b88c
movq %rax, %r14
testq %rax, %rax
jne 0x46c95c
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r14
movq %r13, %rdi
movl $0x52, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43a65f
movq %r13, %rdi
movl %eax, %esi
movq %r14, %rdx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x40e765
movq 0x20(%rsp), %r14
movl 0x4c(%r12), %r8d
movq %r13, %rdi
movl 0x1c(%rsp), %esi
movl %r15d, %edx
movl %ebx, %ecx
callq 0x43a65f
movq 0x40(%r12), %rsi
movq (%r13), %rdi
cmpb $0x0, 0x61(%rdi)
je 0x46c9bd
testb $0x10, 0x4(%rsi)
movl (%rsp), %r9d
je 0x46c9da
callq 0x415f0a
jmp 0x46c9d6
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)
movl (%rsp), %r9d
movslq 0xb8(%r13), %rax
testq %rax, %rax
jle 0x46c9f7
movzbl %bpl, %ecx
movq 0x68(%r13), %rdx
leaq (%rax,%rax,2), %rsi
movw %cx, -0x16(%rdx,%rsi,8)
movl 0x8(%rsp), %edx
testl %edx, %edx
je 0x46ca2a
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
leaq 0x1383fa(%rip), %rcx    # 0x5a4e08
jne 0x46ca27
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 0x46c5d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq