// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: updateAccumulator
static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
  Vdbe *v = pParse->pVdbe;
  int i;
  int regHit = 0;
  int addrHitTest = 0;
  struct AggInfo_func *pF;
  struct AggInfo_col *pC;

  pAggInfo->directMode = 1;
  sqlite3ExprCacheClear(pParse);
  for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
    int nArg;
    int addrNext = 0;
    int regAgg;
    ExprList *pList = pF->pExpr->x.pList;
    assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
    if( pList ){
      nArg = pList->nExpr;
      regAgg = sqlite3GetTempRange(pParse, nArg);
      sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
    }else{
      nArg = 0;
      regAgg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
      codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
    }
    if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
      CollSeq *pColl = 0;
      struct ExprList_item *pItem;
      int j;
      assert( pList!=0 );  /* pList!=0 if pF->pFunc has NEEDCOLL */
      for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
        pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
      }
      if( !pColl ){
        pColl = pParse->db->pDfltColl;
      }
      if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
      sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
    }
    sqlite3VdbeAddOp4(v, OP_AggStep, 0, regAgg, pF->iMem,
                      (void*)pF->pFunc, P4_FUNCDEF);
    sqlite3VdbeChangeP5(v, (u8)nArg);
    sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
    sqlite3ReleaseTempRange(pParse, regAgg, nArg);
    if( addrNext ){
      sqlite3VdbeResolveLabel(v, addrNext);
      sqlite3ExprCacheClear(pParse);
    }
  }

  /* Before populating the accumulator registers, clear the column cache.
  ** Otherwise, if any of the required column values are already present 
  ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
  ** to pC->iMem. But by the time the value is used, the original register
  ** may have been used, invalidating the underlying buffer holding the
  ** text or blob value. See ticket [883034dcb5].
  **
  ** Another solution would be to change the OP_SCopy used to copy cached
  ** values to an OP_Copy.
  */
  if( regHit ){
    addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
  }
  sqlite3ExprCacheClear(pParse);
  for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
    sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
  }
  pAggInfo->directMode = 0;
  sqlite3ExprCacheClear(pParse);
  if( addrHitTest ){
    sqlite3VdbeJumpHere(v, addrHitTest);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq 0x10(%rdi), %r13
movb $0x1, (%rsi)
callq 0x5526f
movl $0x0, -0x30(%rbp)
cmpl $0x0, 0x30(%r12)
movl $0x0, -0x2c(%rbp)
jle 0x5556d
movq 0x28(%r12), %rbx
xorl %r15d, %r15d
movl $0x0, -0x2c(%rbp)
movq %r13, -0x48(%rbp)
movq %r12, -0x50(%rbp)
movq %r15, -0x60(%rbp)
movq (%rbx), %rax
movq 0x20(%rax), %r15
movl $0x0, %r12d
movl $0x0, %eax
testq %r15, %r15
je 0x553e0
movl (%r15), %r12d
movl 0x48(%r14), %eax
subl %r12d, %eax
jge 0x553b6
movl 0x58(%r14), %eax
leal 0x1(%rax), %edx
addl %r12d, %eax
movl %eax, 0x58(%r14)
jmp 0x553c6
movl 0x4c(%r14), %edx
leal (%rdx,%r12), %ecx
movl %ecx, 0x4c(%r14)
movl %eax, 0x48(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %ecx
movq %rdx, %r13
callq 0x4e56d
movq %r13, %rax
movq -0x48(%rbp), %r13
movq %rax, -0x40(%rbp)
cmpl $0x0, 0x14(%rbx)
js 0x5540d
movq %r13, %rdi
callq 0x4c4bf
movl 0x14(%rbx), %esi
movq %r14, %rdi
movl %eax, -0x34(%rbp)
movl %eax, %edx
movl $0x1, %ecx
movq -0x40(%rbp), %r8
callq 0x5b8b4
jmp 0x55414
movl $0x0, -0x34(%rbp)
movq 0x8(%rbx), %rax
testb $0x8, 0x3(%rax)
je 0x554b9
movq %rbx, -0x58(%rbp)
testl %r12d, %r12d
jle 0x5545b
movq 0x8(%r15), %r13
movl $0x1, %ebx
movq (%r13), %rsi
movq %r14, %rdi
callq 0x4b095
movq %rax, %r15
testq %rax, %rax
sete %al
jne 0x55460
addq $0x20, %r13
leal 0x1(%rbx), %ecx
cmpl %r12d, %ebx
movl %ecx, %ebx
jl 0x55434
jmp 0x55460
movb $0x1, %al
xorl %r15d, %r15d
testb %al, %al
je 0x5546b
movq (%r14), %rax
movq 0x10(%rax), %r15
movl -0x2c(%rbp), %edx
testl %edx, %edx
movq -0x48(%rbp), %r13
movq -0x58(%rbp), %rbx
jne 0x55492
movq -0x50(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x55490
movl 0x58(%r14), %edx
incl %edx
movl %edx, 0x58(%r14)
jmp 0x55492
xorl %edx, %edx
movq %r13, %rdi
movl $0x1f, %esi
movl %edx, -0x2c(%rbp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %r13, %rdi
movl %eax, %esi
movq %r15, %rdx
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
callq 0x11975
movq -0x40(%rbp), %rcx
movl 0x10(%rbx), %r8d
movq 0x8(%rbx), %r15
movq %r13, %rdi
movl $0x8, %esi
xorl %edx, %edx
callq 0x45b9e
movq %r13, %rdi
movl %eax, %esi
movq %r15, %rdx
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
callq 0x11975
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x554fc
movslq 0x34(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
movb %r12b, -0x15(%rax,%rcx,8)
movq %r14, %rdi
movq -0x40(%rbp), %r13
movl %r13d, %esi
movl %r12d, %edx
callq 0x4e50d
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x4e50d
cmpl %r12d, 0x48(%r14)
movq -0x60(%rbp), %r15
jge 0x5552e
movl %r12d, 0x48(%r14)
movl %r13d, 0x4c(%r14)
movl -0x34(%rbp), %edx
testl %edx, %edx
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r13
je 0x5555b
jns 0x55553
movq 0x40(%r13), %rax
testq %rax, %rax
je 0x55553
notl %edx
movl 0x34(%r13), %ecx
movl %edx, %edx
movl %ecx, (%rax,%rdx,4)
movq %r14, %rdi
callq 0x5526f
incl %r15d
addq $0x18, %rbx
cmpl 0x30(%r12), %r15d
jl 0x5537f
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x55589
movq %r13, %rdi
movl $0x27, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movl %eax, -0x30(%rbp)
movq %r14, %rdi
callq 0x5526f
cmpl $0x0, 0x24(%r12)
jle 0x555c1
movq 0x18(%r12), %rbx
addq $0x18, %rbx
xorl %r15d, %r15d
movq (%rbx), %rsi
movl -0x4(%rbx), %edx
movq %r14, %rdi
callq 0x4e4ba
incl %r15d
addq $0x20, %rbx
cmpl 0x24(%r12), %r15d
jl 0x555a5
movb $0x0, (%r12)
movq %r14, %rdi
callq 0x5526f
movl -0x30(%rbp), %edx
testl %edx, %edx
jle 0x555eb
movl 0x34(%r13), %eax
cmpl %edx, %eax
jbe 0x555eb
movq 0x8(%r13), %rcx
movl %edx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq