// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: windowCodeRangeTest
static void windowCodeRangeTest(
  WindowCodeArg *p,
  int op,                         /* OP_Ge, OP_Gt, or OP_Le */
  int csr1,                       /* Cursor number for cursor 1 */
  int regVal,                     /* Register containing non-negative number */
  int csr2,                       /* Cursor number for cursor 2 */
  int lbl                         /* Jump destination if condition is true */
){
  Parse *pParse = p->pParse;
  Vdbe *v = sqlite3GetVdbe(pParse);
  ExprList *pOrderBy = p->pMWin->pOrderBy;  /* ORDER BY clause for window */
  int reg1 = sqlite3GetTempReg(pParse);     /* Reg. for csr1.peerVal+regVal */
  int reg2 = sqlite3GetTempReg(pParse);     /* Reg. for csr2.peerVal */
  int regString = ++pParse->nMem;           /* Reg. for constant value '' */
  int arith = OP_Add;                       /* OP_Add or OP_Subtract */
  int addrGe;                               /* Jump destination */

  assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
  assert( pOrderBy && pOrderBy->nExpr==1 );
  if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
    switch( op ){
      case OP_Ge: op = OP_Le; break;
      case OP_Gt: op = OP_Lt; break;
      default: assert( op==OP_Le ); op = OP_Ge; break;
    }
    arith = OP_Subtract;
  }

  /* Read the peer-value from each cursor into a register */
  windowReadPeerValues(p, csr1, reg1);
  windowReadPeerValues(p, csr2, reg2);

  VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl",
      reg1, (arith==OP_Add ? "+" : "-"), regVal,
      ((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2
  ));

  /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
  ** This block adds (or subtracts for DESC) the numeric value in regVal
  ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
  ** then leave reg1 as it is. In pseudo-code, this is implemented as:
  **
  **   if( reg1>='' ) goto addrGe;
  **   reg1 = reg1 +/- regVal
  **   addrGe:
  **
  ** Since all strings and blobs are greater-than-or-equal-to an empty string,
  ** the add/subtract is skipped for these, as required. If reg1 is a NULL,
  ** then the arithmetic is performed, but since adding or subtracting from
  ** NULL is always NULL anyway, this case is handled as required too.  */
  sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
  addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
  VdbeCoverage(v);
  sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
  sqlite3VdbeJumpHere(v, addrGe);

  /* If the BIGNULL flag is set for the ORDER BY, then it is required to
  ** consider NULL values to be larger than all other values, instead of
  ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this
  ** (and adding that capability causes a performance regression), so
  ** instead if the BIGNULL flag is set then cases where either reg1 or
  ** reg2 are NULL are handled separately in the following block. The code
  ** generated is equivalent to:
  **
  **   if( reg1 IS NULL ){
  **     if( op==OP_Ge ) goto lbl;
  **     if( op==OP_Gt && reg2 IS NOT NULL ) goto lbl;
  **     if( op==OP_Le && reg2 IS NULL ) goto lbl;
  **   }else if( reg2 IS NULL ){
  **     if( op==OP_Le ) goto lbl;
  **   }
  **
  ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
  ** not taken, control jumps over the comparison operator coded below this
  ** block.  */
  if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
    /* This block runs if reg1 contains a NULL. */
    int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
    switch( op ){
      case OP_Ge:
        sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
        break;
      case OP_Gt:
        sqlite3VdbeAddOp2(v, OP_NotNull, reg2, lbl);
        VdbeCoverage(v);
        break;
      case OP_Le:
        sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl);
        VdbeCoverage(v);
        break;
      default: assert( op==OP_Lt ); /* no-op */ break;
    }
    sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);

    /* This block runs if reg1 is not NULL, but reg2 is. */
    sqlite3VdbeJumpHere(v, addr);
    sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
    if( op==OP_Gt || op==OP_Ge ){
      sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
    }
  }

  /* Compare registers reg2 and reg1, taking the jump if required. Note that
  ** control skips over this test if the BIGNULL flag is set and either
  ** reg1 or reg2 contain a NULL value.  */
  sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
  sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);

  assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
  testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
  testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
  testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
  testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);
  sqlite3ReleaseTempReg(pParse, reg1);
  sqlite3ReleaseTempReg(pParse, reg2);

  VdbeModuleComment((v, "CodeRangeTest: end"));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, 0x4(%rsp)
