// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq %rdx, 0x1c0(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0xc8(%rsp)
cmpq $0x0, 0x1c8(%rsp)
jne 0x9d71f
jmp 0x9de8f
movq 0xc8(%rsp), %rax
movq 0x1c8(%rsp), %rsi
movzbl 0x48(%rax), %edx
andl $0x1, %edx
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x9c000
movq 0xb8(%rsp), %rsi
movq 0x1c8(%rsp), %rdi
callq 0x9d160
movl %eax, 0xc4(%rsp)
jmp 0x9d769
movq 0xc8(%rsp), %rax
movl 0xc4(%rsp), %ecx
movslq %ecx, %rcx
movq %rcx, 0x1a0(%rsp)
testb $0x1, 0x48(%rax)
je 0x9da01
movq 0x1c8(%rsp), %rdi
callq 0x94ad0
movq %rax, 0xb0(%rsp)
jmp 0x9d7a4
movq 0xb0(%rsp), %rax
movq %rax, 0x188(%rsp)
movq $0x0, 0x180(%rsp)
movq 0x1c8(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x178(%rsp)
movq 0x180(%rsp), %rax
cmpq 0x178(%rsp), %rax
jae 0x9d9e9
movq 0x180(%rsp), %rax
cmpq 0x1a0(%rsp), %rax
jae 0x9d8c7
movq 0x1c0(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x94bf0
movq %rax, 0xa8(%rsp)
jmp 0x9d827
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x8350
movq %rax, 0x98(%rsp)
jmp 0x9d846
movq 0x98(%rsp), %rdi
leaq 0x1559f(%rip), %rsi     # 0xb2df4
callq 0x8400
jmp 0x9d85c
movq 0x180(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x170(%rsp)
cmpq $0x0, 0x170(%rsp)
jbe 0x9d8c2
movq 0x1c0(%rsp), %rdi
leaq 0x151fc(%rip), %rsi     # 0xb2a86
callq 0x8400
jmp 0x9d891
jmp 0x9d893
movq 0x170(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x170(%rsp)
jmp 0x9d870
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x9deaa
jmp 0x9d9bf
movq 0x180(%rsp), %rax
movq 0x178(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x9d989
movq 0x1c0(%rsp), %rdi
leaq -0x10873(%rip), %rsi    # 0x8d080
callq 0x8140
movq %rax, 0x90(%rsp)
jmp 0x9d902
movq 0x180(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x9e2c0
movq %rax, 0x88(%rsp)
jmp 0x9d921
movq 0x88(%rsp), %rax
movl (%rax), %edi
callq 0x8d0a0
movl %eax, 0x84(%rsp)
jmp 0x9d939
movq 0x90(%rsp), %rdi
movl 0x84(%rsp), %eax
movl %eax, 0x16c(%rsp)
movl 0x16c(%rsp), %esi
callq 0x84e0
movq %rax, 0x78(%rsp)
jmp 0x9d962
leaq 0x188(%rsp), %rdi
callq 0x94bf0
movq %rax, 0x70(%rsp)
jmp 0x9d976
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
callq 0x8350
jmp 0x9d987
jmp 0x9d9bd
movq 0x1c0(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x94bf0
movq %rax, 0x68(%rsp)
jmp 0x9d9aa
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0x8350
jmp 0x9d9bb
jmp 0x9d9bd
jmp 0x9d9bf
leaq 0x188(%rsp), %rdi
callq 0x94c10
jmp 0x9d9ce
jmp 0x9d9d0
movq 0x180(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x180(%rsp)
jmp 0x9d7d4
movq 0x1c0(%rsp), %rdi
movq 0x32590(%rip), %rsi     # 0xcff88
callq 0x8470
jmp 0x9d9ff
jmp 0x9da01
movq 0x1a0(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x85c0
jmp 0x9da1d
leaq 0x12f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x94930
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rcx
leaq 0x150(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x9e570
jmp 0x9da50
leaq 0x12f(%rsp), %rdi
callq 0x8dd20
leaq 0x130(%rsp), %rdi
callq 0x88f8
jmp 0x9da6c
leaq 0x108(%rsp), %rdi
callq 0x85c0
jmp 0x9da7b
movq $0x0, 0x100(%rsp)
movq 0x1c8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0xf8(%rsp)
movq 0x100(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x9de64
movq $0x0, 0xf0(%rsp)
movq 0x1c8(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
cmpq 0xe8(%rsp), %rax
jae 0x9de33
movq 0x1c8(%rsp), %rdi
addq $0x18, %rdi
movq 0x100(%rsp), %rsi
callq 0x94620
movq %rax, 0x48(%rsp)
jmp 0x9db07
movq 0x48(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0x94640
movq %rax, 0x40(%rsp)
jmp 0x9db20
movq 0x40(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x8050
jmp 0x9db34
movq 0xf0(%rsp), %rax
cmpq 0x1a0(%rsp), %rax
jae 0x9dd60
movq 0xf0(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x94600
movq %rax, 0x38(%rsp)
jmp 0x9db66
movq 0x38(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x8d190
movb %al, 0x37(%rsp)
jmp 0x9db7e
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x9db97
jmp 0x9db88
cmpq $0x0, 0x100(%rsp)
jne 0x9dd43
movq 0x1c0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x8350
jmp 0x9dbae
movq 0xf0(%rsp), %rax
movq 0xe8(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x9dd11
movq 0x1c0(%rsp), %rdi
leaq 0x1521a(%rip), %rsi     # 0xb2df4
callq 0x8400
jmp 0x9dbe1
movq 0xf0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xe0(%rsp)
cmpq $0x0, 0xe0(%rsp)
jbe 0x9dca6
movq 0x1c0(%rsp), %rdi
leaq 0x14e73(%rip), %rsi     # 0xb2a86
callq 0x8400
jmp 0x9dc1a
jmp 0x9dc1c
movq 0xe0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xe0(%rsp)
jmp 0x9dbf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x12f(%rsp), %rdi
callq 0x8dd20
leaq 0x130(%rsp), %rdi
callq 0x88f8
jmp 0x9dc62
jmp 0x9deaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x9de99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x88f8
jmp 0x9de97
movq 0xf0(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
cmpq 0x1a0(%rsp), %rax
jae 0x9dd0f
movq 0xd8(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x94600
movq %rax, 0x28(%rsp)
jmp 0x9dce4
movq 0x28(%rsp), %rdi
leaq 0x15105(%rip), %rsi     # 0xb2df5
callq 0x85a0
jmp 0x9dcf7
jmp 0x9dcf9
movq 0xd8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
jmp 0x9dcb6
jmp 0x9dd11
movq 0xf0(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x94600
movq %rax, 0x20(%rsp)
jmp 0x9dd2d
movq 0x20(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x8050
jmp 0x9dd41
jmp 0x9dd5b
movq 0x1c0(%rsp), %rdi
leaq 0x14d34(%rip), %rsi     # 0xb2a86
callq 0x8400
jmp 0x9dd59
jmp 0x9dd5b
jmp 0x9de18
movq 0xf0(%rsp), %rax
movq 0xe8(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x9ddfd
movq 0x1c0(%rsp), %rdi
leaq -0x10d0c(%rip), %rsi    # 0x8d080
callq 0x8140
movq %rax, 0x18(%rsp)
jmp 0x9dd98
movq 0xf0(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x9e2c0
movq %rax, 0x10(%rsp)
jmp 0x9ddb4
movq 0x10(%rsp), %rax
movl (%rax), %edi
callq 0x8d0a0
movl %eax, 0xc(%rsp)
jmp 0x9ddc6
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %eax
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %esi
callq 0x84e0
movq %rax, (%rsp)
jmp 0x9dde8
movq (%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x8350
jmp 0x9ddfb
jmp 0x9de16
movq 0x1c0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x8350
jmp 0x9de14
jmp 0x9de16
jmp 0x9de18
jmp 0x9de1a
movq 0xf0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xf0(%rsp)
jmp 0x9dad1
movq 0x1c0(%rsp), %rdi
movq 0x32146(%rip), %rsi     # 0xcff88
callq 0x8470
jmp 0x9de49
jmp 0x9de4b
movq 0x100(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x100(%rsp)
jmp 0x9da9b
leaq 0x108(%rsp), %rdi
callq 0x88f8
jmp 0x9de73
leaq 0x150(%rsp), %rdi
callq 0x8d860
jmp 0x9de82
leaq 0x1a8(%rsp), %rdi
callq 0x9e2e0
addq $0x1d8, %rsp            # imm = 0x1D8
retq
jmp 0x9de99
leaq 0x150(%rsp), %rdi
callq 0x8d860
jmp 0x9dea8
jmp 0x9deaa
leaq 0x1a8(%rsp), %rdi
callq 0x9e2e0
jmp 0x9deb9
jmp 0x9debb
movq 0x198(%rsp), %rdi
callq 0x87d0
movq %rax, %rdi
callq 0x8cf60