// File: bonetblai[P]mdp-engine/race/parsing.cc
// Function: grid_t::dump(std::ostream&, bool) const
void grid_t::dump(ostream &os, bool postscript) const {
    if( postscript ) ps::header(os, rows_, cols_);

    for( size_t y = 0; y < (size_t)rows_; ++y ) {
        for( size_t x = 0; x < (size_t)cols_; ++x ) {
            switch( map_[y*cols_ + x] ) {
                case Valid:
                    if( postscript )
                        ps::draw_filled_rectangle(os, x*BOXW, (rows_-1-y)*BOXW, BOXW, BOXW, 255, 255, 255);
                    else
                        os << '.';
                    break;
                case (Valid | Start):
                    if( postscript )
                        ps::draw_filled_rectangle(os, x*BOXW, (rows_-1-y)*BOXW, BOXW, BOXW, 0, 255, 255);
                    else
                        os << 's';
                    break;
                case (Valid | Goal):
                    if( postscript )
                        ps::draw_filled_rectangle(os, x*BOXW, (rows_-1-y)*BOXW, BOXW, BOXW, 255, 0, 0);
                    else
                        os << 'g';
                    break;
                default:
                    if( !postscript ) os << 'x';
                    break;
            }

#if 0
            if( postscript ) {
                // draw outer thick frame
                if( map_[y*cols_+x] & Valid ) {
                    if( (c == 0) || !(gridMap[r*cols + c - 1] & VALID) ) psDrawThickLine(x,(rows-1)*BOXW-y,0,BOXW);
                    if( c == cols - 1 ) psDrawThickLine(x+BOXW,(rows-1)*BOXW-y,0,BOXW);
                    if( (r == 0) || !(gridMap[(r-1)*cols + c] & VALID) ) psDrawThickLine(x-0.5,(rows-1)*BOXW-y+BOXW,BOXW+1,0);
                    if( r == rows - 1 ) psDrawThickLine(x-0.5,(rows-1)*BOXW-y,BOXW+1,0);
                } else {
                    if( (c != 0) && (gridMap[r*cols + c - 1] & VALID) ) psDrawThickLine(x,(rows-1)*BOXW-y,0,BOXW);
                    if( (r != 0) && (gridMap[(r-1)*cols + c] & VALID) ) psDrawThickLine(x-0.5,(rows-1)*BOXW-y+BOXW,BOXW+1,0);
                }
            }
#endif
        }
        if( !postscript ) os << endl;
    }

    if( postscript ) {
        ps::trailer(os);
    } else {
        os << "Valid positions = { ";
        for( size_t x = 0; x < (size_t)cols_; ++x ) {
            for( size_t y = 0; y < (size_t)rows_; ++y )
                if( valid_pos(x, y) ) os << "(" << x << "," << y << ") ";
        }
        os << "}" << endl;
    }
}

// Assembly:
subq $0x58, %rsp
movb %dl, %al
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
andb $0x1, %al
movb %al, 0x47(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
testb $0x1, 0x47(%rsp)
je 0x53e5e
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rdi
movslq 0x10(%rax), %rsi
movslq 0x14(%rax), %rdx
callq 0x53490
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %rax
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jae 0x5406a
movq $0x0, 0x30(%rsp)
movq 0x18(%rsp), %rcx
movq 0x30(%rsp), %rax
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jae 0x5403d
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rax
movq 0x38(%rsp), %rcx
movslq 0x14(%rdx), %rdx
imulq %rdx, %rcx
movq 0x30(%rsp), %rdx
addq %rdx, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, 0x14(%rsp)
subl $0x1, %eax
je 0x53ee8
jmp 0x53ecb
movl 0x14(%rsp), %eax
subl $0x3, %eax
je 0x53f4d
jmp 0x53ed6
movl 0x14(%rsp), %eax
subl $0x5, %eax
je 0x53fac
jmp 0x54010
testb $0x1, 0x47(%rsp)
je 0x53f39
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rdi
imulq $0xa, 0x30(%rsp), %rcx
movl %ecx, %esi
movl 0x10(%rax), %eax
subl $0x1, %eax
cltq
subq 0x38(%rsp), %rax
imulq $0xa, %rax, %rax
movl %eax, %edx
movl $0xa, %r8d
movl $0xff, %r9d
movl %r8d, %ecx
movl $0xff, (%rsp)
movl $0xff, 0x8(%rsp)
callq 0x53660
jmp 0x53f48
movq 0x48(%rsp), %rdi
movl $0x2e, %esi
callq 0x63b0
jmp 0x54028
testb $0x1, 0x47(%rsp)
je 0x53f9b
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rdi
imulq $0xa, 0x30(%rsp), %rcx
movl %ecx, %esi
movl 0x10(%rax), %eax
subl $0x1, %eax
cltq
subq 0x38(%rsp), %rax
imulq $0xa, %rax, %rax
movl %eax, %edx
movl $0xa, %r8d
xorl %r9d, %r9d
movl %r8d, %ecx
movl $0xff, (%rsp)
movl $0xff, 0x8(%rsp)
callq 0x53660
jmp 0x53faa
movq 0x48(%rsp), %rdi
movl $0x73, %esi
callq 0x63b0
jmp 0x54028
testb $0x1, 0x47(%rsp)
je 0x53fff
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rdi
imulq $0xa, 0x30(%rsp), %rcx
movl %ecx, %esi
movl 0x10(%rax), %eax
subl $0x1, %eax
cltq
subq 0x38(%rsp), %rax
imulq $0xa, %rax, %rax
movl %eax, %edx
movl $0xa, %r8d
movl $0xff, %r9d
xorl %eax, %eax
movl %r8d, %ecx
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x53660
jmp 0x5400e
movq 0x48(%rsp), %rdi
movl $0x67, %esi
callq 0x63b0
jmp 0x54028
testb $0x1, 0x47(%rsp)
jne 0x54026
movq 0x48(%rsp), %rdi
movl $0x78, %esi
callq 0x63b0
jmp 0x54028
jmp 0x5402a
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x53e87
testb $0x1, 0x47(%rsp)
jne 0x54055
movq 0x48(%rsp), %rdi
movq 0x22f68(%rip), %rsi     # 0x76fb8
callq 0x6340
jmp 0x54057
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x53e67
testb $0x1, 0x47(%rsp)
je 0x54080
movq 0x48(%rsp), %rdi
callq 0x53630
jmp 0x5417e
movq 0x48(%rsp), %rdi
leaq 0x4dfc(%rip), %rsi      # 0x58e88
callq 0x62f0
movq $0x0, 0x28(%rsp)
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jae 0x5415e
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jae 0x54149
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rax
movl %eax, %esi
movq 0x20(%rsp), %rax
movl %eax, %edx
callq 0xee20
testb $0x1, %al
jne 0x540eb
jmp 0x54134
movq 0x48(%rsp), %rdi
leaq 0x1d36(%rip), %rsi      # 0x55e2d
callq 0x62f0
movq %rax, %rdi
movq 0x28(%rsp), %rsi
callq 0x60a0
movq %rax, %rdi
leaq 0x1ade(%rip), %rsi      # 0x55bf1
callq 0x62f0
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x60a0
movq %rax, %rdi
leaq 0x4d6e(%rip), %rsi      # 0x58e9d
callq 0x62f0
jmp 0x54136
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x540ba
jmp 0x5414b
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x5409a
movq 0x48(%rsp), %rdi
leaq 0x4d36(%rip), %rsi      # 0x58ea0
callq 0x62f0
movq %rax, %rdi
movq 0x22e3f(%rip), %rsi     # 0x76fb8
callq 0x6340
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)