// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movw $0x0, 0x70(%rsp)
movq $0xf, 0x78(%rsp)
movzbl 0xf8(%rsp), %eax
movzbl 0x100(%rsp), %edx
movq %rdx, 0x20(%rsp)
addl %edx, %eax
movl %ecx, 0x3c(%rsp)
cmpl %ecx, %eax
jle 0x8482
movl %eax, %eax
movq %rax, 0x10(%rdi)
movb $0x0, (%rdi)
movq %rdi, %rbx
jmp 0x8609
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
leaq 0xf0(%rsp), %rax
movq (%rax), %rbx
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x3146
testb %al, %al
je 0x84bc
movq 0x28(%rsp), %rbx
movb $0x1, (%rbx)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rbx)
jmp 0x8609
movq (%r14), %rdi
callq 0x4670
leaq 0x88(%rsp), %r12
leaq 0x70(%rsp), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x3660
movq (%r12), %r13
movq 0x8(%r12), %rax
movq %rax, 0x50(%rsp)
cmpq %rax, %r13
je 0x85e9
movq %rbx, 0x40(%rsp)
movq %r14, 0x48(%rsp)
movq 0x20(%rsp), %rax
incb %al
movq %rax, 0x20(%rsp)
movq $-0x1, 0x30(%rsp)
movq (%r13), %r12
cmpq %rbp, %r12
je 0x85cb
movq %rbp, %r14
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x38b6
movq 0x48(%rsp), %rbx
movzbl %al, %ebp
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x46b6
andq $-0x100, %r15
orq %rbp, %r15
movq %r12, 0x58(%rsp)
movq %r15, 0x60(%rsp)
movq 0x20(%rsp), %rax
movb %al, 0x68(%rsp)
movl $0xffffffff, 0x6c(%rsp) # imm = 0xFFFFFFFF
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
movq 0x40(%rsp), %rdx
movl 0x3c(%rsp), %ecx
callq 0x842e
movq 0xb0(%rsp), %rax
movq 0x28(%rsp), %rbx
movq %rax, 0x10(%rbx)
movups 0xa0(%rsp), %xmm0
movups %xmm0, (%rbx)
cmpb $0x0, (%rbx)
jne 0x861e
movq 0x10(%rbx), %rax
movq 0x30(%rsp), %rcx
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %r14, %rbp
addq $0x8, %r13
cmpq 0x50(%rsp), %r13
jne 0x8512
movq 0x88(%rsp), %r13
movq 0x30(%rsp), %r14
jmp 0x85f0
movq $-0x1, %r14
testq %r13, %r13
movq 0x28(%rsp), %rbx
je 0x8602
movq %r13, %rdi
callq 0x21f0
movq %r14, 0x10(%rbx)
movb $0x0, (%rbx)
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x8609
callq 0x21f0
jmp 0x8609
jmp 0x8634
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x8649
callq 0x21f0
movq %rbx, %rdi
callq 0x2320
nop