// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rdi, %rbx
leaq 0xa0(%rdi), %r14
leaq 0x1d0(%rsp), %r15
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x65a0
movq (%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1f0(%rsp,%rax)
jne 0x1aa47
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
leaq 0x1fe39(%rip), %rsi     # 0x3a387
leaq 0x198(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq %rax, 0x48(%rsp)
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x188(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x21c2f(%rip), %rsi     # 0x3c1c3
leaq 0x158(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
leaq 0x21a2c(%rip), %rsi     # 0x3bfd7
leaq 0x138(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
leaq 0x21c07(%rip), %rsi     # 0x3c1c9
leaq 0x118(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
leaq 0x21bfd(%rip), %rsi     # 0x3c1d6
leaq 0xf8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
leaq 0x21bf3(%rip), %rsi     # 0x3c1e3
leaq 0xd8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
leaq 0x21be9(%rip), %rsi     # 0x3c1f0
leaq 0xb8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x9162
xorl %r15d, %r15d
movq 0x48(%rsp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0xb0(%rsp)
decl %eax
movq %rax, 0xa8(%rsp)
leaq 0x1d0(%rsp), %r14
leaq 0x178(%rsp), %r13
leaq 0x1b8(%rsp), %rbp
movq $0x0, 0x40(%rsp)
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
callq 0x60b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1a94c
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rcx
cmpb $0xd, -0x1(%rax,%rcx)
jne 0x1a699
leaq 0x78(%rsp), %rdi
callq 0x6460
testb $0x1, 0x40(%rsp)
je 0x1a90c
movl %r15d, %ecx
movq 0x48(%rsp), %rax
imull %eax, %ecx
movq %rcx, 0x18(%rsp)
leal 0x1(%r15), %ecx
movl %eax, %edx
movl %ecx, 0x14(%rsp)
imull %ecx, %edx
movq %rdx, 0x98(%rsp)
decl %r15d
imull %eax, %r15d
movq %r15, 0xa0(%rsp)
xorl %r14d, %r14d
cmpq %r14, 0xb0(%rsp)
je 0x1a913
movq 0x78(%rsp), %rax
movsbl (%rax,%r14), %esi
movq %r13, %rdi
callq 0x65e0
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x138(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
jne 0x1a904
cmpb $0x0, 0x8(%rbx)
jne 0x1a73f
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x158(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
je 0x1a73f
movb $0x1, 0x8(%rbx)
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %r15
movq %rbx, %rdi
movl %r15d, %esi
callq 0x16428
testb %al, %al
je 0x1a9fe
movq %rbx, %rdi
movl %r15d, %esi
callq 0x16206
movq %rax, %r15
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x1a77a
movq %rax, 0x28(%rsp)
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x118(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
je 0x1a7cf
movq 0xa0(%rsp), %rax
leaq (%rax,%r14), %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16428
testb %al, %al
je 0x1a7cf
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16206
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1aca4
testq %r14, %r14
je 0x1a829
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
je 0x1a829
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %r12
decq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16428
testb %al, %al
je 0x1a829
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16206
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1aca4
cmpq %r14, 0xa8(%rsp)
je 0x1a888
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
je 0x1a888
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %r12
incq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16428
testb %al, %al
je 0x1a888
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16206
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1aca4
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
testb %al, %al
je 0x1a8dd
movq 0x98(%rsp), %rax
leaq (%rax,%r14), %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16428
testb %al, %al
je 0x1a8dd
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16206
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1aca4
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x15d3a
addq $0x8, %r15
movq %r15, %rdi
movq %rbp, %r15
movq %rbp, %rsi
callq 0x16f90
movq %r15, %rdi
callq 0x990e
incq %r14
jmp 0x1a6db
movl %r15d, 0x14(%rsp)
jmp 0x1a91b
leaq 0x1d0(%rsp), %r14
leaq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x198(%rsp), %rdx
xorl %ecx, %ecx
callq 0x91c8
movq 0x40(%rsp), %rcx
orb %al, %cl
movq %rcx, 0x40(%rsp)
movl 0x14(%rsp), %eax
movl %eax, %r15d
jmp 0x1a65c
leaq 0x1d0(%rsp), %rdi
callq 0x60d0
leaq 0xb8(%rsp), %rdi
callq 0x9260
leaq 0xd8(%rsp), %rdi
callq 0x9260
leaq 0xf8(%rsp), %rdi
callq 0x9260
leaq 0x118(%rsp), %rdi
callq 0x9260
leaq 0x138(%rsp), %rdi
callq 0x9260
leaq 0x158(%rsp), %rdi
callq 0x9260
leaq 0x178(%rsp), %rdi
callq 0x61d0
leaq 0x20(%rsp), %rdi
callq 0x990e
leaq 0x198(%rsp), %rdi
callq 0x9260
leaq 0x50(%rsp), %rdi
callq 0x9690
leaq 0x78(%rsp), %rdi
callq 0x61d0
leaq 0x1d0(%rsp), %rdi
callq 0x6120
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f593(%rip), %rdi     # 0x59f98
leaq 0x217f1(%rip), %rsi     # 0x3c1fd
callq 0x63a0
leaq 0x21603(%rip), %rsi     # 0x3c01b
movq %rax, %rdi
callq 0x63a0
movq 0x18(%rsp), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x6630
leaq 0x1fb2c(%rip), %rsi     # 0x3a563
movq %rax, %rdi
callq 0x63a0
pushq $0x1
popq %rdi
callq 0x6450
movq 0x3f54a(%rip), %rdi     # 0x59f98
leaq 0x21749(%rip), %rsi     # 0x3c19e
callq 0x63a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x6360
leaq 0x1f86c(%rip), %rsi     # 0x3a2d8
movq %rax, %rdi
callq 0x63a0
leaq 0x1fae8(%rip), %rsi     # 0x3a563
movq %rax, %rdi
callq 0x63a0
jmp 0x1aa3f
movq %rax, %rbx
jmp 0x1ab64
jmp 0x1aadb
movq %rax, %rbx
jmp 0x1aaeb
movq %rax, %rbx
jmp 0x1aaf8
movq %rax, %rbx
jmp 0x1ab05
movq %rax, %rbx
jmp 0x1ab12
movq %rax, %rbx
jmp 0x1ab1f
movq %rax, %rbx
jmp 0x1ab2c
movq %rax, %rbx
jmp 0x1ab43
movq %rax, %rbx
jmp 0x1ab50
jmp 0x1aadb
jmp 0x1aadb
jmp 0x1aadb
jmp 0x1aadb
jmp 0x1aadb
jmp 0x1aadb
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x990e
jmp 0x1aade
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x9260
leaq 0xd8(%rsp), %rdi
callq 0x9260
leaq 0xf8(%rsp), %rdi
callq 0x9260
leaq 0x118(%rsp), %rdi
callq 0x9260
leaq 0x138(%rsp), %rdi
callq 0x9260
leaq 0x158(%rsp), %rdi
callq 0x9260
leaq 0x178(%rsp), %rdi
callq 0x61d0
leaq 0x20(%rsp), %rdi
callq 0x990e
leaq 0x198(%rsp), %rdi
callq 0x9260
leaq 0x50(%rsp), %rdi
callq 0x9690
leaq 0x78(%rsp), %rdi
callq 0x61d0
leaq 0x1d0(%rsp), %rdi
callq 0x6120
movq %rbx, %rdi
callq 0x6650
nop