// File: 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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x4130
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, -0x158(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4160
movq -0x158(%rbp), %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
ja 0x3544
movq -0x8(%rbp), %rdi
leaq 0x9b70(%rip), %rsi      # 0xd0a4
callq 0x2190
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x34da
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x41c0
leaq -0x50(%rbp), %rdi
callq 0x3eb0
movq %rax, -0x168(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4160
movq -0x168(%rbp), %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jae 0x3629
movq -0x8(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x41c0
movq -0x180(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3fd0
movq -0x178(%rbp), %rdi
movl (%rax), %esi
callq 0x22e0
movq %rax, -0x170(%rbp)
jmp 0x35e5
movq -0x170(%rbp), %rdi
movl $0x20, %esi
callq 0x2220
jmp 0x35f8
leaq -0x68(%rbp), %rdi
callq 0x4160
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x354b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4160
jmp 0x3b3d
movq -0x8(%rbp), %rdi
movq 0x10984(%rip), %rsi     # 0x13fb8
callq 0x21c0
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rdi
callq 0x26f0
movq %rax, %rdi
callq 0x41f0
movq %rax, %rcx
movq -0x188(%rbp), %rax
cmpq %rcx, %rax
jae 0x399b
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq %rax, -0x190(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x4130
movl -0x78(%rbp), %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, -0x198(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4160
movq -0x198(%rbp), %rcx
movq -0x190(%rbp), %rax
cmpq %rcx, %rax
jae 0x3773
movq -0x8(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x4130
movq -0x1b0(%rbp), %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
movl -0x7c(%rbp), %eax
movl %eax, %esi
callq 0x3fd0
movq -0x1a8(%rbp), %rdi
movl (%rax), %esi
callq 0x22e0
movq %rax, -0x1a0(%rbp)
jmp 0x3729
movq -0x1a0(%rbp), %rdi
movl $0x20, %esi
callq 0x2220
jmp 0x373c
leaq -0xb0(%rbp), %rdi
callq 0x4160
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x3675
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4160
jmp 0x3b3d
movq -0x8(%rbp), %rdi
leaq 0x9929(%rip), %rsi      # 0xd0a7
callq 0x2190
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq %rax, -0x1b8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x26f0
movq %rax, %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x2710
movq %rax, %rdi
callq 0x4220
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x3859
movb $0x2d, -0xb5(%rbp)
movq -0x10(%rbp), %rdi
callq 0x26f0
movq %rax, %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x2710
movq %rax, %rdi
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0x2730
movl (%rax), %eax
movl %eax, -0x1bc(%rbp)
subl $0x1, %eax
je 0x3814
jmp 0x3807
movl -0x1bc(%rbp), %eax
subl $0x2, %eax
je 0x381d
jmp 0x3826
movb $0x4f, -0xb5(%rbp)
jmp 0x3828
movb $0x58, -0xb5(%rbp)
jmp 0x3828
jmp 0x3828
movq -0x8(%rbp), %rdi
movsbl -0xb5(%rbp), %esi
callq 0x2220
movq %rax, %rdi
movl $0x20, %esi
callq 0x2220
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x378d
movq -0x8(%rbp), %rdi
leaq 0x9846(%rip), %rsi      # 0xd0aa
callq 0x2190
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movq %rax, -0x1c8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x4130
movl -0x78(%rbp), %eax
movl %eax, %esi
leaq -0xd8(%rbp), %rdi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, -0x1d0(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x4160
movq -0x1d0(%rbp), %rcx
movq -0x1c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x397d
movq -0x8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x4130
movq -0x1e8(%rbp), %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x3fd0
movq -0x1e0(%rbp), %rdi
movl (%rax), %esi
callq 0x22e0
movq %rax, -0x1d8(%rbp)
jmp 0x392d
movq -0x1d8(%rbp), %rdi
movl $0x20, %esi
callq 0x2220
jmp 0x3940
leaq -0xf0(%rbp), %rdi
callq 0x4160
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x3873
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x4160
jmp 0x3b3d
movq -0x8(%rbp), %rdi
movq 0x10630(%rip), %rsi     # 0x13fb8
callq 0x21c0
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x3640
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movq %rax, -0x1f0(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x4130
leaq -0x110(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, -0x1f8(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x4160
movq -0x1f8(%rbp), %rcx
movq -0x1f0(%rbp), %rax
cmpq %rcx, %rax
ja 0x3a21
movq -0x8(%rbp), %rdi
leaq 0x9699(%rip), %rsi      # 0xd0a4
callq 0x2190
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x39a5
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
movq %rax, -0x200(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x41c0
leaq -0x130(%rbp), %rdi
callq 0x3eb0
movq %rax, -0x208(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x4160
movq -0x208(%rbp), %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
jae 0x3b24
movq -0x8(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x148(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x41c0
movq -0x220(%rbp), %rdi
movl -0x114(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3fd0
movq -0x218(%rbp), %rdi
movl (%rax), %esi
callq 0x22e0
movq %rax, -0x210(%rbp)
jmp 0x3ad7
movq -0x210(%rbp), %rdi
movl $0x20, %esi
callq 0x2220
jmp 0x3aea
leaq -0x148(%rbp), %rdi
callq 0x4160
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x3a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x4160
jmp 0x3b3d
movq -0x8(%rbp), %rdi
movq 0x10489(%rip), %rsi     # 0x13fb8
callq 0x21c0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)