// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movl %esi, %r14d
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
movq %rax, 0x18(%rsp)
movl %r12d, 0x44(%rax)
cmpl $0x2, %r14d
jne 0x2df047
xorl %r15d, %r15d
cmpb $0x5a, 0x21(%rsi)
je 0x2df43d
movl $0x0, 0x28(%rsp)
testl %ebp, %ebp
movq %rsi, 0x10(%rsp)
jle 0x2df0c0
cmpb $0x59, 0xc(%rsp)
jne 0x2df087
movl 0x90(%rbx), %eax
movl %eax, 0x28(%rsp)
cmpl $0x2, %r14d
jne 0x2df0a1
cmpb $0x56, 0x21(%rsi)
jne 0x2df0e0
movl 0x28(%r13), %r8d
movl 0x30(%r13), %edx
movq %r13, %rdi
movl $0x37, %esi
jmp 0x2df0f0
movq %rbx, %rdi
movl $0x30, %esi
movl %ebp, %edx
movl %r12d, %ecx
movl $0x1, %r8d
callq 0x2a83e1
jmp 0x2df0bb
movl 0x30(%r13), %r8d
movl 0x38(%r13), %edx
movq %r13, %rdi
movl $0x36, %esi
movl %ebp, %ecx
movl %r12d, %r9d
callq 0x2df44f
movq 0x10(%rsp), %rsi
cmpl $0x1, %r14d
jne 0x2df0ff
cmpl $0x0, 0x84(%rsi)
jne 0x2df0ff
movq (%r13), %rdi
movq 0x8(%r13), %rsi
xorl %edx, %edx
callq 0x2de55c
jmp 0x2df0fa
movl 0x28(%r13), %edx
movl 0x30(%r13), %r8d
movq %r13, %rdi
movl $0x39, %esi
movl %ebp, %ecx
movl %r12d, %r9d
callq 0x2df44f
movq 0x10(%rsp), %rsi
movl 0x90(%rbx), %eax
movl %eax, 0x30(%rsp)
testl %ebp, %ebp
je 0x2df153
movb 0x22(%rsi), %al
cmpb %al, 0x21(%rsi)
jne 0x2df153
cmpl $0x2, %r14d
jne 0x2df153
cmpb $0x59, 0x20(%rsi)
jne 0x2df153
movq 0x18(%rsp), %rdx
movb 0x1f(%rdx), %al
testb %al, %al
je 0x2df19c
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movzbl %cl, %ecx
movl 0xd4(%rdx,%rcx,4), %r15d
testb %cl, %cl
je 0x2df1b7
addb $-0x2, %al
movb %al, 0x1f(%rdx)
movzbl %al, %eax
movl 0xd4(%rdx,%rax,4), %ebp
jmp 0x2df1bf
cmpl $0x2, %r14d
je 0x2df252
cmpl $0x1, %r14d
jne 0x2df17c
movl 0x30(%r13), %r15d
movl 0x34(%r13), %eax
movl %eax, 0x24(%rsp)
movq %r13, %rdi
callq 0x2de730
jmp 0x2df293
movl 0x38(%r13), %r15d
movl 0x3c(%r13), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x84(%rsi)
je 0x2df1a6
movl 0x88(%rsi), %edx
jmp 0x2df268
movl 0x38(%rdx), %ebp
incl %ebp
movl %ebp, %r15d
jmp 0x2df1ba
movl 0x20(%r13), %r8d
movq %r13, %rdi
movl %r15d, %edx
xorl %ecx, %ecx
jmp 0x2df28e
movl 0x38(%rdx), %ebp
incl %ebp
movl %ebp, 0x38(%rdx)
movl 0x28(%r13), %edx
movq %rbx, %rdi
movl $0x7f, %esi
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x38(%r13), %edx
movq %rbx, %rdi
movl $0x7f, %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbx, %rdi
movl $0x39, %esi
movl %ebp, %edx
movl %r12d, %ecx
movl %r15d, %r8d
callq 0x2a83e1
testl %r15d, %r15d
je 0x2df228
movq 0x18(%rsp), %rax
movzbl 0x1f(%rax), %eax
cmpq $0x7, %rax
ja 0x2df228
leal 0x1(%rax), %ecx
movq 0x18(%rsp), %rdx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xd4(%rdx,%rax,4)
testl %ebp, %ebp
movq 0x10(%rsp), %rsi
je 0x2df252
movq 0x18(%rsp), %rax
movzbl 0x1f(%rax), %eax
cmpq $0x7, %rax
ja 0x2df252
leal 0x1(%rax), %ecx
movq 0x18(%rsp), %rdx
movb %cl, 0x1f(%rdx)
movl %ebp, 0xd4(%rdx,%rax,4)
movl 0x28(%r13), %r15d
movl 0x2c(%r13), %eax
movl %eax, 0x24(%rsp)
movl 0x84(%rsi), %edx
testl %edx, %edx
je 0x2df27f
movq %rbx, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
jmp 0x2df293
movl 0x20(%r13), %r8d
movq %r13, %rdi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x2df7c7
cmpl %r14d, 0x24(%r13)
jne 0x2df2ce
movq %rbx, %rdi
movl $0x7a, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movslq 0x90(%rbx), %rcx
testq %rcx, %rcx
jle 0x2df2d4
movq 0x88(%rbx), %rax
leaq (%rcx,%rcx,2), %rdx
movw $0x2, -0x16(%rax,%rdx,8)
jmp 0x2df2d4
movl 0x90(%rbx), %ecx
cmpl $0x0, 0x34(%rsp)
movl %r15d, 0x2c(%rsp)
je 0x2df319
addl $0x2, %ecx
movq %rbx, %rdi
movl $0x5, %esi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, %r15d
cmpb $0x4c, 0xc(%rsp)
jne 0x2df364
jmp 0x2df418
xorl %eax, %eax
movb 0xc(%rsp), %bpl
cmpb $0x4c, %bpl
sete %al
subl %eax, %ecx
addl $0x2, %ecx
movl %r15d, %edx
xorl %r15d, %r15d
movq %rbx, %rdi
movl $0x5, %esi
xorl %r8d, %r8d
callq 0x2a83e1
cmpb $0x4c, %bpl
je 0x2df418
xorl %r15d, %r15d
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %r12d, 0xc(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x2df39a
movl (%rax), %ebp
movl $0x0, %r14d
testl %ebp, %ebp
je 0x2df39d
movq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x2beb15
movl %eax, %r14d
movl %ebp, %r12d
jmp 0x2df39d
xorl %r14d, %r14d
movq %r13, %rdi
movl 0x2c(%rsp), %esi
movl %r14d, %edx
callq 0x2df754
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r14d, %edx
movl 0x24(%rsp), %ecx
movl 0x30(%rsp), %r8d
callq 0x2def1c
cmpl $0x1, %r12d
jne 0x2df3fa
testl %r14d, %r14d
je 0x2df413
movzbl 0x1f(%r13), %eax
cmpq $0x7, %rax
movl 0xc(%rsp), %r12d
ja 0x2df418
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
leaq 0xd4(%r13,%rax,4), %r13
jmp 0x2df40d
cmpl %r12d, 0x28(%r13)
jge 0x2df413
movl %r12d, 0x28(%r13)
addq $0x2c, %r13
movl 0xc(%rsp), %r12d
movl %r14d, (%r13)
jmp 0x2df418
movl 0xc(%rsp), %r12d
movl 0x28(%rsp), %ecx
testl %ecx, %ecx
je 0x2df432
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2bfa39
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq