// File: bonetblai[P]mdp-engine/race/parsing.cc
// Function: grid_t::parse(std::ostream&, _IO_FILE*)
void grid_t::parse(ostream &os, FILE *is) {
    char buff[1024];
    if( fgets(buff, sizeof(buff), is) == NULL ) {
        os << "error reading file header" << endl;
        throw(0);
    } else {
        sscanf(buff, "dim: %u %u", &rows_, &cols_);
        if( (rows_ == 0) || (cols_ == 0) ) throw( 0 );
        assert((size_t)cols_ <= sizeof(buff));
        map_ = new char[rows_ * cols_];
    }

    // parse file
    for( size_t r = 0; r < (size_t)rows_; ++r ) {
        if( fgets(buff, sizeof(buff), is) == NULL ) {
            os << " error while reading row " << r << endl;
            throw(0);
        }
        for( size_t c = 0; c < (size_t)cols_; ++c ) {
            switch( buff[c] ) {
                case 's':
                    map_[r*cols_ + c] = Valid | Start;
                    starts_.push_back(r*cols_ + c);
                    break;
                case 'g':
                    map_[r*cols_ + c] = Valid | Goal;
                    goals_.push_back(r*cols_ + c);
                    break;
                case '.':
                    map_[r*cols_ + c] = Valid;
                    break;
                case 'x':
                    map_[r*cols_ + c] = Invalid;
                    break;
                default:
                    os << " error reading col " << c << " of row " << r << endl;
                    throw(0);
            }
        }
    }
}

// Assembly:
subq $0x448, %rsp            # imm = 0x448
movq %rdi, 0x440(%rsp)
movq %rsi, 0x438(%rsp)
movq %rdx, 0x430(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movq 0x430(%rsp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x6490
cmpq $0x0, %rax
jne 0x53aef
movq 0x438(%rsp), %rdi
leaq 0x5325(%rip), %rsi      # 0x58ddd
callq 0x62f0
movq %rax, %rdi
movq 0x234f1(%rip), %rsi     # 0x76fb8
callq 0x6340
movl $0x4, %edi
callq 0x6150
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x234c2(%rip), %rsi     # 0x76fa8
xorl %eax, %eax
movl %eax, %edx
callq 0x6510
movq 0x10(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movq %rcx, %rdx
addq $0x10, %rdx
addq $0x14, %rcx
leaq 0x52ec(%rip), %rsi      # 0x58df7
movb $0x0, %al
callq 0x62e0
movq 0x10(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x53b28
movq 0x10(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x53b4b
movl $0x4, %edi
callq 0x6150
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x23466(%rip), %rsi     # 0x76fa8
xorl %eax, %eax
movl %eax, %edx
callq 0x6510
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
cmpq $0x400, %rax            # imm = 0x400
ja 0x53b5e
jmp 0x53b7d
leaq 0x529d(%rip), %rdi      # 0x58e02
leaq 0x52b4(%rip), %rsi      # 0x58e20
movl $0x41, %edx
leaq 0x52b3(%rip), %rcx      # 0x58e2b
callq 0x61c0
movq 0x10(%rsp), %rcx
movl 0x10(%rcx), %eax
imull 0x14(%rcx), %eax
movslq %eax, %rdi
movq $-0x1, %rax
cmpq $0x0, %rdi
cmovlq %rax, %rdi
callq 0x6030
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, 0x28(%rsp)
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jae 0x53e11
leaq 0x30(%rsp), %rdi
movq 0x430(%rsp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x6490
cmpq $0x0, %rax
jne 0x53c3c
movq 0x438(%rsp), %rdi
leaq 0x5259(%rip), %rsi      # 0x58e51
callq 0x62f0
movq %rax, %rdi
movq 0x28(%rsp), %rsi
callq 0x60a0
movq %rax, %rdi
movq 0x233a4(%rip), %rsi     # 0x76fb8
callq 0x6340
movl $0x4, %edi
callq 0x6150
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x23375(%rip), %rsi     # 0x76fa8
xorl %eax, %eax
movl %eax, %edx
callq 0x6510
movq $0x0, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jae 0x53dfc
movq 0x20(%rsp), %rax
movsbl 0x30(%rsp,%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x2e, %eax
je 0x53d33
jmp 0x53c75
movl 0xc(%rsp), %eax
subl $0x67, %eax
je 0x53ce8
jmp 0x53c80
movl 0xc(%rsp), %eax
subl $0x73, %eax
je 0x53c9d
jmp 0x53c8b
movl 0xc(%rsp), %eax
subl $0x78, %eax
je 0x53d57
jmp 0x53d78
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rsp), %rdx
movslq 0x14(%rcx), %rsi
imulq %rsi, %rdx
addq 0x20(%rsp), %rdx
movb $0x3, (%rax,%rdx)
movq %rcx, %rdi
addq $0x18, %rdi
movq 0x28(%rsp), %rax
movslq 0x14(%rcx), %rcx
imulq %rcx, %rax
addq 0x20(%rsp), %rax
movl %eax, 0x1c(%rsp)
leaq 0x1c(%rsp), %rsi
callq 0x54190
jmp 0x53de7
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rsp), %rdx
movslq 0x14(%rcx), %rsi
imulq %rsi, %rdx
addq 0x20(%rsp), %rdx
movb $0x5, (%rax,%rdx)
movq %rcx, %rdi
addq $0x30, %rdi
movq 0x28(%rsp), %rax
movslq 0x14(%rcx), %rcx
imulq %rcx, %rax
addq 0x20(%rsp), %rax
movl %eax, 0x18(%rsp)
leaq 0x18(%rsp), %rsi
callq 0x54190
jmp 0x53de7
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rax
movq 0x28(%rsp), %rcx
movslq 0x14(%rdx), %rdx
imulq %rdx, %rcx
addq 0x20(%rsp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x53de7
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rax
movq 0x28(%rsp), %rcx
movslq 0x14(%rdx), %rdx
imulq %rdx, %rcx
addq 0x20(%rsp), %rcx
movb $0x8, (%rax,%rcx)
jmp 0x53de7
movq 0x438(%rsp), %rdi
leaq 0x50e4(%rip), %rsi      # 0x58e6b
callq 0x62f0
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x60a0
movq %rax, %rdi
leaq 0x50dc(%rip), %rsi      # 0x58e7f
callq 0x62f0
movq %rax, %rdi
movq 0x28(%rsp), %rsi
callq 0x60a0
movq %rax, %rdi
movq 0x231f9(%rip), %rsi     # 0x76fb8
callq 0x6340
movl $0x4, %edi
callq 0x6150
movq %rax, %rdi
movl $0x0, (%rdi)
movq 0x231ca(%rip), %rsi     # 0x76fa8
xorl %eax, %eax
movl %eax, %edx
callq 0x6510
jmp 0x53de9
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x53c45
jmp 0x53dfe
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x53bb5
addq $0x448, %rsp            # imm = 0x448
retq
nopl (%rax)