// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: windowCodeOp
static int windowCodeOp(
 WindowCodeArg *p,                /* Context object */
 int op,                          /* WINDOW_RETURN_ROW, AGGSTEP or AGGINVERSE */
 int regCountdown,                /* Register for OP_IfPos countdown */
 int jumpOnEof                    /* Jump here if stepped cursor reaches EOF */
){
  int csr, reg;
  Parse *pParse = p->pParse;
  Window *pMWin = p->pMWin;
  int ret = 0;
  Vdbe *v = p->pVdbe;
  int addrContinue = 0;
  int bPeer = (pMWin->eFrmType!=TK_ROWS);

  int lblDone = sqlite3VdbeMakeLabel(pParse);
  int addrNextRange = 0;

  /* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
  ** starts with UNBOUNDED PRECEDING. */
  if( op==WINDOW_AGGINVERSE && pMWin->eStart==TK_UNBOUNDED ){
    assert( regCountdown==0 && jumpOnEof==0 );
    return 0;
  }

  if( regCountdown>0 ){
    if( pMWin->eFrmType==TK_RANGE ){
      addrNextRange = sqlite3VdbeCurrentAddr(v);
      assert( op==WINDOW_AGGINVERSE || op==WINDOW_AGGSTEP );
      if( op==WINDOW_AGGINVERSE ){
        if( pMWin->eStart==TK_FOLLOWING ){
          windowCodeRangeTest(
              p, OP_Le, p->current.csr, regCountdown, p->start.csr, lblDone
          );
        }else{
          windowCodeRangeTest(
              p, OP_Ge, p->start.csr, regCountdown, p->current.csr, lblDone
          );
        }
      }else{
        windowCodeRangeTest(
            p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
        );
      }
    }else{
      sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, lblDone, 1);
      VdbeCoverage(v);
    }
  }

  if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
    windowAggFinal(p, 0);
  }
  addrContinue = sqlite3VdbeCurrentAddr(v);

  /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
  ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
  ** start cursor does not advance past the end cursor within the
  ** temporary table. It otherwise might, if (a>b).  */
  if( pMWin->eStart==pMWin->eEnd && regCountdown
   && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
  ){
    int regRowid1 = sqlite3GetTempReg(pParse);
    int regRowid2 = sqlite3GetTempReg(pParse);
    sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
    sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
    sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
    VdbeCoverage(v);
    sqlite3ReleaseTempReg(pParse, regRowid1);
    sqlite3ReleaseTempReg(pParse, regRowid2);
    assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
  }

  switch( op ){
    case WINDOW_RETURN_ROW:
      csr = p->current.csr;
      reg = p->current.reg;
      windowReturnOneRow(p);
      break;

    case WINDOW_AGGINVERSE:
      csr = p->start.csr;
      reg = p->start.reg;
      if( pMWin->regStartRowid ){
        assert( pMWin->regEndRowid );
        sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
      }else{
        windowAggStep(p, pMWin, csr, 1, p->regArg);
      }
      break;

    default:
      assert( op==WINDOW_AGGSTEP );
      csr = p->end.csr;
      reg = p->end.reg;
      if( pMWin->regStartRowid ){
        assert( pMWin->regEndRowid );
        sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
      }else{
        windowAggStep(p, pMWin, csr, 0, p->regArg);
      }
      break;
  }

  if( op==p->eDelete ){
    sqlite3VdbeAddOp1(v, OP_Delete, csr);
    sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
  }

  if( jumpOnEof ){
    sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+2);
    VdbeCoverage(v);
    ret = sqlite3VdbeAddOp0(v, OP_Goto);
  }else{
    sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
    VdbeCoverage(v);
    if( bPeer ){
      sqlite3VdbeAddOp2(v, OP_Goto, 0, lblDone);
    }
  }

  if( bPeer ){
    int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
    int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
    windowReadPeerValues(p, csr, regTmp);
    windowIfNewPeer(pParse, pMWin->pOrderBy, regTmp, reg, addrContinue);
    sqlite3ReleaseTempRange(pParse, regTmp, nReg);
  }

  if( addrNextRange ){
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
  }
  sqlite3VdbeResolveLabel(v, lblDone);
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x34(%rsp)
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %r13
movq (%rdi), %rax
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rbx
movb 0x20(%rsi), %cl
movb %cl, 0xc(%rsp)
movl 0x44(%rax), %r12d
decl %r12d
movl %r12d, 0x44(%rax)
cmpl $0x2, %r15d
jne 0x27d65b
xorl %ebp, %ebp
cmpb $0x5a, 0x21(%rsi)
je 0x27d99b
movl $0x0, 0x28(%rsp)
testl %r14d, %r14d
movq %rax, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
jle 0x27d6d0
cmpb $0x59, 0xc(%rsp)
jne 0x27d69b
movl 0x90(%rbx), %eax
cmpl $0x2, %r15d
movl %eax, 0x28(%rsp)
jne 0x27d6b2
cmpb $0x56, 0x21(%rsi)
jne 0x27d6eb
movl 0x28(%r13), %r8d
movl 0x30(%r13), %edx
pushq $0x37
jmp 0x27d6f5
pushq $0x30
popq %rsi
pushq $0x1
popq %r8
movq %rbx, %rdi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x24d51f
jmp 0x27d6cb
movl 0x30(%r13), %r8d
movl 0x38(%r13), %edx
pushq $0x36
popq %rsi
movq %r13, %rdi
movl %r14d, %ecx
movl %r12d, %r9d
callq 0x27d9ac
movq 0x10(%rsp), %rsi
cmpl $0x1, %r15d
jne 0x27d709
cmpl $0x0, 0x84(%rsi)
jne 0x27d709
movq %r13, %rdi
xorl %esi, %esi
callq 0x27cda0
jmp 0x27d704
movl 0x28(%r13), %edx
movl 0x30(%r13), %r8d
pushq $0x39
popq %rsi
movq %r13, %rdi
movl %r14d, %ecx
movl %r12d, %r9d
callq 0x27d9ac
movq 0x10(%rsp), %rsi
movl 0x90(%rbx), %eax
movl %eax, 0x30(%rsp)
testl %r14d, %r14d
je 0x27d7cf
movb 0x22(%rsi), %al
cmpb %al, 0x21(%rsi)
jne 0x27d7cf
cmpl $0x2, %r15d
jne 0x27d7cf
cmpb $0x59, 0x20(%rsi)
jne 0x27d7cf
movq 0x20(%rsp), %rdi
callq 0x267d61
movl %eax, %r14d
movq 0x20(%rsp), %rdi
callq 0x267d61
movl %eax, %ebp
movl 0x28(%r13), %edx
pushq $0x7f
popq %rsi
movq %rbx, %rdi
movl %r14d, %ecx
callq 0x24d51a
movl 0x38(%r13), %edx
movq %rbx, %rdi
pushq $0x7f
popq %rsi
movl %ebp, %ecx
callq 0x24d51a
pushq $0x39
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0x24d51f
movq 0x20(%rsp), %rdx
testl %r14d, %r14d
je 0x27d7ad
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x27d7ad
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r14d, 0xd4(%rdx,%rax,4)
testl %ebp, %ebp
movq 0x10(%rsp), %rsi
je 0x27d7f1
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x27d7f1
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %ebp, 0xd4(%rdx,%rax,4)
jmp 0x27d7f1
cmpl $0x2, %r15d
je 0x27d7f1
cmpl $0x1, %r15d
jne 0x27d815
movl 0x30(%r13), %ebp
movl 0x34(%r13), %eax
movl %eax, 0x1c(%rsp)
movq %r13, %rdi
callq 0x27cee8
jmp 0x27d850
movl 0x28(%r13), %ebp
movl 0x2c(%r13), %eax
movl %eax, 0x1c(%rsp)
movl 0x84(%rsi), %edx
testl %edx, %edx
jne 0x27d830
movl 0x20(%r13), %r8d
pushq $0x1
popq %rcx
movq %r13, %rdi
movl %ebp, %edx
jmp 0x27d84b
movl 0x38(%r13), %ebp
movl 0x3c(%r13), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x84(%rsi)
je 0x27d840
movl 0x88(%rsi), %edx
pushq $0x52
popq %rsi
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0x24d51a
jmp 0x27d850
movl 0x20(%r13), %r8d
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x27dc56
cmpl %r15d, 0x24(%r13)
jne 0x27d883
pushq $0x7a
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x265d5c
movslq 0x90(%rbx), %rcx
testq %rcx, %rcx
jle 0x27d889
movq 0x88(%rbx), %rax
imulq $0x18, %rcx, %rdx
movw $0x2, -0x16(%rax,%rdx)
jmp 0x27d889
movl 0x90(%rbx), %ecx
cmpl $0x0, 0x34(%rsp)
movl %ebp, 0x2c(%rsp)
je 0x27d8bd
addl $0x2, %ecx
pushq $0x5
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x24d51a
pushq $0xb
popq %rsi
movq %rbx, %rdi
callq 0x2645ec
movl %eax, %ebp
cmpb $0x4c, 0xc(%rsp)
jne 0x27d8fb
jmp 0x27d97b
xorl %eax, %eax
movb 0xc(%rsp), %r14b
cmpb $0x4c, %r14b
sete %al
subl %eax, %ecx
addl $0x2, %ecx
pushq $0x5
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x24d51a
xorl %ebp, %ebp
cmpb $0x4c, %r14b
je 0x27d97b
pushq $0xb
popq %rsi
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x24d51a
movl %r12d, 0xc(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x27d934
movl (%rax), %r15d
movl $0x0, %r14d
testl %r15d, %r15d
je 0x27d937
movq 0x20(%rsp), %rdi
movl %r15d, %esi
callq 0x266492
movl %eax, %r14d
movl %r15d, %r12d
jmp 0x27d937
xorl %r14d, %r14d
movq %r13, %rdi
movl 0x2c(%rsp), %esi
movl %r14d, %edx
callq 0x27dbe4
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x20(%rsp), %r15
movq %r15, %rdi
movl %r14d, %edx
movl 0x1c(%rsp), %ecx
movl 0x30(%rsp), %r8d
callq 0x27d555
movq %r15, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x2666df
movl 0xc(%rsp), %r12d
movl 0x28(%rsp), %ecx
testl %ecx, %ecx
je 0x27d990
pushq $0xb
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x24d51a
movq %rbx, %rdi
movl %r12d, %esi
callq 0x266fe1
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq