// File: /workspace/github_cpp_makefile_star2_O1/Razakhel[P]RaZonogram/src/Grid.cpp
// Function: operator<<(std::ostream&, Grid&)
std::ostream& operator<<(std::ostream& os, Grid& grid) {
  // For each entry in rows' clues, prints two spaces to make a margin (plus two for the starting '[ ')
  // Ideally, should get the entry with maximum number of clues and remove the last space
  // TODO: should also handle numbers, not only digits
  for (unsigned int i = 0; i <= grid.getRowClues()[0].size(); ++i)
    os << "  ";

  for (unsigned int colIndex = 0; colIndex < grid.getColClues().size(); ++colIndex) // Prints columns' clues
    os << grid.getColClues()[colIndex][0] << ' ';
  os << std::endl;

  for (unsigned int height = 0; height < grid.getBoard().size(); ++height) { // For each row
    for (unsigned int rowIndex = 0; rowIndex < grid.getRowClues()[height].size(); ++rowIndex) // Prints rows' clues
      os << grid.getRowClues()[height][rowIndex] << ' ';

    // Prints the whole grid in the form:
    // [ X O X ]
    // [ - O X ]
    // [ - O - ]
    // Where the tiles marked as 'O' are filled, those with an 'X' are denied, and '-' means it's empty
    os << "[ ";
    for (unsigned int width = 0; width < grid.getBoard()[height].size(); ++width) { // For each tile
      char res = '-';
      switch (static_cast<State>(grid.getBoard()[height][width].state)) { // Prints ouput depending of the tile's state
        case State::FILLED:
          res = 'O';
          break;
        case State::DENIED:
          res = 'X';
          break;
        default:
          break;
      }
      os << res << ' ';
    }
    os << "] ";

    for (unsigned int rowIndex = 0; rowIndex < grid.getRowClues()[height].size(); ++rowIndex) // Prints rows' clues
      os << grid.getRowClues()[height][rowIndex] << ' ';
    os << std::endl;
  }

  // Prints margin again at the bottom of the grid
  for (unsigned int i = 0; i <= grid.getRowClues()[0].size(); ++i)
    os << "  ";
  for (unsigned int colIndex = 0; colIndex < grid.getColClues().size(); ++colIndex) // Prints columns' clues
    os << grid.getColClues()[colIndex][0] << ' ';

  return os << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq %rsi, 0x30(%rsp)
leaq 0x20(%rsi), %r15
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x390c
movq %r14, %rdi
callq 0x35a2
movl $0x1, %ebp
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x21b3(%rip), %rsi      # 0x50bf
callq 0x2190
movl %ebp, %r12d
movq %r14, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r13
subq (%rax), %r13
sarq $0x2, %r13
movq %r14, %rdi
callq 0x35a2
incl %ebp
cmpq %r12, %r13
jae 0x2efd
movq 0x30(%rsp), %rax
leaq 0x8(%rax), %rsi
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %rsi, 0x38(%rsp)
callq 0x390c
movq 0x8(%rbp), %r14
movq (%rbp), %r12
movq %rbp, %rdi
callq 0x35a2
cmpq %r12, %r14
je 0x300e
movl $0x1, %r12d
xorl %r13d, %r13d
leaq 0x10(%rsp), %rdi
movq %rdi, %r14
movq 0x38(%rsp), %rsi
movq %rsi, %rbp
callq 0x390c
movq 0x10(%rsp), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x2210
movb $0x20, 0xf(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2190
movq %r14, %rdi
callq 0x35a2
movl %r12d, %r13d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x390c
movq 0x18(%rsp), %rbp
subq 0x10(%rsp), %rbp
sarq $0x3, %rbp
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rbp
movq %r14, %rdi
callq 0x35a2
incl %r12d
cmpq %r13, %rbp
movq %r14, %rdi
ja 0x2f80
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x30(%rsp), %rcx
movq 0x40(%rcx), %rax
cmpq 0x38(%rcx), %rax
movq %rbx, 0x28(%rsp)
je 0x32a2
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq %r14, 0x40(%rsp)
leaq (%r14,%r14,2), %r14
movq 0x8(%rax,%r14,8), %r12
movq (%rax,%r14,8), %rbp
movq %r13, %rdi
callq 0x35a2
cmpq %rbp, %r12
je 0x30ff
movl $0x1, %r12d
xorl %ebp, %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rax
movl (%rax,%rbp,4), %esi
movq %rbx, %rdi
callq 0x2210
movb $0x20, 0xf(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2190
movq %r13, %rdi
callq 0x35a2
movl %r12d, %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14,8), %rbx
subq (%rax,%r14,8), %rbx
sarq $0x2, %rbx
movq %r13, %rdi
callq 0x35a2
incl %r12d
cmpq %rbp, %rbx
movq 0x28(%rsp), %rbx
ja 0x308c
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x1fb4(%rip), %rsi      # 0x50c2
callq 0x2190
movq 0x30(%rsp), %rbp
movq 0x38(%rbp), %rcx
movq (%rcx,%r14,8), %rax
cmpq %rax, 0x8(%rcx,%r14,8)
je 0x3194
movl $0x1, %r12d
xorl %ecx, %ecx
movl (%rax,%rcx,4), %ecx
movl $0x58, %eax
cmpl $0x2, %ecx
je 0x3141
movl $0x2d, %eax
cmpl $0x1, %ecx
movl $0x4f, %ecx
cmovel %ecx, %eax
movb %al, 0x10(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2190
movb $0x20, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2190
movl %r12d, %ecx
movq 0x38(%rbp), %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r12d
cmpq %rcx, %rdx
ja 0x312f
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x1f22(%rip), %rsi      # 0x50c5
callq 0x2190
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14,8), %rbx
movq (%rax,%r14,8), %r12
movq %r13, %rdi
callq 0x35a2
cmpq %r12, %rbx
je 0x3246
movl $0x1, %r12d
xorl %ebp, %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rax
movl (%rax,%rbp,4), %esi
movq 0x28(%rsp), %rdi
callq 0x2210
movb $0x20, 0xf(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2190
movq %r13, %rdi
callq 0x35a2
movl %r12d, %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14,8), %rbx
subq (%rax,%r14,8), %rbx
sarq $0x2, %rbx
movq %r13, %rdi
callq 0x35a2
incl %r12d
cmpq %rbp, %rbx
ja 0x31d6
movq 0x28(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x30(%rsp), %rcx
movq 0x40(%rcx), %rax
subq 0x38(%rcx), %rax
movq 0x40(%rsp), %r14
incl %r14d
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %r14, %rax
ja 0x3055
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x390c
movq %r12, %rdi
callq 0x35a2
movl $0x1, %ebp
movq %rbx, %r13
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1dee(%rip), %rsi      # 0x50bf
callq 0x2190
movl %ebp, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
sarq $0x2, %r14
movq %r12, %rdi
callq 0x35a2
incl %ebp
cmpq %rbx, %r14
jae 0x32c2
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq 0x38(%rsp), %r13
movq %r13, %rsi
callq 0x390c
movq 0x8(%r15), %rbx
movq (%r15), %r14
movq %r15, %rdi
callq 0x35a2
cmpq %r14, %rbx
je 0x33bb
movl $0x1, %ebp
xorl %r14d, %r14d
leaq 0x10(%rsp), %r15
leaq 0xf(%rsp), %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x390c
movq 0x10(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq 0x28(%rsp), %rdi
callq 0x2210
movb $0x20, 0xf(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r15, %rdi
callq 0x35a2
movl %ebp, %r14d
movq %r15, %rdi
movq %r13, %rsi
callq 0x390c
movq 0x18(%rsp), %rbx
subq 0x10(%rsp), %rbx
sarq $0x3, %rbx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rbx
movq %r15, %rdi
callq 0x35a2
incl %ebp
cmpq %r14, %rbx
ja 0x3341
movq 0x28(%rsp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33fc
jmp 0x33fc
jmp 0x33fc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x35a2
movq %rbx, %rdi
callq 0x2230
nop