// File: davidjosepha[P]slitherlink/src/solver/main.cpp
// Function: main
int main(int argc, char * argv[]) {
    clock_t startTime, endTime;
    startTime = clock();

    Rule rules[NUM_RULES];
    initRules(rules);
    Contradiction contradictions[NUM_CONTRADICTIONS];
    initContradictions(contradictions);
    int selectedRules[NUM_RULES - NUM_CONST_RULES];
    for (int i = 0; i < NUM_RULES - NUM_CONST_RULES; i++) {
        selectedRules[i] = i;
    }

    for (int i = 1; i < argc; i++) {
        char * filename = argv[i];
        std::cout << "Puzzle: " << filename << std::endl;

        Grid grid;
        Import importer = Import(grid, filename);
        Export exporter = Export(grid);

        Solver solver = Solver(grid, rules, contradictions, selectedRules, NUM_RULES - NUM_CONST_RULES, 100);

        exporter.print();

        if (grid.isSolved()) {
            std::cout << "Solved" << std::endl;
        } else {
            if (solver.testContradictions()) {
                std::cout << "Invalid puzzle" << std::endl;
            } else if (solver.hasMultipleSolutions()) {
                std::cout << "Puzzle has multiple solutions" << std::endl;
            } else {
                std::cout << "Not solved" << std::endl;
            }
        }
    }

    endTime = clock();
    float diff = ((float)endTime - (float)startTime) / CLOCKS_PER_SEC;
    std::cout << "Total time:\t" << diff << " seconds" << std::endl;

    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x16f0, %rsp           # imm = 0x16F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x2100
movq %rax, -0x18(%rbp)
leaq -0x10a0(%rbp), %rax
movq %rax, -0x15d0(%rbp)
movq %rax, %rcx
addq $0x1080, %rcx           # imm = 0x1080
movq %rcx, -0x15c8(%rbp)
movq %rax, -0x15c0(%rbp)
movq -0x15c0(%rbp), %rdi
movq %rdi, -0x15d8(%rbp)
callq 0x10c30
jmp 0x1052d
movq -0x15c8(%rbp), %rcx
movq -0x15d8(%rbp), %rax
addq $0x80, %rax
cmpq %rcx, %rax
movq %rax, -0x15c0(%rbp)
jne 0x10518
leaq -0x10a0(%rbp), %rdi
callq 0xab50
jmp 0x1055b
leaq -0x1420(%rbp), %rax
movq %rax, -0x15f0(%rbp)
movq %rax, %rcx
addq $0x370, %rcx            # imm = 0x370
movq %rcx, -0x15e8(%rbp)
movq %rax, -0x15e0(%rbp)
movq -0x15e0(%rbp), %rdi
movq %rdi, -0x15f8(%rbp)
callq 0x10c90
jmp 0x10596
movq -0x15e8(%rbp), %rcx
movq -0x15f8(%rbp), %rax
addq $0x50, %rax
cmpq %rcx, %rax
movq %rax, -0x15e0(%rbp)
jne 0x10581
leaq -0x1420(%rbp), %rdi
callq 0x61a0
jmp 0x105c2
movl $0x0, -0x14a4(%rbp)
cmpl $0x1e, -0x14a4(%rbp)
jge 0x106ec
movl -0x14a4(%rbp), %ecx
movslq -0x14a4(%rbp), %rax
movl %ecx, -0x14a0(%rbp,%rax,4)
movl -0x14a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14a4(%rbp)
jmp 0x105cc
movq -0x15d0(%rbp), %rcx
movq %rax, %rsi
movq -0x15d8(%rbp), %rax
movq %rsi, -0x10a8(%rbp)
movl %edx, -0x10ac(%rbp)
cmpq %rax, %rcx
movq %rax, -0x1600(%rbp)
je 0x10659
movq -0x1600(%rbp), %rdi
addq $-0x80, %rdi
movq %rdi, -0x1608(%rbp)
callq 0xc960
movq -0x15d0(%rbp), %rcx
movq -0x1608(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1600(%rbp)
jne 0x10628
jmp 0x10c16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
jmp 0x10bc8
movq -0x15f0(%rbp), %rcx
movq %rax, %rsi
movq -0x15f8(%rbp), %rax
movq %rsi, -0x10a8(%rbp)
movl %edx, -0x10ac(%rbp)
cmpq %rax, %rcx
movq %rax, -0x1610(%rbp)
je 0x106d0
movq -0x1610(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x1618(%rbp)
callq 0x6970
movq -0x15f0(%rbp), %rcx
movq -0x1618(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1610(%rbp)
jne 0x1069f
jmp 0x10bc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
jmp 0x10b3d
movl $0x1, -0x14a8(%rbp)
movl -0x14a8(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x10a36
movq -0x10(%rbp), %rax
movslq -0x14a8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x14b0(%rbp)
movq 0x68b6(%rip), %rdi      # 0x16fd8
leaq 0xedb(%rip), %rsi       # 0x11604
callq 0x2170
movq %rax, -0x1620(%rbp)
jmp 0x10737
movq -0x1620(%rbp), %rdi
movq -0x14b0(%rbp), %rsi
callq 0x2170
movq %rax, -0x1628(%rbp)
jmp 0x10753
movq -0x1628(%rbp), %rdi
movq 0x6867(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x10768
leaq -0x1508(%rbp), %rdi
callq 0xfbb0
jmp 0x10776
movq -0x14b0(%rbp), %rax
movq %rax, -0x1638(%rbp)
leaq -0x1539(%rbp), %rdi
movq %rdi, -0x1630(%rbp)
callq 0x2240
movq -0x1638(%rbp), %rsi
movq -0x1630(%rbp), %rdx
leaq -0x1538(%rbp), %rdi
callq 0x21d0
jmp 0x107b3
leaq -0x1518(%rbp), %rdi
leaq -0x1508(%rbp), %rsi
leaq -0x1538(%rbp), %rdx
callq 0x4ad0
jmp 0x107cf
leaq -0x1538(%rbp), %rdi
callq 0x20e0
leaq -0x1539(%rbp), %rdi
callq 0x21a0
leaq -0x1548(%rbp), %rdi
leaq -0x1508(%rbp), %rsi
callq 0x2670
jmp 0x107fc
movq %rsp, %rax
movl $0x64, (%rax)
leaq -0x15b0(%rbp), %rdi
leaq -0x1508(%rbp), %rsi
leaq -0x10a0(%rbp), %rdx
leaq -0x1420(%rbp), %rcx
leaq -0x14a0(%rbp), %r8
movl $0x1e, %r9d
callq 0xcb00
jmp 0x10835
leaq -0x1548(%rbp), %rdi
callq 0x2690
jmp 0x10843
leaq -0x1508(%rbp), %rdi
callq 0x4750
movb %al, -0x1639(%rbp)
jmp 0x10857
movb -0x1639(%rbp), %al
testb $0x1, %al
jne 0x10866
jmp 0x10919
movq 0x676b(%rip), %rdi      # 0x16fd8
leaq 0xd99(%rip), %rsi       # 0x1160d
callq 0x2170
movq %rax, -0x1648(%rbp)
jmp 0x10882
movq -0x1648(%rbp), %rdi
movq 0x6738(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x10897
jmp 0x109f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
jmp 0x108ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x1538(%rbp), %rdi
callq 0x20e0
leaq -0x1539(%rbp), %rdi
callq 0x21a0
jmp 0x10a25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
jmp 0x10a25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x15b0(%rbp), %rdi
callq 0xfc10
jmp 0x10a25
leaq -0x15b0(%rbp), %rdi
callq 0xd090
movb %al, -0x1649(%rbp)
jmp 0x1092d
movb -0x1649(%rbp), %al
testb $0x1, %al
jne 0x10939
jmp 0x1096f
movq 0x6698(%rip), %rdi      # 0x16fd8
leaq 0xccd(%rip), %rsi       # 0x11614
callq 0x2170
movq %rax, -0x1658(%rbp)
jmp 0x10955
movq -0x1658(%rbp), %rdi
movq 0x6665(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x1096a
jmp 0x109f7
leaq -0x15b0(%rbp), %rdi
callq 0xfbf0
movb %al, -0x1659(%rbp)
jmp 0x10983
movb -0x1659(%rbp), %al
testb $0x1, %al
jne 0x1098f
jmp 0x109c2
movq 0x6642(%rip), %rdi      # 0x16fd8
leaq 0xc86(%rip), %rsi       # 0x11623
callq 0x2170
movq %rax, -0x1668(%rbp)
jmp 0x109ab
movq -0x1668(%rbp), %rdi
movq 0x660f(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x109c0
jmp 0x109f5
movq 0x660f(%rip), %rdi      # 0x16fd8
leaq 0xc71(%rip), %rsi       # 0x11641
callq 0x2170
movq %rax, -0x1670(%rbp)
jmp 0x109de
movq -0x1670(%rbp), %rdi
movq 0x65dc(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x109f3
jmp 0x109f5
jmp 0x109f7
jmp 0x109f9
leaq -0x15b0(%rbp), %rdi
callq 0xfc10
leaq -0x1508(%rbp), %rdi
callq 0x2a30
movl -0x14a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14a8(%rbp)
jmp 0x106f6
leaq -0x1508(%rbp), %rdi
callq 0x2a30
jmp 0x10b3d
callq 0x2100
movq %rax, -0x20(%rbp)
cvtsi2ssq -0x20(%rbp), %xmm0
cvtsi2ssq -0x18(%rbp), %xmm1
subss %xmm1, %xmm0
movss 0xba9(%rip), %xmm1      # 0x11600
divss %xmm1, %xmm0
movss %xmm0, -0x15b4(%rbp)
movq 0x656e(%rip), %rdi      # 0x16fd8
leaq 0xbdb(%rip), %rsi       # 0x1164c
callq 0x2170
movq %rax, -0x1678(%rbp)
jmp 0x10a7f
movq -0x1678(%rbp), %rdi
movss -0x15b4(%rbp), %xmm0
callq 0x2120
movq %rax, -0x1680(%rbp)
jmp 0x10a9c
movq -0x1680(%rbp), %rdi
leaq 0xbaf(%rip), %rsi       # 0x11659
callq 0x2170
movq %rax, -0x1688(%rbp)
jmp 0x10ab8
movq -0x1688(%rbp), %rdi
movq 0x6502(%rip), %rsi      # 0x16fc8
callq 0x2190
jmp 0x10acd
movl $0x0, -0x4(%rbp)
leaq -0x1420(%rbp), %rax
movq %rax, -0x1698(%rbp)
addq $0x370, %rax            # imm = 0x370
movq %rax, -0x1690(%rbp)
movq -0x1690(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x16a0(%rbp)
callq 0x6970
movq -0x1698(%rbp), %rcx
movq -0x16a0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1690(%rbp)
jne 0x10aef
leaq -0x10a0(%rbp), %rax
movq %rax, -0x16b0(%rbp)
addq $0x1080, %rax           # imm = 0x1080
movq %rax, -0x16a8(%rbp)
jmp 0x10b8b
leaq -0x1420(%rbp), %rax
movq %rax, -0x16c0(%rbp)
addq $0x370, %rax            # imm = 0x370
movq %rax, -0x16b8(%rbp)
movq -0x16b8(%rbp), %rdi
addq $-0x50, %rdi
movq %rdi, -0x16c8(%rbp)
callq 0x6970
movq -0x16c0(%rbp), %rcx
movq -0x16c8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x16b8(%rbp)
jne 0x10b58
jmp 0x10bc8
movq -0x16a8(%rbp), %rdi
addq $-0x80, %rdi
movq %rdi, -0x16d0(%rbp)
callq 0xc960
movq -0x16b0(%rbp), %rcx
movq -0x16d0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x16a8(%rbp)
jne 0x10b8b
movl -0x4(%rbp), %eax
addq $0x16f0, %rsp           # imm = 0x16F0
popq %rbp
retq
leaq -0x10a0(%rbp), %rax
movq %rax, -0x16e0(%rbp)
addq $0x1080, %rax           # imm = 0x1080
movq %rax, -0x16d8(%rbp)
movq -0x16d8(%rbp), %rdi
addq $-0x80, %rdi
movq %rdi, -0x16e8(%rbp)
callq 0xc960
movq -0x16e0(%rbp), %rcx
movq -0x16e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x16d8(%rbp)
jne 0x10be3
jmp 0x10c16
movq -0x10a8(%rbp), %rdi
callq 0x2230
nopw %cs:(%rax,%rax)
nopl (%rax)