// File: /workspace/github_cpp_makefile_star2_O2/camargodev[P]n-tile-puzzle/src/algorithms/IDAStar.cpp
// Function: IDAStar::recursiveSearch(Node, unsigned long, int)
IDAStar::Solution IDAStar :: recursiveSearch(Node currentNode, PackedState parent, int fLimit){
    IDAStar::Solution solution;
    StateManager stateManager;
    int val = f(currentNode);

    if(val > fLimit){
        solution.limit = val;
        solution.isSolution = false;
        return solution;
    }

    if(stateManager.isGoalState(currentNode.state.value)){
        solution.isSolution = true;
        solution.cost = currentNode.cost;
        return solution;
    }

    unsigned long long int nextLimit = ULLONG_MAX;

    this->result->increaseExpandedNodes();

    for (auto successorState : stateManager.produceNextPackedStates(currentNode.state.value)) {
        if(successorState != parent){
            State sucState;
            sucState.heuristic = stateManager.calculateHeuristic(successorState);
            this->result->increaseTotalHeuristicValue(sucState.heuristic);
            if(sucState.heuristic < ULLONG_MAX){
                sucState.value = successorState;
                Node sucNode = IDAStar::buildNode(sucState, currentNode.cost+1);
                solution = recursiveSearch(sucNode, currentNode.state.value, fLimit);
                if(solution.isSolution == true){
                    return solution;
                }
                nextLimit = min(nextLimit, solution.limit);
            }
        }            
    }

    solution.limit = nextLimit;
    solution.isSolution = false;
    return solution;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r14
movq %rdi, %r12
andw $0x0, 0x70(%rsp)
movq $0xf, 0x78(%rsp)
movzbl 0xf8(%rsp), %eax
movzbl 0x100(%rsp), %edx
movq %rdx, 0x20(%rsp)
addl %edx, %eax
movl %ecx, 0x34(%rsp)
cmpl %ecx, %eax
jle 0x75dd
movl %eax, %eax
movq %rax, 0x10(%r12)
jmp 0x774b
movq %rsi, %r15
movq %r12, 0x28(%rsp)
leaq 0xf0(%rsp), %rax
movq (%rax), %r12
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x2dec
testb %al, %al
je 0x761a
movq 0x28(%rsp), %r12
movb $0x1, (%r12)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%r12)
jmp 0x7750
movq %r15, 0x48(%rsp)
movq (%r15), %rdi
callq 0x42ec
movq %r14, 0x38(%rsp)
movq %r12, 0x40(%rsp)
leaq 0x88(%rsp), %r12
leaq 0x70(%rsp), %rsi
movq %r12, %rdi
movq 0x40(%rsp), %rdx
callq 0x329a
movq (%r12), %r14
movq 0x8(%r12), %rax
movq %rax, 0x50(%rsp)
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
incb %cl
movq %rcx, 0x20(%rsp)
pushq $-0x1
popq %rbx
movq 0x28(%rsp), %r12
movq 0x48(%rsp), %rbp
cmpq 0x50(%rsp), %r14
je 0x7739
movq (%r14), %r13
cmpq %rax, %r13
je 0x7730
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x34a2
movzbl %al, %r12d
movq (%rbp), %rdi
movl %r12d, %esi
callq 0x4332
andq $-0x100, %r15
orq %r12, %r15
movq %r13, 0x58(%rsp)
movq %r15, 0x60(%rsp)
movq 0x20(%rsp), %rax
movb %al, 0x68(%rsp)
orl $-0x1, 0x6c(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %rdx
movl 0x34(%rsp), %ecx
callq 0x758c
movq 0xb0(%rsp), %rax
movq 0x28(%rsp), %r12
movq %rax, 0x10(%r12)
movups 0xa0(%rsp), %xmm0
movups %xmm0, (%r12)
cmpb $0x0, (%r12)
jne 0x7765
movq 0x10(%r12), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
movq 0x38(%rsp), %rax
addq $0x8, %r14
jmp 0x7677
leaq 0x88(%rsp), %rdi
callq 0x3d6e
movq %rbx, 0x10(%r12)
movb $0x0, (%r12)
movq %r12, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x88(%rsp), %rdi
callq 0x3d6e
jmp 0x7750
jmp 0x7776
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3d6e
movq %rbx, %rdi
callq 0x2340