// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
movl %edx, -0x2c(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdi, -0x40(%rbp)
movl (%rcx), %eax
movl %eax, -0x50(%rbp)
movl 0x4(%rcx), %eax
movl %eax, -0x4c(%rbp)
movq 0x50(%rcx), %rax
movq %rcx, -0x60(%rbp)
cmpq %rax, 0x58(%rcx)
movl %r8d, -0x44(%rbp)
je 0xc8a8
movq -0x40(%rbp), %rcx
addq $0x8, %rcx
movq %rcx, -0x38(%rbp)
movl $0x8, %r12d
xorl %ebx, %ebx
movl -0x8(%rax,%r12), %edi
movl -0x4(%rax,%r12), %esi
movl (%rax,%r12), %eax
movl %eax, -0x48(%rbp)
movl -0x50(%rbp), %edx
movl -0x4c(%rbp), %ecx
movl %r15d, %r8d
callq 0x6244
cmpl $0x7, %r15d
ja 0xc877
movq %rax, %r13
shrq $0x20, %r13
movl $0x33, %ecx
btl %r15d, %ecx
jae 0xc81f
movq -0x38(%rbp), %rcx
movq (%rcx), %rdi
movq -0x58(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x2c(%rbp), %r13d
movl %r14d, %esi
movl %r13d, %edx
callq 0x431a
testl %eax, %eax
jne 0xc877
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movl -0x48(%rbp), %ecx
callq *(%rax)
jmp 0xc85a
movq -0x38(%rbp), %rcx
movq (%rcx), %rdi
movq -0x58(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x2c(%rbp), %r13d
movl %r14d, %esi
movl %r13d, %edx
callq 0x4360
testl %eax, %eax
jne 0xc877
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movl -0x48(%rbp), %ecx
callq *0x8(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0xc864
movl 0x48(%r15), %ecx
movb %cl, 0x48(%r15)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x44(%rbp), %r15d
incq %rbx
movq -0x60(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r12
cmpq %rbx, %rcx
ja 0xc7a8
movq -0x60(%rbp), %rcx
movq 0x68(%rcx), %rax
cmpq %rax, 0x70(%rcx)
je 0xc9c7
addq $0x8, -0x40(%rbp)
movl $0x8, %r12d
xorl %ebx, %ebx
movl -0x8(%rax,%r12), %edi
movl -0x4(%rax,%r12), %esi
movl (%rax,%r12), %eax
movl %eax, -0x38(%rbp)
movl -0x50(%rbp), %edx
movl -0x4c(%rbp), %ecx
movl %r15d, %r8d
callq 0x6250
cmpl $0x7, %r15d
ja 0xc996
movq %rax, %r13
shrq $0x20, %r13
movl $0x33, %ecx
btl %r15d, %ecx
jae 0xc93f
movq -0x40(%rbp), %rcx
movq (%rcx), %rdi
movq -0x58(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x2c(%rbp), %r13d
movl %r14d, %esi
movl %r13d, %edx
callq 0x4360
testl %eax, %eax
jne 0xc996
movq -0x40(%rbp), %rax
movq (%rax), %r15
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movl -0x38(%rbp), %ecx
callq *0x8(%rax)
jmp 0xc979
movq -0x40(%rbp), %rcx
movq (%rcx), %rdi
movq -0x58(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x2c(%rbp), %r13d
movl %r14d, %esi
movl %r13d, %edx
callq 0x431a
testl %eax, %eax
jne 0xc996
movq -0x40(%rbp), %rax
movq (%rax), %r15
movq (%r15), %rax
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movl -0x38(%rbp), %ecx
callq *(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0xc983
movl 0x48(%r15), %ecx
movb %cl, 0x48(%r15)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x44(%rbp), %r15d
incq %rbx
movq -0x60(%rbp), %rcx
movq 0x68(%rcx), %rax
movq 0x70(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r12
cmpq %rbx, %rcx
ja 0xc8c7
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq