// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: computeLimitRegisters
static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
  Vdbe *v = 0;
  int iLimit = 0;
  int iOffset;
  int addr1, n;
  if( p->iLimit ) return;

  /* 
  ** "LIMIT -1" always shows all rows.  There is some
  ** controversy about what the correct behavior should be.
  ** The current implementation interprets "LIMIT 0" to mean
  ** no rows.
  */
  sqlite3ExprCacheClear(pParse);
  assert( p->pOffset==0 || p->pLimit!=0 );
  if( p->pLimit ){
    p->iLimit = iLimit = ++pParse->nMem;
    v = sqlite3GetVdbe(pParse);
    if( NEVER(v==0) ) return;  /* VDBE should have already been allocated */
    if( sqlite3ExprIsInteger(p->pLimit, &n) ){
      sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
      VdbeComment((v, "LIMIT counter"));
      if( n==0 ){
        sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
      }else if( n>=0 && p->nSelectRow>(u64)n ){
        p->nSelectRow = n;
      }
    }else{
      sqlite3ExprCode(pParse, p->pLimit, iLimit);
      sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
      VdbeComment((v, "LIMIT counter"));
      sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
    }
    if( p->pOffset ){
      p->iOffset = iOffset = ++pParse->nMem;
      pParse->nMem++;   /* Allocate an extra register for limit+offset */
      sqlite3ExprCode(pParse, p->pOffset, iOffset);
      sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
      VdbeComment((v, "OFFSET counter"));
      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
      sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
      sqlite3VdbeJumpHere(v, addr1);
      sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
      VdbeComment((v, "LIMIT+OFFSET"));
      addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
      sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
      sqlite3VdbeJumpHere(v, addr1);
    }
  }
}

// Assembly:
cmpl $0x0, 0xc(%rsi)
je 0x51c43
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, %r15
callq 0x5526f
cmpq $0x0, 0x68(%r12)
je 0x51e1b
movl 0x58(%r15), %r14d
incl %r14d
movl %r14d, 0x58(%r15)
movl %r14d, 0xc(%r12)
movq %r15, %rdi
callq 0x45b57
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x51e1b
movq 0x68(%r12), %rdi
leaq -0x34(%rbp), %rsi
callq 0x4aaf6
testl %eax, %eax
je 0x51cd5
movl -0x34(%rbp), %ebx
movq -0x30(%rbp), %rdi
movl $0x15, %esi
movl %ebx, %edx
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x45b9e
testq %rbx, %rbx
je 0x51d0b
testl %ebx, %ebx
js 0x51d21
cmpq %rbx, 0x20(%r12)
jbe 0x51d21
movq %rbx, 0x20(%r12)
jmp 0x51d21
movq 0x68(%r12), %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x4e4ba
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x21, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %rbx, %rdi
movl $0x80, %esi
movl %r14d, %edx
jmp 0x51d16
movq -0x30(%rbp), %rdi
movl $0xe, %esi
xorl %edx, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq 0x70(%r12), %rsi
testq %rsi, %rsi
je 0x51e1b
movl 0x58(%r15), %eax
leal 0x1(%rax), %r13d
movl %r13d, 0x58(%r15)
movl %r13d, 0x10(%r12)
movq %rax, %r12
addl $0x2, %r12d
movl %r12d, 0x58(%r15)
movq %r15, %rdi
movl %r13d, %edx
callq 0x4e4ba
movq -0x30(%rbp), %r15
movq %r15, %rdi
movl $0x21, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %r15, %rdi
movl $0x7e, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movl %eax, %ebx
movq %r15, %rdi
movl $0x15, %esi
xorl %edx, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x45b9e
testl %ebx, %ebx
js 0x51db5
movl 0x34(%r15), %eax
cmpl %ebx, %eax
jbe 0x51db5
movq 0x8(%r15), %rcx
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r15, %rdi
movl $0x56, %esi
movl %r14d, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x45b9e
movq %r15, %rdi
movl $0x7e, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movl %eax, %ebx
movq %r15, %rdi
movl $0x15, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x45b9e
testl %ebx, %ebx
js 0x51e1b
movq -0x30(%rbp), %rax
movl 0x34(%rax), %eax
cmpl %ebx, %eax
jbe 0x51e1b
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq