// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/formatter.cpp
// Function: ash::GroupedFormatter::insert(ash::ResultSet const*, std::ostream&) const
void GroupedFormatter::insert(const ResultSet * rs, ostream & out) const {
  if (!rs) return;  // Sanity check.

  vector<size_t> widths = get_widths(rs, do_show_headings);
  size_t levels = get_grouped_level_count(rs, widths);

  if (do_show_headings) {
    ResultSet::HeadersType::const_iterator h = rs -> headers.begin();
    for (size_t c = 0, cols = rs -> columns; c < cols; ++c) {
      if (c < levels) {
        // if it's a grouped column, print it followed by a newline and an
        // indent for the next line.
        out << *h << "\n";
        for (size_t i = c + 1; i > 0; --i) out << "    ";
      } else {
        // if it's not the last column, we set the alignment left and pad the
        // value with spaces.  Otherwise we just print the value to remove
        // trailing spaces from the last value.
        if (c < cols - 1) {
          out << left << setw(widths[c]) << *h;
        } else {
          out << *h;
        }
      }
      ++h;
    }
    out << endl;
  }
  
  vector<string> prev(levels);
  string value;
  for (size_t r = 0, rows = rs -> rows; r < rows; ++r) {
    for (size_t c = 0, cols = rs -> columns; c < cols; ++c) {
      value = rs -> data[r][c];
      if (c < levels) {
        if (value != prev[c] || r == 0) {
          // The value has not been grouped, 
          out << value;
          if (c < cols - 1) {
            // Since it's not the final column, wrap the line and indent
            // to the next level in preparation for the next value.
            out << "\n";
            for (size_t i = c + 1; i > 0; --i) out << "    ";
            for (size_t i = c; i < levels; ++i) prev[i] = "";
          }
          prev[c] = value;
        } else {
          // The value has been grouped, only print the indent.
          out << "    ";
        }
      } else {
        // Normal (non-grouped) case.
        if (c < cols - 1) {
          out << left << setw(widths[c]) << value;
        } else {
          out << value;
        }
      }
    }
    out << endl;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
testq %rsi, %rsi
je 0x6ef50
movq %rdx, %r12
movq %rdi, %r14
movzbl 0x48(%rdi), %edx
movq %rsi, %rbx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x6df8f
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6e948
cltq
movq %rax, 0x28(%rsp)
cmpb $0x1, 0x48(%r14)
movq %r12, (%rsp)
jne 0x6ecae
movq 0x10(%rsp), %rax
movq 0x38(%rax), %r15
testq %r15, %r15
je 0x6ec82
leaq -0x1(%r15), %rax
movq %rax, 0x20(%rsp)
movq $-0x1, %rbp
xorl %r14d, %r14d
leaq 0xf458(%rip), %r12      # 0x7e031
movq 0x10(%rsp), %r13
movq (%r13), %r13
cmpq 0x28(%rsp), %r14
jae 0x6ec29
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq (%rsp), %rdi
callq 0x8470
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf7a6(%rip), %rsi      # 0x7e3af
callq 0x8470
movq %rbp, %rbx
movl $0x4, %edx
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x8470
incq %rbx
jne 0x6ec11
jmp 0x6ec73
cmpq 0x20(%rsp), %r14
jae 0x6ec62
movq (%rsp), %rsi
movq (%rsi), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rsi,%rcx), %edx
movl $0xffffff4f, %edi       # imm = 0xFFFFFF4F
andl %edi, %edx
orl $0x20, %edx
movl %edx, 0x18(%rsi,%rcx)
movq 0x80(%rsp), %rcx
movslq (%rcx,%r14,8), %rcx
movq -0x18(%rax), %rax
movq %rcx, 0x10(%rsi,%rax)
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq (%rsp), %rdi
callq 0x8470
incq %r14
decq %rbp
cmpq %r15, %r14
jne 0x6ebde
movq (%rsp), %r12
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x83c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8250
leaq 0x40(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq 0x68(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0xf(%rsp), %rcx
movq 0x28(%rsp), %rsi
callq 0x6f1d0
movq 0x10(%rsp), %r15
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x6ecf0
callq 0x8390
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq 0x30(%r15), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x6ef34
movq $0x0, 0x18(%rsp)
movq 0x38(%r15), %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x6eee0
movq 0x20(%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
movq $-0x1, %rbp
movq 0x18(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x60(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x18(%r15), %rax
movq %rbx, %r14
shlq $0x5, %r14
movq 0x60(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq %r14, %rsi
leaq 0x30(%rsp), %rdi
callq 0x81f0
cmpq 0x28(%rsp), %rbx
jae 0x6edb8
movq 0x68(%rsp), %rax
movq 0x38(%rsp), %r12
cmpq 0x8(%rax,%r14), %r12
jne 0x6ee32
testq %r12, %r12
je 0x6ee07
addq %r14, %rax
movq (%rax), %rsi
movq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x8410
testl %eax, %eax
setne %al
jmp 0x6ee09
cmpq 0x50(%rsp), %rbx
jae 0x6edf0
movq (%r12), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r12,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x20, %edx
movl %edx, 0x18(%r12,%rcx)
movq 0x80(%rsp), %rcx
movslq (%rcx,%rbx,8), %rcx
movq -0x18(%rax), %rax
movq %rcx, 0x10(%r12,%rax)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r12, %rdi
callq 0x8470
jmp 0x6eecb
xorl %eax, %eax
cmpq $0x0, 0x18(%rsp)
je 0x6ee32
testb %al, %al
jne 0x6ee32
movl $0x4, %edx
movq (%rsp), %r12
movq %r12, %rdi
leaq 0xf209(%rip), %rsi      # 0x7e031
callq 0x8470
jmp 0x6eecb
movq 0x30(%rsp), %rsi
movq (%rsp), %rdi
movq %r12, %rdx
callq 0x8470
cmpq 0x50(%rsp), %rbx
jae 0x6eeb0
movl $0x1, %edx
movq (%rsp), %r12
movq %r12, %rdi
leaq 0xf552(%rip), %rsi      # 0x7e3af
callq 0x8470
movq %rbp, %r15
movl $0x4, %edx
movq %r12, %rdi
leaq 0xf1bd(%rip), %rsi      # 0x7e031
callq 0x8470
incq %r15
jne 0x6ee65
movq %r13, %r12
movq %rbx, %r15
movq 0x68(%rsp), %rdi
movq 0x8(%rdi,%r12), %rdx
addq %r12, %rdi
xorl %esi, %esi
leaq 0xf516(%rip), %rcx      # 0x7e3b0
xorl %r8d, %r8d
callq 0x85f0
incq %r15
addq $0x20, %r12
cmpq 0x28(%rsp), %r15
jb 0x6ee84
addq 0x68(%rsp), %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x81f0
movq (%rsp), %r12
movq 0x10(%rsp), %r15
incq %rbx
decq %rbp
addq $0x20, %r13
cmpq 0x20(%rsp), %rbx
jne 0x6ed5c
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x83c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8250
movq 0x18(%rsp), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
cmpq 0x58(%rsp), %rcx
jne 0x6ed23
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6ef34
callq 0x8390
leaq 0x68(%rsp), %rdi
callq 0x68b48
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x6ef50
callq 0x8390
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6ef80
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x6efaa
callq 0x8390
jmp 0x6efaa
jmp 0x6ef80
jmp 0x6ef80
jmp 0x6ef80
jmp 0x6ef89
movq %rax, %rbx
jmp 0x6efaa
jmp 0x6ef89
jmp 0x6ef89
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6efa0
callq 0x8390
leaq 0x68(%rsp), %rdi
callq 0x68b48
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x6efbc
callq 0x8390
movq %rbx, %rdi
callq 0x8720
movq %rax, %rdi
callq 0x68a31