// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
movl %edx, 0x18(%rsp)
movl %esi, %ebx
movq %rdi, %r15
movq (%rdi), %r13
movq %r13, %rdi
callq 0x2645be
movq %rax, %r12
movq 0x8(%r15), %rax
movq 0x18(%rax), %r14
movq %r14, 0x28(%rsp)
movq %r13, %rdi
callq 0x267d61
movl %eax, 0x10(%rsp)
movq %r13, %rdi
callq 0x267d61
movl %eax, 0xc(%rsp)
movl 0x38(%r13), %ebp
incl %ebp
movq %r13, 0x30(%rsp)
movl %ebp, 0x38(%r13)
movzbl 0x18(%r14), %eax
xorl %ecx, %ecx
cmpl $0x36, %ebx
sete %cl
xorl $0x39, %ecx
cmpl $0x39, %ebx
pushq $0x37
popq %r13
cmovnel %ecx, %r13d
andl $0x1, %eax
leal 0x69(%rax), %ecx
movl %ecx, 0x14(%rsp)
testl %eax, %eax
cmovel %ebx, %r13d
movq %r15, %rdi
movl 0x18(%rsp), %esi
movl 0x10(%rsp), %r14d
movl %r14d, %edx
callq 0x27dbe4
movq %r15, %rdi
movl 0x1c(%rsp), %esi
movl 0xc(%rsp), %ebx
movl %ebx, %edx
callq 0x27dbe4
orl $-0x1, (%rsp)
leaq 0xecb01(%rip), %r9      # 0x36a570
pushq $0x73
popq %rsi
movq %r12, %rdi
xorl %edx, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x264609
pushq $0x39
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %ebx, %ebp
xorl %ecx, %ecx
movl %r14d, %r8d
callq 0x24d51f
movl %eax, %ebx
movq %r12, %rdi
movl 0x14(%rsp), %esi
movl 0x20(%rsp), %edx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0x24d51f
movq %r12, %rdi
movl %ebx, %esi
movl 0x24(%rsp), %ebx
callq 0x2645f8
movq 0x28(%rsp), %rax
testb $0x2, 0x18(%rax)
je 0x27db66
pushq $0x33
popq %rsi
movq %r12, %rdi
movl %r14d, %edx
callq 0x265d5c
movl %eax, %r15d
cmpl $0x36, %r13d
je 0x27dafb
cmpl $0x37, %r13d
je 0x27daf7
cmpl $0x39, %r13d
jne 0x27db0a
pushq $0xb
popq %rsi
movq %r12, %rdi
xorl %edx, %edx
jmp 0x27db03
pushq $0x32
jmp 0x27dafd
pushq $0x33
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x24d51a
movl 0x90(%r12), %ecx
addl $0x3, %ecx
pushq $0xb
popq %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x24d51a
movq %r12, %rdi
movl %r15d, %esi
callq 0x2645f8
pushq $0x32
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x24d51a
cmpl $0x39, %r13d
je 0x27db48
cmpl $0x36, %r13d
jne 0x27db66
movl %ebx, %r15d
movl 0x90(%r12), %ebx
incl %ebx
pushq $-0x1
popq %rsi
movq %r12, %rdi
callq 0x26468f
movl %ebx, 0x8(%rax)
movl %r15d, %ebx
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movl %r14d, %r8d
callq 0x24d51f
movslq 0x90(%r12), %rax
testq %rax, %rax
jle 0x27db98
movq 0x88(%r12), %rcx
imulq $0x18, %rax, %rax
movw $0x80, -0x16(%rcx,%rax)
testl %r14d, %r14d
movq 0x30(%rsp), %rdx
je 0x27dbba
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x27dbba
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r14d, 0xd4(%rdx,%rax,4)
testl %ebp, %ebp
je 0x27dbd5
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x27dbd5
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %ebp, 0xd4(%rdx,%rax,4)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq