// File: /workspace/github_c_makefile_star2_O1/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 0x6f1e8
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r14
movzbl 0x48(%rdi), %edx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x6e22b
movq %r12, %rdi
movq %r15, %rsi
callq 0x6ebd0
cltq
movq %rax, 0x10(%rsp)
cmpb $0x1, 0x48(%r14)
movq %rbp, (%rsp)
movq %r12, 0x18(%rsp)
jne 0x6ef45
movq 0x38(%r12), %r15
testq %r15, %r15
je 0x6ef14
leaq -0x1(%r15), %rax
movq %rax, 0x28(%rsp)
movq $-0x1, %rbp
xorl %r14d, %r14d
leaq 0xf176(%rip), %r12      # 0x7dfe1
movq 0x18(%rsp), %r13
movq (%r13), %r13
cmpq 0x10(%rsp), %r14
jae 0x6eebb
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq (%rsp), %rdi
callq 0x8470
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf4c4(%rip), %rsi      # 0x7e35f
callq 0x8470
movq %rbp, %rbx
movl $0x4, %edx
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x8470
incq %rbx
jne 0x6eea3
jmp 0x6ef05
cmpq 0x28(%rsp), %r14
jae 0x6eef4
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 0x6ee70
movq (%rsp), %rbp
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x83c0
movq 0x18(%rsp), %r12
movsbl %al, %esi
movq %rbp, %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 0x10(%rsp), %rsi
callq 0x6f45e
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x6ef82
callq 0x8390
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq 0x30(%r12), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x6f1b8
movq $0x0, 0x20(%rsp)
movq 0x38(%r12), %rax
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x6f178
movq 0x28(%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
movq $-0x1, %r13
movq 0x20(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x60(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x18(%r12), %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 0x10(%rsp), %rbx
jae 0x6f04b
movq 0x68(%rsp), %rcx
movq 0x38(%rsp), %r12
movb $0x1, %al
cmpq 0x8(%rcx,%r14), %r12
jne 0x6f09a
testq %r12, %r12
je 0x6f098
addq %r14, %rcx
movq (%rcx), %rsi
movq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x8410
testl %eax, %eax
setne %al
jmp 0x6f09a
cmpq 0x50(%rsp), %rbx
jae 0x6f081
movq (%rbp), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbp,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbp,%rcx)
movq 0x80(%rsp), %rcx
movslq (%rcx,%rbx,8), %rcx
movq -0x18(%rax), %rax
movq %rcx, 0x10(%rbp,%rax)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %rdi
callq 0x8470
jmp 0x6f163
xorl %eax, %eax
cmpq $0x0, 0x20(%rsp)
je 0x6f0c4
testb %al, %al
jne 0x6f0c4
movl $0x4, %edx
movq %rbp, %rdi
leaq 0xef2c(%rip), %rsi      # 0x7dfe1
callq 0x8470
movq 0x18(%rsp), %r12
jmp 0x6f163
movq 0x30(%rsp), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x8470
cmpq 0x50(%rsp), %rbx
jae 0x6f148
movl $0x1, %edx
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0xf271(%rip), %rsi      # 0x7e35f
callq 0x8470
movq %r13, %r12
movl $0x4, %edx
movq %rbp, %rdi
leaq 0xeedc(%rip), %rsi      # 0x7dfe1
callq 0x8470
incq %r12
jne 0x6f0f6
movq %r15, %r12
movq %rbx, %rbp
cmpq 0x10(%rsp), %rbx
jae 0x6f148
movq 0x68(%rsp), %rdi
movq 0x8(%rdi,%r12), %rdx
addq %r12, %rdi
xorl %esi, %esi
leaq 0xf22e(%rip), %rcx      # 0x7e360
xorl %r8d, %r8d
callq 0x85f0
incq %rbp
addq $0x20, %r12
cmpq 0x10(%rsp), %rbp
jb 0x6f11c
addq 0x68(%rsp), %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x81f0
movq (%rsp), %rbp
movq 0x18(%rsp), %r12
incq %rbx
decq %r13
addq $0x20, %r15
cmpq 0x28(%rsp), %rbx
jne 0x6eff0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x83c0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8250
movq 0x20(%rsp), %rcx
incq %rcx
movq %rcx, 0x20(%rsp)
cmpq 0x58(%rsp), %rcx
jne 0x6efb6
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6f1cc
callq 0x8390
leaq 0x68(%rsp), %rdi
callq 0x68d64
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x6f1e8
callq 0x8390
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6f218
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x6f242
callq 0x8390
jmp 0x6f242
jmp 0x6f218
jmp 0x6f218
jmp 0x6f218
jmp 0x6f221
movq %rax, %rbx
jmp 0x6f242
jmp 0x6f221
jmp 0x6f221
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x6f238
callq 0x8390
leaq 0x68(%rsp), %rdi
callq 0x68d64
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x6f254
callq 0x8390
movq %rbx, %rdi
callq 0x8720
movq %rax, %rdi
callq 0x68c53