// File: /workspace/github_cpp_makefile_star2_O3/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, %r13d
movl %edx, -0x3c(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, -0x38(%rbp)
movl (%rcx), %eax
movl %eax, -0x48(%rbp)
movl 0x4(%rcx), %eax
movl %eax, -0x44(%rbp)
movq 0x50(%rcx), %rax
movq %rcx, -0x58(%rbp)
cmpq %rax, 0x58(%rcx)
movl %r8d, -0x40(%rbp)
je 0xc8e3
movl $0x8, %r15d
xorl %ebx, %ebx
movl -0x8(%rax,%r15), %edi
movl -0x4(%rax,%r15), %esi
movl (%rax,%r15), %eax
movl %eax, -0x2c(%rbp)
movl -0x48(%rbp), %edx
movl -0x44(%rbp), %ecx
movl %r13d, %r8d
callq 0x6260
cmpl $0x7, %r13d
ja 0xc8b2
movq %rax, %r12
shrq $0x20, %r12
movl $0x33, %ecx
btl %r13d, %ecx
jae 0xc856
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x3c(%rbp), %r12d
movl %r14d, %esi
movl %r12d, %edx
callq 0x4322
testl %eax, %eax
jne 0xc8b2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *(%rax)
jmp 0xc894
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x3c(%rbp), %r12d
movl %r14d, %esi
movl %r12d, %edx
callq 0x4368
testl %eax, %eax
jne 0xc8b2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *0x8(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0xc89e
movl 0x48(%r13), %ecx
movb %cl, 0x48(%r13)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x40(%rbp), %r13d
incq %rbx
movq -0x58(%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, %r15
cmpq %rbx, %rcx
ja 0xc7dc
movq -0x58(%rbp), %rcx
movq 0x68(%rcx), %rax
cmpq %rax, 0x70(%rcx)
je 0xca04
movl $0x8, %r15d
xorl %ebx, %ebx
movl -0x8(%rax,%r15), %edi
movl -0x4(%rax,%r15), %esi
movl (%rax,%r15), %eax
movl %eax, -0x2c(%rbp)
movl -0x48(%rbp), %edx
movl -0x44(%rbp), %ecx
movl %r13d, %r8d
callq 0x626c
cmpl $0x7, %r13d
ja 0xc9d3
movq %rax, %r12
shrq $0x20, %r12
movl $0x33, %ecx
btl %r13d, %ecx
jae 0xc978
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x3c(%rbp), %r12d
movl %r14d, %esi
movl %r12d, %edx
callq 0x4368
testl %eax, %eax
jne 0xc9d3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *0x8(%rax)
jmp 0xc9b5
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x50(%rbp), %rcx
leal (%rax,%rcx), %r14d
addl -0x3c(%rbp), %r12d
movl %r14d, %esi
movl %r12d, %edx
callq 0x4322
testl %eax, %eax
jne 0xc9d3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %r13
movq (%r13), %rax
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
callq *(%rax)
xorl %ecx, %ecx
testb %al, %al
je 0xc9bf
movl 0x48(%r13), %ecx
movb %cl, 0x48(%r13)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x1, 0x9(%rax)
movl -0x40(%rbp), %r13d
incq %rbx
movq -0x58(%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, %r15
cmpq %rbx, %rcx
ja 0xc8fd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop