// File: /workspace/github_cpp_makefile_star2_O2/ncbi[P]amr/tsv.cpp
// Function: Common_sp::TextTable::group(Common_sp::StringVector const&, Common_sp::StringVector const&, Common_sp::StringVector const&, Common_sp::StringVector const&, Common_sp::StringVector const&)
void TextTable::group (const StringVector &by,
                       const StringVector &sum,
                       const StringVector &minV,
                       const StringVector &maxV,
                       const StringVector &aggr)
{
  const Vector<ColNum> byIndex   (columns2nums (by));
  const Vector<ColNum> sumIndex  (columns2nums (sum));
  const Vector<ColNum> minIndex  (columns2nums (minV));
  const Vector<ColNum> maxIndex  (columns2nums (maxV));
  const Vector<ColNum> aggrIndex (columns2nums (aggr));
  
  // QC
  {
    ColumnPartitionQC cp;
    cp. add (by, "group by");
    cp. add (sum, "sum");
    cp. add (minV, "min");
    cp. add (maxV, "max");
    cp. add (aggr, "aggregation");
  }
  for (const string& s : sum)
    if (! header [col2num (s)]. numeric)
      throw runtime_error ("Summation column " + strQuote (s) + " is not numeric");

  sort (by);
  
  RowNum i = 0;  
  FFOR_START (RowNum, j, 1, rows. size ())
  {
    ASSERT (i < j);
    if (rows [i]. same (rows [j], byIndex))
      merge (i, j, sumIndex, minIndex, maxIndex, aggrIndex);
    else
    {
      i++;
      if (i < j)
        rows [i] = std::move (rows [j]);
    }
  }
  if (! rows. empty ())
    i++;

  ASSERT (rows. size () >= i);
  FFOR (RowNum, k, rows. size () - i)
    rows. pop_back ();
    
  StringVector newColumns;
  newColumns << by << sum << minV << maxV << aggr;
  filterColumns (newColumns);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %r9, %r13
movq %r8, %rbp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rdx
movq %rdi, %rbx
leaq 0x1d8(%rsp), %rdi
movq %rbx, %rsi
movq %rdx, 0x38(%rsp)
callq 0x555d4
leaq 0x1b8(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x555d4
leaq 0x198(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x555d4
leaq 0x178(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x555d4
leaq 0x158(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x555d4
leaq 0x48(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xc756(%rip), %rsi      # 0x5f82f
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b7b6
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rsi
callq 0x537cc
leaq 0x18(%rsp), %rdi
callq 0xbb68
leaq 0xc72b(%rip), %rsi      # 0x5f838
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b7b6
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r12, %rsi
callq 0x537cc
leaq 0x18(%rsp), %rdi
callq 0xbb68
leaq 0x624c(%rip), %rsi      # 0x5938b
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b7b6
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r14, %rsi
callq 0x537cc
leaq 0x18(%rsp), %rdi
callq 0xbb68
leaq 0x7fea(%rip), %rsi      # 0x5b15b
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b7b6
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %rbp, %rsi
callq 0x537cc
leaq 0x18(%rsp), %rdi
callq 0xbb68
leaq 0xc699(%rip), %rsi      # 0x5f83c
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b7b6
movq %r14, 0xb0(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r13, %rsi
callq 0x537cc
leaq 0x18(%rsp), %rdi
callq 0xbb68
leaq 0x40(%rsp), %rdi
callq 0x1be2a
movq (%r12), %r15
movq %r12, 0xa8(%rsp)
movq 0x8(%r12), %r12
leaq 0x30(%rbx), %r14
cmpq %r12, %r15
je 0x53220
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1daec
movq %r14, %rdi
movq %rax, %rsi
callq 0x55318
cmpb $0x0, 0x30(%rax)
je 0x53403
addq $0x20, %r15
jmp 0x531f5
movq %rbp, 0x98(%rsp)
movq %r13, 0xa0(%rsp)
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
callq 0x52f56
movq 0x58(%rbx), %r13
subq 0x50(%rbx), %r13
leaq 0x50(%rbx), %r15
sarq $0x5, %r13
pushq $0x1
popq %rbp
xorl %r12d, %r12d
cmpq %r13, %rbp
jae 0x53305
callq 0xb060
andl $0x0, (%rax)
cmpq %rbp, %r12
jae 0x53472
movq %r15, %rdi
movq %r12, %rsi
callq 0x201be
movq %rax, %r14
movq %r15, %rdi
movq %rbp, %rsi
callq 0x201be
movq %r14, %rdi
movq %rax, %rsi
leaq 0x1d8(%rsp), %rdx
callq 0x29db4
testb %al, %al
je 0x532d1
leaq 0x158(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
leaq 0x1b8(%rsp), %rcx
leaq 0x198(%rsp), %r8
leaq 0x178(%rsp), %r9
callq 0x539c6
jmp 0x532fd
incq %r12
cmpq %rbp, %r12
jae 0x532fd
movq %r15, %rdi
movq %rbp, %rsi
callq 0x201be
movq %rax, %r14
movq %r15, %rdi
movq %r12, %rsi
callq 0x201be
movq %rax, %rdi
movq %r14, %rsi
callq 0x20b7a
incq %rbp
jmp 0x53253
movq 0x58(%rbx), %r14
xorl %eax, %eax
subq 0x50(%rbx), %r14
setne %al
addq %rax, %r12
callq 0xb060
andl $0x0, (%rax)
sarq $0x5, %r14
subq %r12, %r14
jb 0x5354c
movq 0xa0(%rsp), %r12
movq 0x98(%rsp), %r13
subq $0x1, %r14
jb 0x5334a
movq %r15, %rdi
callq 0x55714
jmp 0x5333a
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movups %xmm0, 0x9(%rdi)
movaps %xmm0, (%rdi)
movq 0x38(%rsp), %rsi
callq 0x55770
movq %rax, %rdi
movq 0xa8(%rsp), %rsi
callq 0x55770
movq %rax, %rdi
movq 0xb0(%rsp), %rsi
callq 0x55770
movq %rax, %rdi
movq %r13, %rsi
callq 0x55770
movq %rax, %rdi
movq %r12, %rsi
callq 0x55770
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x52e10
leaq 0x40(%rsp), %rdi
callq 0x20bee
leaq 0x158(%rsp), %rdi
callq 0x40424
leaq 0x178(%rsp), %rdi
callq 0x40424
leaq 0x198(%rsp), %rdi
callq 0x40424
leaq 0x1b8(%rsp), %rdi
callq 0x40424
leaq 0x1d8(%rsp), %rdi
callq 0x40424
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0xb300
movq %rax, %r14
leaq 0x78(%rsp), %rdi
pushq $0x22
popq %rdx
movq %r15, %rsi
callq 0x243b1
leaq 0xc423(%rip), %rsi      # 0x5f848
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1b94c
leaq 0xc41f(%rip), %rdx      # 0x5f85a
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1b92d
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0xb940
xorl %ebp, %ebp
movq 0x30b85(%rip), %rsi     # 0x83fe8
movq 0x30af6(%rip), %rdx     # 0x83f60
movq %r14, %rdi
callq 0xb9d0
callq 0xb6c0
testl %eax, %eax
jne 0x53626
leaq 0xc123(%rip), %rsi      # 0x5f5a9
leaq 0x118(%rsp), %rdi
leaq 0x17(%rsp), %rdx
callq 0x1b7b6
leaq 0xf8(%rsp), %rdi
movl $0x24d, %esi            # imm = 0x24D
callq 0x1caa3
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x1ca3c
leaq 0x6715(%rip), %rdx      # 0x59be3
leaq 0x78(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x1b92d
leaq 0xc383(%rip), %rsi      # 0x5f86a
leaq 0xb8(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x1b7b6
leaq 0x843e(%rip), %rdx      # 0x5b93e
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x1b92d
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x1ca3c
leaq 0xc3c6(%rip), %rdx      # 0x5f8f9
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1b92d
leaq 0x40(%rsp), %rdi
callq 0x224fc
callq 0xb6c0
testl %eax, %eax
jne 0x53626
leaq 0xc049(%rip), %rsi      # 0x5f5a9
leaq 0x118(%rsp), %rdi
leaq 0x17(%rsp), %rdx
callq 0x1b7b6
leaq 0xf8(%rsp), %rdi
movl $0x25a, %esi            # imm = 0x25A
callq 0x1caa3
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x1ca3c
leaq 0x663b(%rip), %rdx      # 0x59be3
leaq 0x78(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x1b92d
leaq 0xc2a9(%rip), %rsi      # 0x5f86a
leaq 0xb8(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x1b7b6
leaq 0x8364(%rip), %rdx      # 0x5b93e
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x1b92d
leaq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x1ca3c
leaq 0xc2f2(%rip), %rdx      # 0x5f8ff
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1b92d
leaq 0x40(%rsp), %rdi
callq 0x224fc
pushq $0x1
popq %rdi
callq 0xb6d0
jmp 0x5363a
jmp 0x53649
jmp 0x5365d
jmp 0x53674
jmp 0x5368b
jmp 0x5369a
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xbb68
jmp 0x5364c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xbb68
jmp 0x53660
jmp 0x53702
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xbb68
jmp 0x53677
jmp 0x53714
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0xbb68
jmp 0x5368e
jmp 0x53780
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xbb68
jmp 0x5369d
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0xbb68
jmp 0x53705
jmp 0x53780
jmp 0x536c1
jmp 0x536d0
jmp 0x536c1
jmp 0x536d0
jmp 0x536c1
jmp 0x536d0
jmp 0x536c1
jmp 0x536d0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xbb68
jmp 0x536d3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x1be2a
jmp 0x53783
movq %rax, %rbx
jmp 0x53790
movq %rax, %rbx
jmp 0x5379d
movq %rax, %rbx
jmp 0x537aa
movq %rax, %rbx
jmp 0x537b7
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0xbb68
jmp 0x53717
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0xbb68
jmp 0x53783
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xbb68
jmp 0x5373b
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x18(%rsp), %rdi
callq 0xbb68
jmp 0x5375e
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x20bee
jmp 0x53783
jmp 0x53780
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x78(%rsp), %rdi
callq 0xbb68
testb %bpl, %bpl
jne 0x53772
jmp 0x53783
movq %rax, %rbx
movq %r14, %rdi
callq 0xb470
jmp 0x53783
jmp 0x53780
jmp 0x53780
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x40424
leaq 0x178(%rsp), %rdi
callq 0x40424
leaq 0x198(%rsp), %rdi
callq 0x40424
leaq 0x1b8(%rsp), %rdi
callq 0x40424
leaq 0x1d8(%rsp), %rdi
callq 0x40424
movq %rbx, %rdi
callq 0xba30