// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x4c, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x42d540
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x2, -0x14(%rbp)
jne 0x4582a1
movq -0x38(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x5a, %eax
jne 0x4582a1
movl $0x0, -0x4(%rbp)
jmp 0x4586c4
cmpl $0x0, -0x18(%rbp)
jle 0x458369
movq -0x38(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x59, %eax
jne 0x45834d
movq -0x48(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x58(%rbp)
cmpl $0x2, -0x14(%rbp)
jne 0x458327
movq -0x38(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x56, %eax
jne 0x458301
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edx
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x28(%rax), %r8d
movl -0x54(%rbp), %r9d
movl $0x37, %esi
callq 0x4586d0
jmp 0x458325
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edx
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x30(%rax), %r8d
movl -0x54(%rbp), %r9d
movl $0x39, %esi
callq 0x4586d0
jmp 0x45834b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x30(%rax), %r8d
movl -0x54(%rbp), %r9d
movl $0x36, %esi
callq 0x4586d0
jmp 0x458367
movq -0x48(%rbp), %rdi
movl -0x18(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x30, %esi
movl $0x1, %r8d
callq 0x410130
jmp 0x458369
cmpl $0x1, -0x14(%rbp)
jne 0x458387
movq -0x38(%rbp), %rax
cmpl $0x0, 0x84(%rax)
jne 0x458387
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x457ba0
movq -0x48(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x21(%rax), %eax
movq -0x38(%rbp), %rcx
movzbl 0x22(%rcx), %ecx
cmpl %ecx, %eax
jne 0x458440
cmpl $0x0, -0x18(%rbp)
je 0x458440
movq -0x38(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x59, %eax
jne 0x458440
cmpl $0x2, -0x14(%rbp)
jne 0x458440
movq -0x30(%rbp), %rdi
callq 0x42f190
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rdi
callq 0x42f190
movl %eax, -0x60(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edx
movl -0x5c(%rbp), %ecx
movl $0x7f, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
movl -0x60(%rbp), %ecx
movl $0x7f, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x60(%rbp), %edx
movl -0x54(%rbp), %ecx
movl -0x5c(%rbp), %r8d
movl $0x39, %esi
callq 0x410130
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x42e560
movq -0x30(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x42e560
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x1, %eax
je 0x45845a
jmp 0x45844d
movl -0x6c(%rbp), %eax
subl $0x2, %eax
je 0x45847c
jmp 0x4584db
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x457d60
jmp 0x458537
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x84(%rax)
je 0x4584bc
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x84(%rax), %edx
movl $0x52, %esi
movl $0x1, %ecx
callq 0x410100
jmp 0x4584d9
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x20(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %r8d
movl $0x1, %ecx
callq 0x458dc0
jmp 0x458537
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x84(%rax)
je 0x45851b
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x88(%rax), %edx
movl $0x52, %esi
movl $0x1, %ecx
callq 0x410100
jmp 0x458535
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x20(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %r8d
xorl %ecx, %ecx
callq 0x458dc0
jmp 0x458537
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jne 0x458562
movq -0x48(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x7a, %esi
callq 0x42ba70
movq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x3cb9f0
cmpl $0x0, -0x1c(%rbp)
je 0x4585a8
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rdi
callq 0x430ae0
movq -0x78(%rbp), %rdi
movl -0x70(%rbp), %edx
movl %eax, %ecx
addl $0x2, %ecx
movl $0x5, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl $0xb, %esi
callq 0x429a40
movl %eax, -0x3c(%rbp)
jmp 0x4585f9
movq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x48(%rbp), %rdi
callq 0x430ae0
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl %eax, %ecx
addl $0x1, %ecx
addl -0x50(%rbp), %ecx
movl $0x5, %esi
callq 0x410100
cmpl $0x0, -0x50(%rbp)
je 0x4585f7
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %ecx
movl $0xb, %esi
xorl %edx, %edx
callq 0x410100
jmp 0x4585f9
cmpl $0x0, -0x50(%rbp)
je 0x458699
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x458620
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x45862a
xorl %eax, %eax
movl %eax, -0x8c(%rbp)
jmp 0x45862a
movl -0x8c(%rbp), %eax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x45864d
movq -0x30(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x42cb30
movl %eax, -0x90(%rbp)
jmp 0x458657
xorl %eax, %eax
movl %eax, -0x90(%rbp)
jmp 0x458657
movl -0x90(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x68(%rbp), %edx
callq 0x458cf0
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0x68(%rbp), %edx
movl -0x24(%rbp), %ecx
movl -0x4c(%rbp), %r8d
callq 0x458110
movq -0x30(%rbp), %rdi
movl -0x68(%rbp), %esi
movl -0x64(%rbp), %edx
callq 0x42d0c0
cmpl $0x0, -0x58(%rbp)
je 0x4586b2
movq -0x48(%rbp), %rdi
movl -0x58(%rbp), %ecx
movl $0xb, %esi
xorl %edx, %edx
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x42dc90
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq