// File: /workspace/github_c_makefile_star2_O2/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 0x61e5d
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movzbl 0x48(%rdi), %edx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x61185
movq %r12, %rdi
movq %r15, %rsi
callq 0x61954
movslq %eax, %rsi
cmpb $0x1, 0x48(%r14)
movq %r12, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
jne 0x61c4c
movq 0x38(%r12), %rax
movq %rax, 0x10(%rsp)
decq %rax
movq %rax, 0x18(%rsp)
pushq $-0x1
popq %r15
xorl %r14d, %r14d
movq %r12, %r13
leaq 0xe432(%rip), %r12      # 0x6ffd7
cmpq 0x10(%rsp), %r14
je 0x61c3a
movq (%r13), %r13
cmpq 0x8(%rsp), %r14
jae 0x61bee
leaq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0x8320
movq %rax, %rdi
leaq 0xe773(%rip), %rsi      # 0x70344
callq 0x83a0
movq %r15, %rbp
testq %rbp, %rbp
je 0x61c2f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x83a0
incq %rbp
jmp 0x61bd9
cmpq 0x18(%rsp), %r14
jae 0x61c23
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq 0x80(%rsp), %rcx
movslq (%rcx,%r14,8), %rcx
movq -0x18(%rax), %rax
movq %rcx, 0x10(%rbx,%rax)
leaq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0x8320
incq %r14
decq %r15
jmp 0x61ba5
movq %rbx, %rdi
callq 0x81a0
movq 0x20(%rsp), %r12
movq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %r14
movq %r14, -0x10(%r14)
andq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq 0x68(%rsp), %rdi
leaq 0x38(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0x62038
leaq 0x38(%rsp), %rdi
callq 0x84b0
leaq 0x38(%rsp), %rax
movq %r14, (%rax)
andq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%r12), %rax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movq 0x8(%rsp), %r14
cmpq 0x58(%rsp), %rax
je 0x61e3c
movq 0x38(%r12), %rcx
movq %rcx, 0x18(%rsp)
decq %rcx
movq %rcx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
imulq $0x18, %rax, %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
pushq $-0x1
popq %r15
xorl %ebp, %ebp
cmpq %r14, %rbp
movq %r14, %r13
cmovaq %rbp, %r13
cmpq 0x18(%rsp), %rbp
je 0x61e27
movq 0x18(%r12), %rax
movq %rbp, %r14
shlq $0x5, %r14
movq 0x60(%rsp), %rcx
movq (%rax,%rcx), %rsi
addq %r14, %rsi
leaq 0x38(%rsp), %rdi
callq 0x81d0
cmpq 0x8(%rsp), %rbp
jae 0x61d7e
movq 0x68(%rsp), %rsi
addq %r14, %rsi
leaq 0x38(%rsp), %rdi
callq 0x5c562
cmpq $0x0, 0x28(%rsp)
setne %cl
xorb $0x1, %al
testb %al, %cl
jne 0x61dc2
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x8320
cmpq 0x30(%rsp), %rbp
jae 0x61dfa
movq %rbx, %rdi
leaq 0xe5e7(%rip), %rsi      # 0x70344
callq 0x83a0
movq %r15, %r12
testq %r12, %r12
je 0x61dd3
movq %rbx, %rdi
leaq 0xe263(%rip), %rsi      # 0x6ffd7
callq 0x83a0
incq %r12
jmp 0x61d65
cmpq 0x30(%rsp), %rbp
jae 0x61db3
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq 0x80(%rsp), %rcx
movslq (%rcx,%rbp,8), %rcx
movq -0x18(%rax), %rax
movq %rcx, 0x10(%rbx,%rax)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x8320
jmp 0x61e11
movq %rbx, %rdi
leaq 0xe20b(%rip), %rsi      # 0x6ffd7
callq 0x83a0
jmp 0x61e11
movq 0x10(%rsp), %r12
cmpq %r13, %rbp
je 0x61dfa
movq 0x68(%rsp), %rdi
addq %r12, %rdi
leaq 0xe559(%rip), %rsi      # 0x70345
callq 0x87a0
decq %r13
addq $0x20, %r12
jmp 0x61dd8
addq 0x68(%rsp), %r14
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
callq 0x81d0
movq 0x20(%rsp), %r12
incq %rbp
decq %r15
addq $0x20, 0x10(%rsp)
movq 0x8(%rsp), %r14
jmp 0x61cd8
movq %rbx, %rdi
callq 0x81a0
movq 0x28(%rsp), %rax
incq %rax
jmp 0x61c9e
leaq 0x38(%rsp), %rdi
callq 0x84b0
leaq 0x68(%rsp), %rdi
callq 0x5c66e
leaq 0x80(%rsp), %rdi
callq 0x6253a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x61e8f
jmp 0x61e8f
movq %rax, %rbx
jmp 0x61ea5
jmp 0x61e8f
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x84b0
jmp 0x61eaf
jmp 0x61e8f
jmp 0x61e8f
jmp 0x61e98
movq %rax, %rbx
jmp 0x61eaf
jmp 0x61e98
jmp 0x61e98
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x84b0
leaq 0x68(%rsp), %rdi
callq 0x5c66e
leaq 0x80(%rsp), %rdi
callq 0x6253a
movq %rbx, %rdi
callq 0x86f0
movq %rax, %rdi
callq 0x5c505