// File: /workspace/github_c_makefile_star2_O3/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, %r13
movq %rdi, %r14
movq 0x10(%rdi), %r12
movb $0x1, (%rsi)
callq 0x552af
cmpl $0x0, 0x30(%r13)
movq %r12, -0x50(%rbp)
jle 0x555b8
movq 0x28(%r13), %r15
xorl %ebx, %ebx
movl $0x0, -0x2c(%rbp)
movq %r13, -0x58(%rbp)
movl %ebx, -0x44(%rbp)
movq (%r15), %rax
movq 0x20(%rax), %rbx
movl $0x0, %r13d
movl $0x0, %eax
movq %rax, -0x38(%rbp)
testq %rbx, %rbx
je 0x5540c
movl (%rbx), %r13d
movl 0x48(%r14), %eax
subl %r13d, %eax
jge 0x553e8
movl 0x58(%r14), %eax
leal 0x1(%rax), %edx
addl %r13d, %eax
movl %eax, 0x58(%r14)
jmp 0x553f8
movl 0x4c(%r14), %edx
leal (%rdx,%r13), %ecx
movl %ecx, 0x4c(%r14)
movl %eax, 0x48(%r14)
movq %r14, %rdi
movq %rbx, %rsi
movq %rdx, -0x38(%rbp)
movl $0x1, %ecx
callq 0x4e5c4
cmpl $0x0, 0x14(%r15)
js 0x55437
movq %r12, %rdi
callq 0x4c5eb
movl 0x14(%r15), %esi
movq %r14, %rdi
movl %eax, -0x30(%rbp)
movl %eax, %edx
movl $0x1, %ecx
movq -0x38(%rbp), %r8
callq 0x5b7f6
jmp 0x5543e
movl $0x0, -0x30(%rbp)
movq %r15, -0x40(%rbp)
movq 0x8(%r15), %r15
testb $0x8, 0x3(%r15)
jne 0x55456
movq -0x40(%rbp), %rax
jmp 0x554ea
testl %r13d, %r13d
jle 0x55492
movq 0x8(%rbx), %r15
movl $0x1, %r12d
movq (%r15), %rsi
movq %r14, %rdi
callq 0x4b225
movq %rax, %rbx
testq %rax, %rax
jne 0x55489
addq $0x20, %r15
leal 0x1(%r12), %eax
cmpl %r13d, %r12d
movl %eax, %r12d
jl 0x55465
testq %rbx, %rbx
movq -0x50(%rbp), %r12
jne 0x55499
movq (%r14), %rax
movq 0x10(%rax), %rbx
movl -0x2c(%rbp), %edx
testl %edx, %edx
movq -0x40(%rbp), %r15
jne 0x554bc
movq -0x58(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x554ba
movl 0x58(%r14), %edx
incl %edx
movl %edx, 0x58(%r14)
jmp 0x554bc
xorl %edx, %edx
movq %r12, %rdi
movl $0x1f, %esi
movl %edx, -0x2c(%rbp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r12, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
callq 0x11a9f
movq %r15, %rax
movq 0x8(%r15), %r15
movl 0x10(%rax), %r8d
movq %r12, %rdi
movl $0x8, %esi
xorl %edx, %edx
movq -0x38(%rbp), %rcx
callq 0x45f15
movq %r12, %rdi
movl %eax, %esi
movq %r15, %rdx
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
callq 0x11a9f
movq 0x8(%r12), %rax
testq %rax, %rax
movl -0x44(%rbp), %ebx
je 0x5552e
movslq 0x34(%r12), %rcx
leaq (%rcx,%rcx,2), %rcx
movb %r13b, -0x15(%rax,%rcx,8)
movq %r14, %rdi
movq -0x38(%rbp), %r15
movl %r15d, %esi
movl %r13d, %edx
callq 0x4e564
movq %r14, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x4e564
cmpl %r13d, 0x48(%r14)
jge 0x5555c
movl %r13d, 0x48(%r14)
movl %r15d, 0x4c(%r14)
movl -0x30(%rbp), %edx
testl %edx, %edx
movq -0x58(%rbp), %r13
movq -0x40(%rbp), %r15
je 0x5558b
jns 0x55583
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x55583
notl %edx
movl 0x34(%r12), %ecx
movl %edx, %edx
movl %ecx, (%rax,%rdx,4)
movq %r14, %rdi
callq 0x552af
incl %ebx
addq $0x18, %r15
cmpl 0x30(%r13), %ebx
jl 0x553ae
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x555b8
movq %r12, %rdi
movl $0x27, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, %ebx
jmp 0x555ba
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x552af
cmpl $0x0, 0x24(%r13)
jle 0x555f0
movq 0x18(%r13), %r15
addq $0x18, %r15
xorl %r12d, %r12d
movq (%r15), %rsi
movl -0x4(%r15), %edx
movq %r14, %rdi
callq 0x4e50a
incl %r12d
addq $0x20, %r15
cmpl 0x24(%r13), %r12d
jl 0x555d4
movb $0x0, (%r13)
movq %r14, %rdi
callq 0x552af
testl %ebx, %ebx
movq -0x50(%rbp), %rcx
jle 0x5561a
movl 0x34(%rcx), %eax
cmpl %ebx, %eax
jbe 0x5561a
movq 0x8(%rcx), %rcx
movl %ebx, %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