// File: /workspace/github_cpp_makefile_star2_O1/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 0x63a0
testq %rax, %rax
je 0x27927
leaq 0x10(%r15), %rdx
leaq 0x14(%r15), %r13
leaq 0x4708(%rip), %rsi      # 0x2be37
leaq 0x30(%rsp), %rdi
movq %rdx, 0x18(%rsp)
movq %r13, %rcx
xorl %eax, %eax
callq 0x6260
movl 0x10(%r15), %eax
testl %eax, %eax
je 0x278f8
movl (%r13), %ecx
testl %ecx, %ecx
je 0x278f8
movq %rbx, 0x10(%rsp)
cmpl $0x401, %ecx            # imm = 0x401
jae 0x27938
imull %eax, %ecx
testl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnsl %ecx, %eax
movslq %eax, %rdi
callq 0x6030
movq %rax, 0x8(%r15)
cmpl $0x0, 0x10(%r15)
je 0x278a8
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 0x63a0
testq %rax, %rax
je 0x27919
movslq (%r13), %rax
testq %rax, %rax
je 0x27894
xorl %ebx, %ebx
movzbl 0x30(%rsp,%rbx), %ecx
cmpl $0x72, %ecx
jg 0x27818
cmpl $0x2e, %ecx
je 0x27856
cmpl $0x67, %ecx
jne 0x278ba
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 0x27872
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%r15)
jmp 0x27884
cmpl $0x78, %ecx
je 0x27864
cmpl $0x73, %ecx
jne 0x278ba
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 0x27879
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%r15)
jmp 0x27884
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x1, (%rbx,%rax)
jmp 0x27884
imulq %rbp, %rax
addq 0x8(%r15), %rax
movb $0x8, (%rbx,%rax)
jmp 0x27884
movq 0x28(%rsp), %rdi
jmp 0x2787c
movq %r14, %rdi
movq %r12, %rdx
callq 0x27c36
incq %rbx
movslq (%r13), %rax
cmpq %rax, %rbx
jb 0x277d0
incq %rbp
movq 0x18(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbp
jb 0x277a4
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45ea(%rip), %rsi      # 0x2beab
movq 0x10(%rsp), %rdi
callq 0x6270
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6080
leaq 0x45e2(%rip), %rsi      # 0x2bebf
movq %rax, %rdi
callq 0x6270
movq %rax, %rdi
movq %rbp, %rsi
callq 0x6080
movq %rax, %rdi
callq 0x6130
movl $0x4, %edi
callq 0x6140
movl $0x0, (%rax)
movq 0x106a9(%rip), %rsi     # 0x37fb8
movq %rax, %rdi
xorl %edx, %edx
callq 0x6420
leaq 0x4571(%rip), %rsi      # 0x2be91
movq 0x10(%rsp), %rdi
jmp 0x278e0
leaq 0x44ef(%rip), %rsi      # 0x2be1d
movq %rbx, %rdi
callq 0x6270
jmp 0x278f0
leaq 0x4503(%rip), %rdi      # 0x2be42
leaq 0x451a(%rip), %rsi      # 0x2be60
leaq 0x451e(%rip), %rcx      # 0x2be6b
movl $0x41, %edx
callq 0x6190
nop