// File: /workspace/github_cpp_makefile_star2_O1/SethKasmann[P]clever-girl/src/search.cpp
// Function: iterative_deepening(State&, SearchInfo&)
void iterative_deepening(State& s, SearchInfo& si)
{
    int score;
    // Iterative deepening.
    for (int d = 1; !si.quit; ++d)
    {
        if (d == si.depth)
            break;

        score = scout_search(s, si, d, 0, Neg_inf, Pos_inf, true, false, true);

        if (lineManager.getPvMove() == nullMove)
        {
            std::cout << "bestmove 0000" << std::endl;
            return;
        }

        if (si.quit)
            break;

        // Confirm all the pv moves are legal.
        lineManager.checkPv(s);

        // Print info to gui.
        std::cout << "info "
                  << "depth " << d;

        if (lineManager.isMate())
        {
            int n = lineManager.getMateInN();
            std::cout << " score mate " << (score > 0 ? n : -n);
        }
        else
        {
            std::cout << " score cp " << score;
        }

        std::cout << " time " 
                  << si.clock.elapsed<std::chrono::milliseconds>()
                  << " nodes " 
                  << si.nodes
                  << " nps " 
                  << si.nodes / (si.clock.elapsed<std::chrono::milliseconds>() + 1) * 1000;
        lineManager.printPv();
        std::cout << std::endl;

        // This check handles the case where the search tree was the same
        // exact size as the previous depth (can occur for a forced draw
        // or mating sequence).
        if (si.nodes == si.prevNodes)
            break;

        // Break if there's not enough time for the next search.
        if (si.clock.elapsed<std::chrono::milliseconds>() * 2 > si.moveTime)
            break;

        // Reset node count.
        si.prevNodes = si.nodes;
        si.nodes = 0;
    }

    std::cout << "bestmove " << toString(lineManager.getPvMove()) << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x8(%rsp)
cmpb $0x0, 0x3a(%rsi)
jne 0x1620f
movq %rsi, %r14
cmpl $0x1, 0x14(%rsi)
je 0x1620f
movl $0x2, %r15d
leaq 0x13f715(%rip), %r12    # 0x1556e0
movq 0xefce(%rip), %rbx      # 0x24fa0
leal -0x1(%r15), %r13d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
movl $0xffff3cb0, %r8d       # imm = 0xFFFF3CB0
movl $0xc350, %r9d           # imm = 0xC350
movl $0x1, %eax
pushq %rax
pushq $0x0
pushq %rax
callq 0x15537
addq $0x20, %rsp
movl %eax, %ebp
movq %r12, %rdi
xorl %esi, %esi
callq 0xf96a
testw %ax, %ax
je 0x162ab
cmpb $0x0, 0x3a(%r14)
jne 0x1620f
movq %r15, 0x10(%rsp)
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0xf9e2
movl $0x5, %edx
movq %rbx, %rdi
leaq 0x8312(%rip), %rsi      # 0x1e358
callq 0x4290
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x8304(%rip), %rsi      # 0x1e35e
callq 0x4290
movq %rbx, %rdi
movl %r13d, %esi
callq 0x43a0
movq %r12, %rdi
callq 0xf976
testb %al, %al
je 0x160a2
movq %r12, %rdi
callq 0xf97e
movl %eax, %r13d
movl $0xc, %edx
movq %rbx, %rdi
leaq 0x82d5(%rip), %rsi      # 0x1e365
callq 0x4290
movl %r13d, %esi
negl %esi
testl %ebp, %ebp
cmovgl %r13d, %esi
jmp 0x160b8
movl $0xa, %edx
movq %rbx, %rdi
leaq 0x82c1(%rip), %rsi      # 0x1e372
callq 0x4290
movl %ebp, %esi
movq %r12, %r15
movq %rbx, %rdi
callq 0x43a0
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x82ab(%rip), %rsi      # 0x1e37d
callq 0x4290
callq 0x4060
subq 0x30(%r14), %rax
movabsq $0x431bde82d7b634db, %r12 # imm = 0x431BDE82D7B634DB
imulq %r12
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x12, %rdx
addq %rdx, %rsi
movq %rbx, %rdi
callq 0x4200
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x826f(%rip), %rsi      # 0x1e384
callq 0x4290
movl 0x1c(%r14), %esi
movq %r13, %rdi
callq 0x43a0
movq %rax, %r13
movl $0x5, %edx
movq %rax, %rdi
leaq 0x8254(%rip), %rsi      # 0x1e38c
callq 0x4290
movslq 0x1c(%r14), %rbp
callq 0x4060
subq 0x30(%r14), %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rdx
leaq (%rdx,%rax), %rcx
incq %rcx
movq %rbp, %rax
cqto
idivq %rcx
imulq $0x3e8, %rax, %rsi      # imm = 0x3E8
movq %r13, %rdi
callq 0x4200
movq %r15, %rdi
callq 0xfad0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4170
movl 0x1c(%r14), %eax
cmpl 0x20(%r14), %eax
movq %r15, %r12
movq 0x10(%rsp), %r15
je 0x1620f
callq 0x4060
subq 0x30(%r14), %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rdx
addq %rax, %rdx
addq %rdx, %rdx
cmpq 0x28(%r14), %rdx
jg 0x1620f
movl 0x14(%r14), %eax
movl 0x1c(%r14), %ecx
movl %ecx, 0x20(%r14)
movl $0x0, 0x1c(%r14)
cmpb $0x0, 0x3a(%r14)
jne 0x1620f
leal 0x1(%r15), %ecx
cmpl %eax, %r15d
movl %ecx, %r15d
jne 0x15fd2
movq 0xed8a(%rip), %rbx      # 0x24fa0
leaq 0x8175(%rip), %rsi      # 0x1e392
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4290
leaq 0x13f4af(%rip), %rdi    # 0x1556e0
xorl %esi, %esi
callq 0xf96a
movzwl %ax, %esi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0xfbab
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x4290
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4170
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1629c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4250
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8098(%rip), %rsi      # 0x1e34a
movl $0xd, %edx
movq %rbx, %rdi
callq 0x4290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4170
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16312
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4250
movq %rbx, %rdi
callq 0x43b0