movl %ecx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movl %esi, %r14d
movq %rdi, %r12
movq (%rdi), %r13
movq %r13, %rdi
callq 0x2bc630
movq %rax, %r15
movq 0x8(%r12), %rax
movq 0x18(%rax), %rsi
movb 0x1f(%r13), %al
testb %al, %al
je 0x2df4c1
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
movzbl %cl, %ecx
movl 0xd4(%r13,%rcx,4), %edx
testb %cl, %cl
je 0x2df4cd
addb $-0x2, %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0xd4(%r13,%rax,4), %ebx
movl 0x38(%r13), %ebp
jmp 0x2df4d5
movl 0x38(%r13), %eax
incl %eax
movl %eax, %edx
movl %eax, 0x38(%r13)
movl 0x38(%r13), %ebp
incl %ebp
movl %ebp, %ebx
incl %ebp
movq %r13, 0x20(%rsp)
movl %ebp, 0x38(%r13)
movq %rsi, 0x18(%rsp)
movzbl 0x18(%rsi), %eax
xorl %ecx, %ecx
cmpl $0x36, %r14d
sete %cl
xorl $0x39, %ecx
cmpl $0x39, %r14d
movl $0x37, %r13d
cmovnel %ecx, %r13d
andl $0x1, %eax
leal 0x69(%rax), %ecx
movl %ecx, 0xc(%rsp)
testl %eax, %eax
cmovel %r14d, %r13d
movq %r12, %rdi
movl 0x10(%rsp), %esi
movl %edx, %r14d
callq 0x2df754
movq %r12, %rdi
movl 0x4(%rsp), %esi
movl %ebx, 0x4(%rsp)
movl %ebx, %edx
callq 0x2df754
movq %r15, %rdi
movl $0x73, %esi
xorl %edx, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
leaq 0xeac21(%rip), %rdx     # 0x3ca170
movq %r15, %rdi
movl %eax, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x27b778
movq %r15, %rdi
movl $0x39, %esi
movl %ebp, %edx
xorl %ecx, %ecx
movl %r14d, %r8d
callq 0x2a83e1
movl %eax, %ebp
movq %r15, %rdi
movl 0xc(%rsp), %esi
movl 0x14(%rsp), %edx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0x2a83e1
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2df5a3
leaq 0x1df8e7(%rip), %rcx    # 0x4bee88
jmp 0x2df5bd
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r15), %rcx
movl 0x8(%rsp), %r12d
movl %eax, 0x8(%rcx)
movq 0x18(%rsp), %rax
testb $0x2, 0x18(%rax)
movl 0x4(%rsp), %ebp
je 0x2df6d7
movq %r15, %rdi
movl $0x33, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, %ebp
cmpl $0x36, %r13d
je 0x2df617
cmpl $0x37, %r13d
je 0x2df60d
cmpl $0x39, %r13d
jne 0x2df62e
movq %r15, %rdi
movl $0xb, %esi
xorl %edx, %edx
jmp 0x2df623
movq %r15, %rdi
movl $0x32, %esi
jmp 0x2df61f
movq %r15, %rdi
movl $0x33, %esi
movl 0x4(%rsp), %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r15), %ecx
addl $0x3, %ecx
movq %r15, %rdi
movl $0xb, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2df663
leaq 0x1df827(%rip), %rcx    # 0x4bee88
jmp 0x2df67d
leal -0x1(%rax), %ecx
testl %ebp, %ebp
cmovnsl %ebp, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r15), %rcx
movl %eax, 0x8(%rcx)
movq %r15, %rdi
movl $0x32, %esi
movl 0x4(%rsp), %ebp
movl %ebp, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
cmpl $0x39, %r13d
je 0x2df6a5
cmpl $0x36, %r13d
jne 0x2df6d7
movslq 0x90(%r15), %rcx
leal 0x1(%rcx), %eax
movq (%r15), %rdx
cmpb $0x0, 0x61(%rdx)
je 0x2df6c1
leaq 0x1df7c9(%rip), %rcx    # 0x4bee88
jmp 0x2df6d4
movq 0x88(%r15), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
addq $-0x18, %rcx
movl %eax, 0x8(%rcx)
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0x2a83e1
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x2df708
movq 0x88(%r15), %rcx
leaq (%rax,%rax,2), %rax
movw $0x80, -0x16(%rcx,%rax,8)
testl %r14d, %r14d
movq 0x20(%rsp), %rdx
je 0x2df72a
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2df72a
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r14d, 0xd4(%rdx,%rax,4)
testl %ebp, %ebp
je 0x2df745
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2df745
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %ebp, 0xd4(%rdx,%rax,4)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq