// File: Kei18[P]pibt/./src/graph/simplegrid.cpp
// Function: SimpleGrid::createNodes()
void SimpleGrid::createNodes() {
  std::ifstream file(filename);
  if (!file) {
    std::cout << "error@SimpleGrid::createNodes, file "
              << filename
              << " does not exist" << "\n";
    std::exit(1);
  }

  std::string line;
  std::smatch results;
  std::regex r_map = std::regex(R"(map)");
  int w  = getW();
  int h = getH();
  int id;
  int j = 0;  // height
  bool mapStart = false;
  char s;

  while (getline(file, line)) {
    // for CRLF coding
    if (*(line.end()-1) == 0x0d) line.pop_back();

    if (mapStart) {
      // width check
      if (line.size() != w) {
        std::cout << "error@SimpleGrid::createNodes, "
                  << "width is invalid, should be " << w <<  "\n";
        std::exit(1);
      }
      for (int i = 0; i < w; ++i) {
        s = line[i];
        id = j * w + i;
        if (s == 'T' or s == '@') continue;
        Node* v = new Node(id);
        v->setPos(i, j);
        nodes.push_back(v);
      }
      ++j;
    }

    if (std::regex_match(line, results, r_map)) mapStart = true;
  }
  file.close();

  // height check
  if (j != h) {
    std::cout << "error@SimpleGrid::createNodes, "
              << "height is invalid, shoudl be " << h <<  "\n";
    std::exit(1);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x2c8(%rbp)
addq $0xa0, %rsi
leaq -0x210(%rbp), %rdi
movl $0x8, %edx
callq 0x8780
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x8260
movb %al, -0x2b9(%rbp)
jmp 0x4b012
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x4b021
jmp 0x4b0b2
movq 0xb5f70(%rip), %rdi     # 0x100f98
leaq 0x6a34d(%rip), %rsi     # 0xb537c
callq 0x84d0
movq %rax, -0x2d0(%rbp)
jmp 0x4b03d
movq -0x2d0(%rbp), %rdi
movq -0x2c8(%rbp), %rsi
addq $0xa0, %rsi
callq 0x8470
movq %rax, -0x2d8(%rbp)
jmp 0x4b060
movq -0x2d8(%rbp), %rdi
leaq 0x682be(%rip), %rsi     # 0xb332c
callq 0x84d0
movq %rax, -0x2e0(%rbp)
jmp 0x4b07c
movq -0x2e0(%rbp), %rdi
leaq 0x6852d(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4b091
movl $0x1, %edi
callq 0x85d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4b506
leaq -0x240(%rbp), %rdi
callq 0x86b0
leaq -0x260(%rbp), %rdi
callq 0xd430
jmp 0x4b0cc
leaq 0x68308(%rip), %rsi     # 0xb33db
leaq -0x280(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b0e6
movq -0x2c8(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x2e4(%rbp)
jmp 0x4b0fd
movq -0x2c8(%rbp), %rdi
movl -0x2e4(%rbp), %eax
movl %eax, -0x284(%rbp)
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
movl %eax, -0x2e8(%rbp)
jmp 0x4b121
movl -0x2e8(%rbp), %eax
movl %eax, -0x288(%rbp)
movl $0x0, -0x290(%rbp)
movb $0x0, -0x291(%rbp)
leaq -0x210(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x80f0
movq %rax, -0x2f0(%rbp)
jmp 0x4b15a
movq -0x2f0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8620
movb %al, -0x2f1(%rbp)
jmp 0x4b178
movb -0x2f1(%rbp), %al
testb $0x1, %al
jne 0x4b187
jmp 0x4b41b
leaq -0x240(%rbp), %rdi
callq 0x82f0
movq %rax, -0x2a8(%rbp)
leaq -0x2a8(%rbp), %rdi
movl $0x1, %esi
callq 0x4c150
movq %rax, -0x2a0(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x1b290
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x4b219
leaq -0x240(%rbp), %rdi
callq 0x85e0
jmp 0x4b219
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4b4fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4b4ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4b4e2
testb $0x1, -0x291(%rbp)
je 0x4b3df
leaq -0x240(%rbp), %rdi
callq 0x83b0
movslq -0x284(%rbp), %rcx
cmpq %rcx, %rax
je 0x4b2b0
movq 0xb5d53(%rip), %rdi     # 0x100f98
leaq 0x6a155(%rip), %rsi     # 0xb53a1
callq 0x84d0
movq %rax, -0x300(%rbp)
jmp 0x4b25a
movq -0x300(%rbp), %rdi
leaq 0x69fbd(%rip), %rsi     # 0xb5225
callq 0x84d0
movq %rax, -0x308(%rbp)
jmp 0x4b276
movq -0x308(%rbp), %rdi
movl -0x284(%rbp), %esi
callq 0x8860
movq %rax, -0x310(%rbp)
jmp 0x4b291
movq -0x310(%rbp), %rdi
leaq 0x68318(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4b2a6
movl $0x1, %edi
callq 0x85d0
movl $0x0, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x284(%rbp), %eax
jge 0x4b3d0
movslq -0x2ac(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x8930
movq %rax, -0x318(%rbp)
jmp 0x4b2e8
movq -0x318(%rbp), %rax
movb (%rax), %al
movb %al, -0x292(%rbp)
movl -0x290(%rbp), %eax
imull -0x284(%rbp), %eax
addl -0x2ac(%rbp), %eax
movl %eax, -0x28c(%rbp)
movsbl -0x292(%rbp), %eax
cmpl $0x54, %eax
je 0x4b328
movsbl -0x292(%rbp), %eax
cmpl $0x40, %eax
jne 0x4b32a
jmp 0x4b394
movl $0x28, %edi
callq 0x84e0
movq %rax, -0x320(%rbp)
jmp 0x4b33d
movq -0x320(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x48730
jmp 0x4b351
movq -0x320(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rdi
movl -0x2ac(%rbp), %esi
movl -0x290(%rbp), %edx
callq 0x4c190
jmp 0x4b379
movq -0x2c8(%rbp), %rdi
addq $0x10, %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3f490
jmp 0x4b392
jmp 0x4b394
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x4b2ba
movq -0x320(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
movl $0x28, %esi
callq 0x84f0
jmp 0x4b4e2
movl -0x290(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x290(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x280(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x321(%rbp)
jmp 0x4b403
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0x4b40f
jmp 0x4b416
movb $0x1, -0x291(%rbp)
jmp 0x4b13e
leaq -0x210(%rbp), %rdi
callq 0x8120
jmp 0x4b429
movl -0x290(%rbp), %eax
cmpl -0x288(%rbp), %eax
je 0x4b4a9
movq 0xb5b5a(%rip), %rdi     # 0x100f98
leaq 0x69f5c(%rip), %rsi     # 0xb53a1
callq 0x84d0
movq %rax, -0x330(%rbp)
jmp 0x4b453
movq -0x330(%rbp), %rdi
leaq 0x69e05(%rip), %rsi     # 0xb5266
callq 0x84d0
movq %rax, -0x338(%rbp)
jmp 0x4b46f
movq -0x338(%rbp), %rdi
movl -0x288(%rbp), %esi
callq 0x8860
movq %rax, -0x340(%rbp)
jmp 0x4b48a
movq -0x340(%rbp), %rdi
leaq 0x6811f(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4b49f
movl $0x1, %edi
callq 0x85d0
leaq -0x280(%rbp), %rdi
callq 0xd6d0
leaq -0x260(%rbp), %rdi
callq 0xd6b0
leaq -0x240(%rbp), %rdi
callq 0x8330
leaq -0x210(%rbp), %rdi
callq 0x8170
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x280(%rbp), %rdi
callq 0xd6d0
leaq -0x260(%rbp), %rdi
callq 0xd6b0
leaq -0x240(%rbp), %rdi
callq 0x8330
leaq -0x210(%rbp), %rdi
callq 0x8170
movq -0x218(%rbp), %rdi
callq 0x8880
nop