// File: davidjosepha[P]slitherlink/src/shared/import.cpp
// Function: Import::buildLattice(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Import::buildLattice(std::string filename) {
    std::string buffer;
    std::ifstream slkfile(filename);

    if (slkfile.is_open()) {

        /* source info */
        std::getline(slkfile, buffer);

        /* get dimensions */
        int m, n;
        slkfile >> m;
        slkfile >> n;
        lattice_->initArrays(m+2, n+2);
        lattice_->initUpdateMatrix();

        /* blank lines */
        std::getline(slkfile, buffer);
        std::getline(slkfile, buffer);

        /* numbers */
        for (int i = 0; i < m; i++) {
            std::getline(slkfile, buffer);
            importNumberRow(i+1, buffer);
        }

        /* blank line */
        std::getline(slkfile, buffer);

        /* horizontal lines */
        for (int i = 0; i < m+1; i++) {
            std::getline(slkfile, buffer);
            importHLineRow(i+1, buffer);
        }
        for (int j = 0; j < n+2; j++) {
            lattice_->setHLine(0, j, NLINE);
            lattice_->setHLine(m+2, j, NLINE);
        }

        /* blank line */
        std::getline(slkfile, buffer);

        /* vertical lines */
        for (int j = 0; j < n+3; j++) {
            lattice_->setVLine(0, j, NLINE);
            lattice_->setVLine(m+1, j, NLINE);
        }
        for (int i = 0; i < m+2; i++) {
            lattice_->setVLine(i, 0, NLINE);
            lattice_->setVLine(i, n+2, NLINE);
        }

        for (int i = 0; i < m; i++) {
            std::getline(slkfile, buffer);
            importVLineRow(i+1, buffer);
        }
        slkfile.close();
    } else {
        std::cout << "Unable to open file\n";
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rsi, -0x2d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2250
movq -0x2d0(%rbp), %rsi
leaq -0x238(%rbp), %rdi
movl $0x8, %edx
callq 0x2290
jmp 0x4c78
leaq -0x238(%rbp), %rdi
callq 0x2280
movb %al, -0x2d9(%rbp)
jmp 0x4c8c
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x4c9b
jmp 0x50ff
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4cad
leaq -0x238(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x2100
jmp 0x4cc2
leaq -0x238(%rbp), %rdi
leaq -0x24c(%rbp), %rsi
callq 0x2100
jmp 0x4cd7
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x248(%rbp), %esi
addl $0x2, %esi
movl -0x24c(%rbp), %edx
addl $0x2, %edx
callq 0x5820
jmp 0x4cfa
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
callq 0x31e0
jmp 0x4d0b
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4d1d
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4d2f
movl $0x0, -0x250(%rbp)
movl -0x250(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x4e06
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4d5d
movl -0x250(%rbp), %eax
incl %eax
movl %eax, -0x2e0(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
jmp 0x4d7d
movl -0x2e0(%rbp), %esi
movq -0x2d8(%rbp), %rdi
leaq -0x270(%rbp), %rdx
callq 0x5360
jmp 0x4d98
leaq -0x270(%rbp), %rdi
callq 0x2110
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0x4d39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x5140
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x5134
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x2110
jmp 0x5134
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4e18
movl $0x0, -0x274(%rbp)
movl -0x274(%rbp), %eax
movl -0x248(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4ec9
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4e4b
movl -0x274(%rbp), %eax
incl %eax
movl %eax, -0x2e4(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
jmp 0x4e6b
movl -0x2e4(%rbp), %esi
movq -0x2d8(%rbp), %rdi
leaq -0x298(%rbp), %rdx
callq 0x54a0
jmp 0x4e86
leaq -0x298(%rbp), %rdi
callq 0x2110
movl -0x274(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274(%rbp)
jmp 0x4e22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x2110
jmp 0x5134
movl $0x0, -0x29c(%rbp)
movl -0x29c(%rbp), %eax
movl -0x24c(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x4f42
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x29c(%rbp), %edx
movq (%rdi), %rax
movq (%rax), %rax
xorl %esi, %esi
movl $0x2, %ecx
callq *%rax
jmp 0x4f07
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x248(%rbp), %esi
addl $0x2, %esi
movl -0x29c(%rbp), %edx
movq (%rdi), %rax
movq (%rax), %rax
movl $0x2, %ecx
callq *%rax
jmp 0x4f2f
jmp 0x4f31
movl -0x29c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x29c(%rbp)
jmp 0x4ed3
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x4f54
movl $0x0, -0x2a0(%rbp)
movl -0x2a0(%rbp), %eax
movl -0x24c(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jge 0x4fce
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x2a0(%rbp), %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
xorl %esi, %esi
movl $0x2, %ecx
callq *%rax
jmp 0x4f93
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x248(%rbp), %esi
incl %esi
movl -0x2a0(%rbp), %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
movl $0x2, %ecx
callq *%rax
jmp 0x4fbb
jmp 0x4fbd
movl -0x2a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a0(%rbp)
jmp 0x4f5e
movl $0x0, -0x2a4(%rbp)
movl -0x2a4(%rbp), %eax
movl -0x248(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x5049
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x2a4(%rbp), %esi
movq (%rdi), %rax
movq 0x8(%rax), %rax
xorl %edx, %edx
movl $0x2, %ecx
callq *%rax
jmp 0x500d
movq -0x2d8(%rbp), %rax
movq (%rax), %rdi
movl -0x2a4(%rbp), %esi
movl -0x24c(%rbp), %edx
addl $0x2, %edx
movq (%rdi), %rax
movq 0x8(%rax), %rax
movl $0x2, %ecx
callq *%rax
jmp 0x5036
jmp 0x5038
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0x4fd8
movl $0x0, -0x2a8(%rbp)
movl -0x2a8(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x50ef
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2040
jmp 0x5077
movl -0x2a8(%rbp), %eax
incl %eax
movl %eax, -0x2e8(%rbp)
leaq -0x2c8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20c0
jmp 0x5097
movl -0x2e8(%rbp), %esi
movq -0x2d8(%rbp), %rdi
leaq -0x2c8(%rbp), %rdx
callq 0x55d0
jmp 0x50b2
leaq -0x2c8(%rbp), %rdi
callq 0x2110
movl -0x2a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x5053
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x2110
jmp 0x5134
leaq -0x238(%rbp), %rdi
callq 0x2050
jmp 0x50fd
jmp 0x5116
movq 0x16ed2(%rip), %rdi     # 0x1bfd8
leaq 0x1009b(%rip), %rsi     # 0x151a8
callq 0x21c0
jmp 0x5114
jmp 0x5116
leaq -0x238(%rbp), %rdi
callq 0x2060
leaq -0x30(%rbp), %rdi
callq 0x2110
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x238(%rbp), %rdi
callq 0x2060
leaq -0x30(%rbp), %rdi
callq 0x2110
movq -0x240(%rbp), %rdi
callq 0x22c0
nopw %cs:(%rax,%rax)