// File: /workspace/github_c_makefile_star2_O1/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, %r8d
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), %r9d
decl %r9d
movq %rax, 0x10(%rsp)
movl %r9d, 0x44(%rax)
cmpl $0x2, %r15d
jne 0x2e82f9
xorl %ebp, %ebp
cmpb $0x5a, 0x21(%rsi)
je 0x2e86e1
movl %r8d, 0x34(%rsp)
xorl %r12d, %r12d
testl %r14d, %r14d
movq %rsi, 0x18(%rsp)
movl %r9d, 0x28(%rsp)
jle 0x2e8386
cmpb $0x59, 0xc(%rsp)
jne 0x2e833c
movl 0x90(%rbx), %r12d
cmpl $0x2, %r15d
jne 0x2e8357
cmpb $0x56, 0x21(%rsi)
jne 0x2e8369
movl 0x28(%r13), %r8d
movl 0x30(%r13), %edx
movq %r13, %rdi
movl $0x37, %esi
jmp 0x2e8379
movq %rbx, %rdi
movl $0x30, %esi
movl %r14d, %edx
movl %r9d, %ecx
movl $0x1, %r8d
callq 0x2b200c
jmp 0x2e8381
movl 0x30(%r13), %r8d
movl 0x38(%r13), %edx
movq %r13, %rdi
movl $0x36, %esi
jmp 0x2e8379
movl 0x28(%r13), %edx
movl 0x30(%r13), %r8d
movq %r13, %rdi
movl $0x39, %esi
movl %r14d, %ecx
callq 0x2e86f2
movq 0x18(%rsp), %rsi
cmpl $0x1, %r15d
jne 0x2e83a4
cmpl $0x0, 0x84(%rsi)
jne 0x2e83a4
movq %r13, %rdi
xorl %esi, %esi
callq 0x2e780e
movq 0x18(%rsp), %rsi
movl 0x90(%rbx), %eax
movl %eax, 0x30(%rsp)
testl %r14d, %r14d
je 0x2e84b5
movb 0x22(%rsi), %al
cmpb %al, 0x21(%rsi)
jne 0x2e84b5
cmpl $0x2, %r15d
jne 0x2e84b5
cmpb $0x59, 0x20(%rsi)
jne 0x2e84b5
movq 0x10(%rsp), %rcx
movb 0x1f(%rcx), %al
testb %al, %al
je 0x2e83f4
decb %al
movb %al, 0x1f(%rcx)
movzbl %al, %eax
movl 0xd4(%rcx,%rax,4), %ebp
jmp 0x2e83fc
movl 0x38(%rcx), %ebp
incl %ebp
movl %ebp, 0x38(%rcx)
movb 0x1f(%rcx), %al
testb %al, %al
je 0x2e8415
decb %al
movb %al, 0x1f(%rcx)
movzbl %al, %eax
movl 0xd4(%rcx,%rax,4), %r14d
jmp 0x2e8420
movl 0x38(%rcx), %r14d
incl %r14d
movl %r14d, 0x38(%rcx)
movl 0x28(%r13), %edx
movq %rbx, %rdi
movl $0x7f, %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x38(%r13), %edx
movq %rbx, %rdi
movl $0x7f, %esi
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %rbx, %rdi
movl $0x39, %esi
movl %r14d, %edx
movl 0x28(%rsp), %ecx
movl %ebp, %r8d
callq 0x2b200c
testl %ebp, %ebp
je 0x2e8489
movq 0x10(%rsp), %rax
movzbl 0x1f(%rax), %eax
cmpq $0x7, %rax
ja 0x2e8489
leal 0x1(%rax), %ecx
movq 0x10(%rsp), %rdx
movb %cl, 0x1f(%rdx)
movl %ebp, 0xd4(%rdx,%rax,4)
testl %r14d, %r14d
movq 0x18(%rsp), %rsi
je 0x2e84b5
movq 0x10(%rsp), %rax
movzbl 0x1f(%rax), %eax
cmpq $0x7, %rax
ja 0x2e84b5
leal 0x1(%rax), %ecx
movq 0x10(%rsp), %rdx
movb %cl, 0x1f(%rdx)
movl %r14d, 0xd4(%rdx,%rax,4)
cmpl $0x2, %r15d
je 0x2e84d7
cmpl $0x1, %r15d
jne 0x2e84fd
movl 0x30(%r13), %ebp
movl 0x34(%r13), %eax
movl %eax, 0x24(%rsp)
movq %r13, %rdi
callq 0x2e79e9
jmp 0x2e853f
movl 0x28(%r13), %ebp
movl 0x2c(%r13), %eax
movl %eax, 0x24(%rsp)
movl 0x84(%rsi), %edx
testl %edx, %edx
jne 0x2e8518
movl 0x20(%r13), %r8d
movq %r13, %rdi
movl %ebp, %edx
movl $0x1, %ecx
jmp 0x2e853a
movl 0x38(%r13), %ebp
movl 0x3c(%r13), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x84(%rsi)
je 0x2e852f
movl 0x88(%rsi), %edx
movq %rbx, %rdi
movl $0x52, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2b200c
jmp 0x2e853f
movl 0x20(%r13), %r8d
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x2e8a6f
cmpl %r15d, 0x24(%r13)
jne 0x2e8577
movq %rbx, %rdi
movl $0x7a, %esi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x2e8577
movq 0x88(%rbx), %rcx
leaq (%rax,%rax,2), %rax
movw $0x2, -0x16(%rcx,%rax,8)
movl 0x90(%rbx), %ecx
cmpl $0x0, 0x34(%rsp)
movl %ebp, 0x2c(%rsp)
je 0x2e85b5
addl $0x2, %ecx
movq %rbx, %rdi
movl $0x5, %esi
movl %ebp, %edx
xorl %r8d, %r8d
callq 0x2b200c
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl %eax, %ebp
jmp 0x2e85fa
xorl %eax, %eax
movb 0xc(%rsp), %r14b
cmpb $0x4c, %r14b
sete %al
subl %eax, %ecx
addl $0x2, %ecx
movl %ebp, %edx
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x5, %esi
xorl %r8d, %r8d
callq 0x2b200c
cmpb $0x4c, %r14b
je 0x2e85fa
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
movl 0x28(%rsp), %ecx
xorl %r8d, %r8d
callq 0x2b200c
cmpb $0x4c, 0xc(%rsp)
je 0x2e86bb
movl %r12d, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
xorl %r14d, %r14d
movl $0x0, %r15d
testq %rax, %rax
je 0x2e8624
movl (%rax), %r15d
testl %r15d, %r15d
movq 0x10(%rsp), %r12
je 0x2e863c
movq %r12, %rdi
movl %r15d, %esi
callq 0x2c8275
movl %eax, %r14d
movq %r13, %rdi
movl 0x2c(%rsp), %esi
movl %r14d, %edx
callq 0x2e89fc
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rsi
movq %r12, %rdi
movl %r14d, %edx
movl 0x24(%rsp), %ecx
movl 0x30(%rsp), %r8d
callq 0x2e81cf
cmpl $0x1, %r15d
jne 0x2e869f
testl %r14d, %r14d
movl 0xc(%rsp), %r12d
je 0x2e86bb
movq 0x10(%rsp), %rax
movzbl 0x1f(%rax), %eax
cmpq $0x7, %rax
ja 0x2e86bb
leal 0x1(%rax), %ecx
movq 0x10(%rsp), %rdx
movb %cl, 0x1f(%rdx)
leaq (%rdx,%rax,4), %rdx
addq $0xd4, %rdx
jmp 0x2e86b8
cmpl %r15d, 0x28(%r12)
movl 0xc(%rsp), %r12d
jge 0x2e86bb
movq 0x10(%rsp), %rdx
movl %r15d, 0x28(%rdx)
addq $0x2c, %rdx
movl %r14d, (%rdx)
testl %r12d, %r12d
je 0x2e86d5
movq %rbx, %rdi
movl $0xb, %esi
xorl %edx, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %rbx, %rdi
movl 0x28(%rsp), %esi
callq 0x2c91a7
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq