// File: /workspace/github_cpp_makefile_star2_O2/davidjosepha[P]slitherlink/src/solver/solver.cpp
// Function: Solver::applyRule(int, int, Rule&, Orientation)
void Solver::applyRule(int i, int j, Rule & rule, Orientation orient) {
    int m = rule.getHeight();
    int n = rule.getWidth();

    std::vector<EdgePosition> const * hLineDiff = rule.getHLineDiff();
    for (int k = 0; k < hLineDiff->size(); k++) {
        EdgePosition pattern = (*hLineDiff)[k];
        Coordinates adjusted = rotateHLine(pattern.coords.i, pattern.coords.j, m, n, orient);

        switch (orient) {
            case UPFLIP:
            case UP:
            case DOWNFLIP:
            case DOWN:
                if (grid_->getHLine(adjusted.i + i, adjusted.j + j) == EMPTY) {
                    grid_->setValid(grid_->setHLine(adjusted.i + i, adjusted.j + j, pattern.edge));
                    grid_->setUpdated(true);
                }
                break;
            case LEFTFLIP:
            case LEFT:
            case RIGHTFLIP:
            case RIGHT:
                if (grid_->getVLine(adjusted.i + i, adjusted.j + j) == EMPTY) {
                    grid_->setValid(grid_->setVLine(adjusted.i + i, adjusted.j + j, pattern.edge));
                    grid_->setUpdated(true);
                }
                break;
        }
    }

    std::vector<EdgePosition> const * vLineDiff = rule.getVLineDiff();
    for (int k = 0; k < vLineDiff->size(); k++) {
        EdgePosition pattern = (*vLineDiff)[k];
        Coordinates adjusted = rotateVLine(pattern.coords.i, pattern.coords.j, m, n, orient);

        switch (orient) {
            case UPFLIP:
            case UP:
            case DOWNFLIP:
            case DOWN:
                if (grid_->getVLine(adjusted.i + i, adjusted.j + j) == EMPTY) {
                    grid_->setValid(grid_->setVLine(adjusted.i + i, adjusted.j + j, pattern.edge));
                    grid_->setUpdated(true);
                }
                break;
            case LEFTFLIP:
            case LEFT:
            case RIGHTFLIP:
            case RIGHT:
                if (grid_->getHLine(adjusted.i + i, adjusted.j + j) == EMPTY) {
                    grid_->setValid(grid_->setHLine(adjusted.i + i, adjusted.j + j, pattern.edge));
                    grid_->setUpdated(true);
                }
                break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebx
movq %rcx, %r13
movl %edx, -0x3c(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, -0x38(%rbp)
movl (%rcx), %eax
movl %eax, -0x44(%rbp)
movl 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
pushq $0x8
popq %r14
xorl %edi, %edi
movq %rcx, -0x60(%rbp)
movq 0x50(%r13), %rcx
movq 0x58(%r13), %rax
subq %rcx, %rax
cqto
pushq $0xc
popq %rsi
idivq %rsi
cmpq %rdi, %rax
jbe 0x7d55
movq %rdi, -0x58(%rbp)
movl -0x8(%rcx,%r14), %edi
movl -0x4(%rcx,%r14), %esi
movl (%rcx,%r14), %eax
movl %eax, -0x2c(%rbp)
movl -0x44(%rbp), %edx
movl -0x40(%rbp), %ecx
movl %ebx, %r8d
callq 0x50f8
cmpl $0x7, %ebx
ja 0x7d45
movq %rax, %r12
shrq $0x20, %r12
pushq $0x33
popq %rcx
btl %ebx, %ecx
jae 0x7ce9
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r15d
addl -0x3c(%rbp), %r12d
movl %r15d, %esi
movl %r12d, %edx
callq 0x3baa
testl %eax, %eax
jne 0x7d45
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *(%rax)
jmp 0x7d27
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r15d
addl -0x3c(%rbp), %r12d
movl %r15d, %esi
movl %r12d, %edx
callq 0x3bee
testl %eax, %eax
jne 0x7d45
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *0x8(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0x7d31
movl 0x48(%r13), %ecx
movb %cl, 0x48(%r13)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x9(%rax)
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %rdi
incq %rdi
addq $0xc, %r14
jmp 0x7c53
pushq $0x8
popq %r14
xorl %edi, %edi
movq 0x68(%r13), %rcx
movq 0x70(%r13), %rax
subq %rcx, %rax
cqto
pushq $0xc
popq %rsi
idivq %rsi
cmpq %rdi, %rax
jbe 0x7e5d
movq %rdi, -0x58(%rbp)
movl -0x8(%rcx,%r14), %edi
movl -0x4(%rcx,%r14), %esi
movl (%rcx,%r14), %eax
movl %eax, -0x2c(%rbp)
movl -0x44(%rbp), %edx
movl -0x40(%rbp), %ecx
movl %ebx, %r8d
callq 0x5104
cmpl $0x7, %ebx
ja 0x7e4d
movq %rax, %r12
shrq $0x20, %r12
pushq $0x33
popq %rcx
btl %ebx, %ecx
jae 0x7df2
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r15d
addl -0x3c(%rbp), %r12d
movl %r15d, %esi
movl %r12d, %edx
callq 0x3bee
testl %eax, %eax
jne 0x7e4d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *0x8(%rax)
jmp 0x7e2f
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r15d
addl -0x3c(%rbp), %r12d
movl %r15d, %esi
movl %r12d, %edx
callq 0x3baa
testl %eax, %eax
jne 0x7e4d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0x7e39
movl 0x48(%r13), %ecx
movb %cl, 0x48(%r13)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x9(%rax)
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %rdi
incq %rdi
addq $0xc, %r14
jmp 0x7d5b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq