// File: /workspace/github_c_makefile_star2_O2/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 0x4a78e
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 0x4da57
cmpq $0x0, 0x68(%r12)
je 0x4a92e
movl 0x58(%r15), %r14d
incl %r14d
movl %r14d, 0x58(%r15)
movl %r14d, 0xc(%r12)
movq %r15, %rdi
callq 0x41ef4
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x4a92e
movq 0x68(%r12), %rdi
leaq -0x34(%rbp), %rsi
callq 0x46204
testl %eax, %eax
je 0x4a81b
movl -0x34(%rbp), %ebx
pushq $0x15
popq %rsi
movq -0x30(%rbp), %rdi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x41f42
testq %rbx, %rbx
je 0x4a84a
testl %ebx, %ebx
js 0x4a85b
cmpq %rbx, 0x20(%r12)
jbe 0x4a85b
movq %rbx, 0x20(%r12)
jmp 0x4a85b
movq 0x68(%r12), %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x494eb
pushq $0x21
popq %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
callq 0x42436
movq %rbx, %rdi
movl $0x80, %esi
movl %r14d, %edx
jmp 0x4a853
pushq $0xe
popq %rsi
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %r13d, %ecx
callq 0x41f42
movq 0x70(%r12), %rsi
testq %rsi, %rsi
je 0x4a92e
movl 0x58(%r15), %eax
leal 0x1(%rax), %r13d
movl %r13d, 0x10(%r12)
movq %rax, %r12
addl $0x2, %r12d
movl %r12d, 0x58(%r15)
movq %r15, %rdi
movl %r13d, %edx
callq 0x494eb
pushq $0x21
popq %rsi
movq -0x30(%rbp), %r15
movq %r15, %rdi
movl %r13d, %edx
callq 0x42436
pushq $0x7e
popq %rsi
movq %r15, %rdi
movl %r13d, %edx
callq 0x42436
movl %eax, %ebx
pushq $0x15
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
movl %r13d, %ecx
callq 0x41f42
testl %ebx, %ebx
js 0x4a8d8
movl 0x34(%r15), %eax
cmpl %ebx, %eax
jbe 0x4a8d8
movq 0x8(%r15), %rcx
movl %ebx, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
pushq $0x56
popq %rsi
movq %r15, %rdi
movl %r14d, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x41f4c
pushq $0x7e
popq %rsi
movq %r15, %rdi
movl %r14d, %edx
callq 0x42436
movl %eax, %ebx
pushq $0x15
popq %rsi
pushq $-0x1
popq %rdx
movq %r15, %rdi
movl %r12d, %ecx
callq 0x41f42
testl %ebx, %ebx
js 0x4a92e
movq -0x30(%rbp), %rax
movl 0x34(%rax), %eax
cmpl %ebx, %eax
jbe 0x4a92e
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %ebx, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq