// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rdx, 0x20(%rsp)
callq 0x53a0
testq %rax, %rax
je 0x25c18
leaq 0x10(%r15), %rdx
leaq 0x14(%r15), %r13
leaq 0x53ac(%rip), %rsi      # 0x2add7
leaq 0x30(%rsp), %rdi
movq %rdx, 0x18(%rsp)
movq %r13, %rcx
xorl %eax, %eax
callq 0x5260
movl 0x10(%r15), %eax
testl %eax, %eax
je 0x25be9
movl (%r13), %ecx
testl %ecx, %ecx
je 0x25be9
movq %rbx, 0x10(%rsp)
cmpl $0x401, %ecx            # imm = 0x401
jae 0x25c29
imull %eax, %ecx
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnsl %ecx, %eax
movslq %eax, %rdi
callq 0x5030
movq %rax, 0x8(%r15)
leaq 0x30(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x18(%r15), %r14
xorl %ebp, %ebp
leaq 0xc(%rsp), %r12
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x20(%rsp), %rdx
callq 0x53a0
testq %rax, %rax
je 0x25c0a
movslq (%r13), %rax
testq %rax, %rax
je 0x25b85
xorl %ebx, %ebx
movzbl 0x30(%rsp,%rbx), %ecx
cmpl $0x72, %ecx
jg 0x25b09
cmpl $0x2e, %ecx
je 0x25b47
cmpl $0x67, %ecx
jne 0x25bab
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x5, (%rbx,%rax)
movl 0x14(%r15), %eax
imull %ebp, %eax
addq %rbx, %rax
movl %eax, 0xc(%rsp)
movq 0x38(%r15), %rsi
cmpq 0x40(%r15), %rsi
je 0x25b63
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%r15)
jmp 0x25b75
cmpl $0x78, %ecx
je 0x25b55
cmpl $0x73, %ecx
jne 0x25bab
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x3, (%rbx,%rax)
movl 0x14(%r15), %eax
imull %ebp, %eax
addq %rbx, %rax
movl %eax, 0xc(%rsp)
movq 0x20(%r15), %rsi
cmpq 0x28(%r15), %rsi
je 0x25b6a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%r15)
jmp 0x25b75
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x1, (%rbx,%rax)
jmp 0x25b75
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x8, (%rbx,%rax)
jmp 0x25b75
movq 0x28(%rsp), %rdi
jmp 0x25b6d
movq %r14, %rdi
movq %r12, %rdx
callq 0x25f54
incq %rbx
movslq (%r13), %rax
cmpq %rax, %rbx
jb 0x25ac1
incq %rbp
movq 0x18(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbp
jb 0x25a95
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5299(%rip), %rsi      # 0x2ae4b
movq 0x10(%rsp), %rdi
callq 0x5270
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5080
leaq 0x5291(%rip), %rsi      # 0x2ae5f
movq %rax, %rdi
callq 0x5270
movq %rax, %rdi
movq %rbp, %rsi
callq 0x5080
movq %rax, %rdi
callq 0x5130
movl $0x4, %edi
callq 0x5140
movl $0x0, (%rax)
movq 0x103b8(%rip), %rsi     # 0x35fb8
movq %rax, %rdi
xorl %edx, %edx
callq 0x5420
leaq 0x5220(%rip), %rsi      # 0x2ae31
movq 0x10(%rsp), %rdi
jmp 0x25bd1
leaq 0x519e(%rip), %rsi      # 0x2adbd
movq %rbx, %rdi
callq 0x5270
jmp 0x25be1
leaq 0x51b2(%rip), %rdi      # 0x2ade2
leaq 0x51c9(%rip), %rsi      # 0x2ae00
leaq 0x51cd(%rip), %rcx      # 0x2ae0b
movl $0x41, %edx
callq 0x5190