// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x6d8f1
jmp 0x6dac0
movq -0x8(%rbp), %rdi
callq 0x6f480
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x6dac0
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
callq 0x5e000
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6d939
jmp 0x6dac0
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x65040
cmpl $0x0, %eax
je 0x6d9a5
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %edx
movl -0x24(%rbp), %ecx
movl $0x15, %esi
callq 0x5e0c0
cmpl $0x0, -0x30(%rbp)
jne 0x6d97e
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl $0xe, %esi
xorl %edx, %edx
callq 0x5e0c0
jmp 0x6d9a3
cmpl $0x0, -0x30(%rbp)
jl 0x6d9a1
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x6d9a1
movslq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x6d9a3
jmp 0x6d9de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
movl -0x24(%rbp), %edx
callq 0x69c70
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x21, %esi
callq 0x5ecf0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x14(%rbp), %ecx
movl $0x80, %esi
callq 0x5e0c0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x6dabe
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movl %ecx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rsi
movl -0x28(%rbp), %edx
callq 0x69c70
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %edx
movl $0x21, %esi
callq 0x5ecf0
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %edx
movl $0x7e, %esi
callq 0x5ecf0
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %ecx
movl $0x15, %esi
xorl %edx, %edx
callq 0x5e0c0
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x5e090
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movl -0x28(%rbp), %r8d
addl $0x1, %r8d
movl $0x56, %esi
callq 0x5e0f0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x7e, %esi
callq 0x5ecf0
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movl $0x15, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5e0c0
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x5e090
jmp 0x6dac0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)