// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rdi, %rbx
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x2b8(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2220
leaq -0x240(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x3446
leaq -0x2b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2040
leaq -0x2b8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2110
leaq -0x2b8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2110
movq (%rbx), %rdi
movl -0x2c(%rbp), %esi
addl $0x2, %esi
movl -0x30(%rbp), %edx
addl $0x2, %edx
callq 0x39d4
movq (%rbx), %rdi
callq 0x2a58
leaq -0x2b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2040
leaq -0x2b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2040
pushq $0x1
popq %r14
leaq -0x2b8(%rbp), %r15
leaq -0x50(%rbp), %r12
leaq -0xb0(%rbp), %r13
leal -0x1(%r14), %eax
cmpl -0x2c(%rbp), %eax
jge 0x345e
movq %r15, %rdi
movq %r12, %rsi
callq 0x2040
movq %r13, %rdi
movq %r12, %rsi
callq 0x21f0
movq %rbx, %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x37ee
movq %r13, %rdi
callq 0x20c0
incl %r14d
jmp 0x340c
movq 0xbb8b(%rip), %rdi      # 0xefd8
leaq 0x6d32(%rip), %rsi      # 0xa186
callq 0x21a0
jmp 0x35d9
leaq -0x2b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2040
xorl %r14d, %r14d
leaq -0x2b8(%rbp), %r15
leaq -0x50(%rbp), %r12
leaq -0x90(%rbp), %r13
cmpl -0x2c(%rbp), %r14d
jg 0x34ba
movq %r15, %rdi
movq %r12, %rsi
callq 0x2040
movq %r13, %rdi
movq %r12, %rsi
callq 0x21f0
incl %r14d
movq %rbx, %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x3848
movq %r13, %rdi
callq 0x20c0
jmp 0x3483
xorl %r14d, %r14d
pushq $0x2
popq %r15
movl -0x30(%rbp), %eax
addl $0x2, %eax
cmpl %eax, %r14d
jge 0x34f5
movq (%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl %r14d, %edx
movl %r15d, %ecx
callq *(%rax)
movq (%rbx), %rdi
movl -0x2c(%rbp), %esi
addl $0x2, %esi
movq (%rdi), %rax
movl %r14d, %edx
movl %r15d, %ecx
callq *(%rax)
incl %r14d
jmp 0x34c1
leaq -0x2b8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2040
xorl %r14d, %r14d
pushq $0x2
popq %r15
movl -0x30(%rbp), %eax
addl $0x3, %eax
cmpl %eax, %r14d
jge 0x3541
movq (%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl %r14d, %edx
movl %r15d, %ecx
callq *0x8(%rax)
movq (%rbx), %rdi
movl -0x2c(%rbp), %esi
incl %esi
movq (%rdi), %rax
movl %r14d, %edx
movl %r15d, %ecx
callq *0x8(%rax)
incl %r14d
jmp 0x350c
xorl %r14d, %r14d
pushq $0x2
popq %r15
movl -0x2c(%rbp), %eax
leal 0x2(%rax), %ecx
cmpl %ecx, %r14d
jge 0x357e
movq (%rbx), %rdi
movq (%rdi), %rax
movl %r14d, %esi
xorl %edx, %edx
movl %r15d, %ecx
callq *0x8(%rax)
movq (%rbx), %rdi
movl -0x30(%rbp), %edx
addl $0x2, %edx
movq (%rdi), %rax
movl %r14d, %esi
movl %r15d, %ecx
callq *0x8(%rax)
incl %r14d
jmp 0x3548
pushq $0x1
popq %r14
leaq -0x2b8(%rbp), %r15
leaq -0x50(%rbp), %r12
leaq -0x70(%rbp), %r13
leal -0x1(%r14), %ecx
cmpl %eax, %ecx
jge 0x35cd
movq %r15, %rdi
movq %r12, %rsi
callq 0x2040
movq %r13, %rdi
movq %r12, %rsi
callq 0x21f0
movq %rbx, %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x38c4
movq %r13, %rdi
callq 0x20c0
movl -0x2c(%rbp), %eax
incl %r14d
jmp 0x3591
leaq -0x2b8(%rbp), %rdi
callq 0x2050
leaq -0x2b8(%rbp), %rdi
callq 0x2070
leaq -0x50(%rbp), %rdi
callq 0x20c0
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3639
movq %rax, %rbx
jmp 0x3648
jmp 0x3639
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x3628
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x3628
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x20c0
jmp 0x363c
jmp 0x3639
jmp 0x3639
jmp 0x3639
jmp 0x3639
jmp 0x3639
movq %rax, %rbx
leaq -0x2b8(%rbp), %rdi
callq 0x2070
leaq -0x50(%rbp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2250
nop