// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x42f190
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x42f190
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
movl %eax, -0x44(%rbp)
movl $0x69, -0x48(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x45878b
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
subl $0x36, %eax
je 0x458774
jmp 0x458761
movl -0x54(%rbp), %eax
subl $0x39, %eax
jne 0x45877d
jmp 0x45876b
movl $0x37, -0xc(%rbp)
jmp 0x458784
movl $0x38, -0xc(%rbp)
jmp 0x458784
movl $0x39, -0xc(%rbp)
movl $0x6a, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x458cf0
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x40(%rbp), %edx
callq 0x458cf0
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %ecx
movl $0x73, %esi
xorl %r8d, %r8d
leaq 0x144e69(%rip), %r9     # 0x59d628
movl %r8d, %edx
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
callq 0x429aa0
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x3c(%rbp), %r8d
movl $0x39, %esi
xorl %ecx, %ecx
callq 0x410130
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x48(%rbp), %esi
movl -0x14(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x410130
movq -0x30(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x429a70
movq -0x38(%rbp), %rax
movzbl 0x18(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x45890e
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl $0x33, %esi
callq 0x42ba70
movl %eax, -0x50(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0x36, %eax
je 0x458868
jmp 0x45883f
movl -0x58(%rbp), %eax
subl $0x37, %eax
je 0x45887e
jmp 0x458849
movl -0x58(%rbp), %eax
subl $0x39, %eax
jne 0x458894
jmp 0x458853
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %ecx
movl $0xb, %esi
xorl %edx, %edx
callq 0x410100
jmp 0x458896
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x33, %esi
callq 0x410100
jmp 0x458896
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x32, %esi
callq 0x410100
jmp 0x458896
jmp 0x458896
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rdi
callq 0x430ae0
movq -0x60(%rbp), %rdi
movl %eax, %ecx
addl $0x3, %ecx
movl $0xb, %esi
xorl %edx, %edx
callq 0x410100
movq -0x30(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x429a70
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x32, %esi
callq 0x410100
cmpl $0x36, -0xc(%rbp)
je 0x4588e8
cmpl $0x39, -0xc(%rbp)
jne 0x45890c
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
callq 0x430ae0
movq -0x68(%rbp), %rdi
movl %eax, %edx
addl $0x1, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x429de0
jmp 0x45890e
movq -0x30(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x40(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x410130
movq -0x30(%rbp), %rdi
movl $0x80, %esi
callq 0x3cb9f0
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x42e560
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x42e560
addq $0x70, %rsp
popq %rbp
retq