// File: Kei18[P]pibt/./src/graph/simplegrid.cpp
// Function: SimpleGrid::createEdges()
void SimpleGrid::createEdges() {
  std::ifstream file(filename);
  if (!file) {
    std::cout << "error@SimpleGrid::createEdges, 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 j = 0;  // height
  int id;
  bool mapStart = false;
  Nodes neighbor;
  std::string s;
  Node* v;

  std::regex r_direction = std::regex(R"([a-z])");
  std::regex r_obj   = std::regex(R"([@T])");
  std::regex r_up    = std::regex(R"([\.oaefgkmn])");
  std::regex r_down  = std::regex(R"([\.ocfhjklm])");
  std::regex r_left  = std::regex(R"([\.odgijlmn])");
  std::regex r_right = std::regex(R"([\.obehikln])");

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

    if (mapStart) {
      for (int i = 0; i < w; ++i) {
        id = j * w + i;
        s = line[i];

        // object
        if (std::regex_match(s, results, r_obj)) continue;

        // digraph, default is undirected graph
        if (!isDirected() && std::regex_match(s, results, r_direction)) {
          setDirected(true);
        }

        if (!existNode(id)) {
          std::cout << "error@SimpleGrid::createEdges, "
                    << "corresponding node does not exist, " << id << "\n";
          std::exit(1);
        }
        v = getNode(id);  // target node
        neighbor.clear();

        if (std::regex_match(s, results, r_up)) {
          if (existNode(id - w)) neighbor.push_back(getNode(id - w));
        }
        if (i != 0 && std::regex_match(s, results, r_left)) {
          if (existNode(id - 1)) neighbor.push_back(getNode(id - 1));
        }
        if (i != w - 1 && std::regex_match(s, results, r_right)) {
          if (existNode(id + 1)) neighbor.push_back(getNode(id + 1));
        }
        if (std::regex_match(s, results, r_down)) {
          if (existNode(id + w)) neighbor.push_back(getNode(id + w));
        }
        v->setNeighbor(neighbor);
      }
      ++j;
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4a0, %rsp            # imm = 0x4A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x3f0(%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, -0x3e1(%rbp)
jmp 0x4b572
movb -0x3e1(%rbp), %al
testb $0x1, %al
jne 0x4b581
jmp 0x4b612
movq 0xb5a10(%rip), %rdi     # 0x100f98
leaq 0x69e32(%rip), %rsi     # 0xb53c1
callq 0x84d0
movq %rax, -0x3f8(%rbp)
jmp 0x4b59d
movq -0x3f8(%rbp), %rdi
movq -0x3f0(%rbp), %rsi
addq $0xa0, %rsi
callq 0x8470
movq %rax, -0x400(%rbp)
jmp 0x4b5c0
movq -0x400(%rbp), %rdi
leaq 0x67d5e(%rip), %rsi     # 0xb332c
callq 0x84d0
movq %rax, -0x408(%rbp)
jmp 0x4b5dc
movq -0x408(%rbp), %rdi
leaq 0x67fcd(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4b5f1
movl $0x1, %edi
callq 0x85d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bf31
leaq -0x240(%rbp), %rdi
callq 0x86b0
leaq -0x260(%rbp), %rdi
callq 0xd430
jmp 0x4b62c
leaq 0x67da8(%rip), %rsi     # 0xb33db
leaq -0x280(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b646
movq -0x3f0(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movl %eax, -0x40c(%rbp)
jmp 0x4b65d
movl -0x40c(%rbp), %eax
movl %eax, -0x284(%rbp)
movl $0x0, -0x288(%rbp)
movb $0x0, -0x28d(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x3e880
leaq -0x2c8(%rbp), %rdi
callq 0x86b0
leaq 0x69d4d(%rip), %rsi     # 0xb53e6
leaq -0x2f0(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b6ac
leaq 0x69b4b(%rip), %rsi     # 0xb51fe
leaq -0x310(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b6c6
leaq 0x69d1f(%rip), %rsi     # 0xb53ec
leaq -0x330(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b6e0
leaq 0x69d12(%rip), %rsi     # 0xb53f9
leaq -0x350(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b6fa
leaq 0x69d05(%rip), %rsi     # 0xb5406
leaq -0x370(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b714
leaq 0x69cf8(%rip), %rsi     # 0xb5413
leaq -0x390(%rbp), %rdi
movl $0x10, %edx
callq 0xd390
jmp 0x4b72e
jmp 0x4b730
leaq -0x210(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x80f0
movq %rax, -0x418(%rbp)
jmp 0x4b74c
movq -0x418(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x8620
movb %al, -0x419(%rbp)
jmp 0x4b76a
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x4b779
jmp 0x4be06
leaq -0x240(%rbp), %rdi
callq 0x82f0
movq %rax, -0x3a0(%rbp)
leaq -0x3a0(%rbp), %rdi
movl $0x1, %esi
callq 0x4c150
movq %rax, -0x398(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x1b290
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x4b8b3
leaq -0x240(%rbp), %rdi
callq 0x85e0
jmp 0x4b8b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bf25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bf19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bf0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bedd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bed1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bec5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4beb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x4bead
testb $0x1, -0x28d(%rbp)
je 0x4bdca
movl $0x0, -0x3a4(%rbp)
movl -0x3a4(%rbp), %eax
cmpl -0x284(%rbp), %eax
jge 0x4bdbb
movl -0x288(%rbp), %eax
movl -0x284(%rbp), %ecx
imull %ecx, %eax
movl -0x3a4(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x28c(%rbp)
movslq -0x3a4(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x8930
movq %rax, -0x428(%rbp)
jmp 0x4b915
movq -0x428(%rbp), %rax
movsbl (%rax), %esi
leaq -0x2c8(%rbp), %rdi
callq 0x87d0
jmp 0x4b92d
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x310(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x429(%rbp)
jmp 0x4b951
movb -0x429(%rbp), %al
testb $0x1, %al
jne 0x4b95d
jmp 0x4b962
jmp 0x4bd84
movq -0x3f0(%rbp), %rdi
callq 0x4c1d0
movb %al, -0x42a(%rbp)
jmp 0x4b976
movb -0x42a(%rbp), %al
testb $0x1, %al
jne 0x4b9c7
jmp 0x4b982
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x2f0(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x42b(%rbp)
jmp 0x4b9a6
movb -0x42b(%rbp), %al
testb $0x1, %al
jne 0x4b9b2
jmp 0x4b9c7
movq -0x3f0(%rbp), %rdi
movl $0x1, %esi
callq 0x4c1f0
jmp 0x4b9c5
jmp 0x4b9c7
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x3c7d0
movb %al, -0x42c(%rbp)
jmp 0x4b9e1
movb -0x42c(%rbp), %al
testb $0x1, %al
jne 0x4ba5f
jmp 0x4b9ed
movq 0xb55a4(%rip), %rdi     # 0x100f98
leaq 0x69a25(%rip), %rsi     # 0xb5420
callq 0x84d0
movq %rax, -0x438(%rbp)
jmp 0x4ba09
movq -0x438(%rbp), %rdi
leaq 0x6982b(%rip), %rsi     # 0xb5242
callq 0x84d0
movq %rax, -0x440(%rbp)
jmp 0x4ba25
movq -0x440(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x8860
movq %rax, -0x448(%rbp)
jmp 0x4ba40
movq -0x448(%rbp), %rdi
leaq 0x67b69(%rip), %rsi     # 0xb35b7
callq 0x84d0
jmp 0x4ba55
movl $0x1, %edi
callq 0x85d0
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x3c590
movq %rax, -0x450(%rbp)
jmp 0x4ba7a
movq -0x450(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x3e9f0
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x330(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x451(%rbp)
jmp 0x4bab8
movb -0x451(%rbp), %al
testb $0x1, %al
jne 0x4bac4
jmp 0x4bb3c
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
movl -0x284(%rbp), %eax
subl %eax, %esi
callq 0x3c7d0
movb %al, -0x452(%rbp)
jmp 0x4bae6
movb -0x452(%rbp), %al
testb $0x1, %al
jne 0x4baf2
jmp 0x4bb3a
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
movl -0x284(%rbp), %eax
subl %eax, %esi
callq 0x3c590
movq %rax, -0x460(%rbp)
jmp 0x4bb15
movq -0x460(%rbp), %rax
movq %rax, -0x3b0(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x4c210
jmp 0x4bb38
jmp 0x4bb3a
jmp 0x4bb3c
cmpl $0x0, -0x3a4(%rbp)
je 0x4bbe5
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x370(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x461(%rbp)
jmp 0x4bb6d
movb -0x461(%rbp), %al
testb $0x1, %al
jne 0x4bb79
jmp 0x4bbe5
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
decl %esi
callq 0x3c7d0
movb %al, -0x462(%rbp)
jmp 0x4bb95
movb -0x462(%rbp), %al
testb $0x1, %al
jne 0x4bba1
jmp 0x4bbe3
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
decl %esi
callq 0x3c590
movq %rax, -0x470(%rbp)
jmp 0x4bbbe
movq -0x470(%rbp), %rax
movq %rax, -0x3b8(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x4c210
jmp 0x4bbe1
jmp 0x4bbe3
jmp 0x4bbe5
movl -0x3a4(%rbp), %eax
movl -0x284(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x4bc98
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x390(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x471(%rbp)
jmp 0x4bc20
movb -0x471(%rbp), %al
testb $0x1, %al
jne 0x4bc2c
jmp 0x4bc98
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
incl %esi
callq 0x3c7d0
movb %al, -0x472(%rbp)
jmp 0x4bc48
movb -0x472(%rbp), %al
testb $0x1, %al
jne 0x4bc54
jmp 0x4bc96
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
incl %esi
callq 0x3c590
movq %rax, -0x480(%rbp)
jmp 0x4bc71
movq -0x480(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x4c210
jmp 0x4bc94
jmp 0x4bc96
jmp 0x4bc98
leaq -0x2c8(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x350(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x481(%rbp)
jmp 0x4bcbc
movb -0x481(%rbp), %al
testb $0x1, %al
jne 0x4bcc8
jmp 0x4bd40
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
movl -0x284(%rbp), %eax
addl %eax, %esi
callq 0x3c7d0
movb %al, -0x482(%rbp)
jmp 0x4bcea
movb -0x482(%rbp), %al
testb $0x1, %al
jne 0x4bcf6
jmp 0x4bd3e
movq -0x3f0(%rbp), %rdi
movl -0x28c(%rbp), %esi
movl -0x284(%rbp), %eax
addl %eax, %esi
callq 0x3c590
movq %rax, -0x490(%rbp)
jmp 0x4bd19
movq -0x490(%rbp), %rax
movq %rax, -0x3c8(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0x4c210
jmp 0x4bd3c
jmp 0x4bd3e
jmp 0x4bd40
movq -0x2d0(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0x3e0(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x3aff0
jmp 0x4bd63
movq -0x498(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x4c240
jmp 0x4bd78
leaq -0x3e0(%rbp), %rdi
callq 0xd7d0
movl -0x3a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3a4(%rbp)
jmp 0x4b8ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0xd7d0
jmp 0x4bead
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x288(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x280(%rbp), %rdx
xorl %ecx, %ecx
callq 0xd470
movb %al, -0x499(%rbp)
jmp 0x4bdee
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x4bdfa
jmp 0x4be01
movb $0x1, -0x28d(%rbp)
jmp 0x4b730
leaq -0x210(%rbp), %rdi
callq 0x8120
jmp 0x4be14
leaq -0x390(%rbp), %rdi
callq 0xd6d0
leaq -0x370(%rbp), %rdi
callq 0xd6d0
leaq -0x350(%rbp), %rdi
callq 0xd6d0
leaq -0x330(%rbp), %rdi
callq 0xd6d0
leaq -0x310(%rbp), %rdi
callq 0xd6d0
leaq -0x2f0(%rbp), %rdi
callq 0xd6d0
leaq -0x2c8(%rbp), %rdi
callq 0x8330
leaq -0x2a8(%rbp), %rdi
callq 0xd7d0
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 $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
leaq -0x390(%rbp), %rdi
callq 0xd6d0
leaq -0x370(%rbp), %rdi
callq 0xd6d0
leaq -0x350(%rbp), %rdi
callq 0xd6d0
leaq -0x330(%rbp), %rdi
callq 0xd6d0
leaq -0x310(%rbp), %rdi
callq 0xd6d0
leaq -0x2f0(%rbp), %rdi
callq 0xd6d0
leaq -0x2c8(%rbp), %rdi
callq 0x8330
leaq -0x2a8(%rbp), %rdi
callq 0xd7d0
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
nopl (%rax)