// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %rbx
movq %rsi, 0x20(%rsp)
leaq 0x20(%rsi), %r15
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
movl %ebp, %r12d
movq %r14, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r13
subq (%rax), %r13
sarq $0x2, %r13
movq %r14, %rdi
callq 0x2f78
cmpq %r12, %r13
jb 0x2b49
movq %rbx, %rdi
leaq 0x257f(%rip), %rsi      # 0x50bf
callq 0x2150
incl %ebp
jmp 0x2b0b
movq 0x20(%rsp), %rax
leaq 0x8(%rax), %r12
xorl %r14d, %r14d
leaq 0x8(%rsp), %r13
movl %r14d, %r14d
movq %r13, %rdi
movq %r12, %rsi
callq 0x320e
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %rbp
movq %r13, %rdi
callq 0x2f78
cmpq %r14, %rbp
jbe 0x2bc4
movq %r13, %rdi
movq %r12, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
imulq $0x18, %r14, %rcx
movq (%rax,%rcx), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x2220
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2180
movq %r13, %rdi
callq 0x2f78
incl %r14d
jmp 0x2b5a
movq %r12, 0x28(%rsp)
movq %rbx, %rdi
callq 0x20a0
xorl %esi, %esi
leaq 0x8(%rsp), %r13
movq 0x20(%rsp), %rcx
movl %esi, %esi
movq 0x40(%rcx), %rax
subq 0x38(%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x2d57
xorl %r12d, %r12d
movq %rsi, 0x30(%rsp)
imulq $0x18, %rsi, %r14
movl %r12d, %r12d
movq %r13, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq 0x8(%rax,%r14), %rbp
subq (%rax,%r14), %rbp
sarq $0x2, %rbp
movq %r13, %rdi
callq 0x2f78
cmpq %r12, %rbp
jbe 0x2c69
movq %r13, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq (%rax,%r14), %rax
movl (%rax,%r12,4), %esi
movq %rbx, %rdi
callq 0x2220
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2180
movq %r13, %rdi
callq 0x2f78
incl %r12d
jmp 0x2c04
movq %rbx, %rdi
leaq 0x244f(%rip), %rsi      # 0x50c2
callq 0x2150
xorl %r12d, %r12d
movq 0x20(%rsp), %rbp
movl %r12d, %r12d
movq 0x38(%rbp), %rcx
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0x2ccc
movl (%rax,%r12,4), %eax
pushq $0x58
popq %rsi
cmpl $0x2, %eax
je 0x2cab
pushq $0x2d
popq %rsi
cmpl $0x1, %eax
pushq $0x4f
popq %rax
cmovel %eax, %esi
movq %rbx, %rdi
callq 0x2180
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2180
incl %r12d
jmp 0x2c80
movq %rbx, %rdi
leaq 0x23ef(%rip), %rsi      # 0x50c5
callq 0x2150
xorl %r12d, %r12d
movl %r12d, %r12d
movq %r13, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq 0x8(%rax,%r14), %rbp
subq (%rax,%r14), %rbp
sarq $0x2, %rbp
movq %r13, %rdi
callq 0x2f78
cmpq %r12, %rbp
jbe 0x2d43
movq %r13, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq (%rax,%r14), %rax
movl (%rax,%r12,4), %esi
movq %rbx, %rdi
callq 0x2220
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2180
movq %r13, %rdi
callq 0x2f78
incl %r12d
jmp 0x2cde
movq %rbx, %rdi
callq 0x20a0
movq 0x30(%rsp), %rsi
incl %esi
jmp 0x2bd8
xorl %ebp, %ebp
leaq 0x8(%rsp), %r12
movl %ebp, %r14d
movq %r12, %rdi
movq %r15, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r13
subq (%rax), %r13
sarq $0x2, %r13
movq %r12, %rdi
callq 0x2f78
cmpq %r14, %r13
jb 0x2d9c
movq %rbx, %rdi
leaq 0x232c(%rip), %rsi      # 0x50bf
callq 0x2150
incl %ebp
jmp 0x2d5e
xorl %r14d, %r14d
leaq 0x8(%rsp), %r15
pushq $0x20
popq %rbp
movq 0x28(%rsp), %r13
movl %r14d, %r14d
movq %r15, %rdi
movq %r13, %rsi
callq 0x320e
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %r12
movq %r15, %rdi
callq 0x2f78
cmpq %r14, %r12
jbe 0x2e15
movq %r15, %rdi
movq %r13, %rsi
callq 0x320e
movq 0x8(%rsp), %rax
imulq $0x18, %r14, %rcx
movq (%rax,%rcx), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x2220
movq %rax, %rdi
movl %ebp, %esi
callq 0x2180
movq %r15, %rdi
callq 0x2f78
incl %r14d
jmp 0x2dac
movq %rbx, %rdi
callq 0x20a0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e32
jmp 0x2e32
jmp 0x2e32
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2f78
movq %rbx, %rdi
callq 0x2240
nop