// File: /workspace/github_cpp_makefile_star2_O3/cpirc[P]Monochrome/src/search.cpp
// Function: quiesce(SearchController&, Position&, int, int, SearchStack*)
int quiesce(SearchController& sc, Position& pos, int alpha, int beta,
            SearchStack* ss) {
    assert(ss);

    if (ss->ply >= MAX_PLY) {
        return evaluate(pos);
    }

    // Check time left
    clock_t current_time = clock() * 1000 / CLOCKS_PER_SEC;
    if (current_time >= sc.search_end_time) {
        return 0;
    }

    int movecount, value;

    value = evaluate(pos);
    if (value >= beta) return beta;

    if (value > alpha) alpha = value;

    movecount = generate_captures(pos, ss->ml);

    ++ss->stats->node_count;

    score_moves(pos, ss, movecount, 0);

    Move move;
    while ((move = next_move(ss, movecount))) {
        Position npos = pos;

        make_move(npos, move);
        if (is_checked(npos, THEM)) {
            continue;
        }

        value = -quiesce(sc, npos, -beta, -alpha, ss + 1);

        if (value >= beta) {
            return beta;
        }
        if (value > alpha) {
            alpha = value;
        }
    }

    return alpha;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
testq %r8, %r8
je 0x7c12
movq %r8, %r15
movq %rsi, %r12
cmpb $0x40, (%r8)
jb 0x79af
movq %r12, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x395b
movl %ecx, %r13d
movl %edx, %ebx
movq %rdi, %r14
callq 0x3110
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
xorl %eax, %eax
cmpq 0x80(%r14), %rdx
jge 0x7bdc
movq %r12, %rdi
callq 0x395b
cmpl %r13d, %eax
jge 0x7bd7
movq %r14, -0x48(%rbp)
cmpl %ebx, %eax
cmovgl %eax, %ebx
leaq 0x4(%r15), %rsi
movq %r12, %rdi
callq 0x5d8d
leaq -0x34(%rbp), %r14
movl %eax, (%r14)
movq 0x810(%r15), %rcx
incq (%rcx)
movq %r12, %rdi
movq %r15, %rsi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x77a8
movq %r15, %rdi
movq %r14, %rsi
callq 0x78de
testl %eax, %eax
je 0x7bda
movl %eax, %r14d
leaq 0x50(%r12), %rax
movq %rax, -0x50(%rbp)
movl %r13d, -0x2c(%rbp)
negl %r13d
movl %r13d, -0x30(%rbp)
leaq 0x818(%r15), %rax
movq %rax, -0x40(%rbp)
leaq -0xb8(%rbp), %r13
movl $0xa, %ecx
movq %r13, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x5300
movq %r13, %rdi
movl %r14d, %esi
callq 0x47a0
movq -0x90(%rbp), %rax
movq -0x80(%rbp), %rdx
movq %rdx, %rcx
andq %rax, %rcx
je 0x7bf3
bsfq %rcx, %rdi
movq -0x88(%rbp), %rcx
orq %rcx, %rdx
leal (,%rdi,8), %esi
movq -0xb8(%rbp), %r8
leaq 0x96f8(%rip), %r9       # 0x111c0
andq 0x200(%r9,%rsi), %r8
movq -0xb0(%rbp), %r9
leaq 0x9ae2(%rip), %r10      # 0x115c0
andq (%r10,%rsi), %r9
orq %r8, %r9
leaq 0x49b4(%rip), %r8       # 0xc4a0
movq (%r8,%rsi), %r8
andq %rdx, %r8
leaq 0x47a6(%rip), %r10      # 0xc2a0
imulq (%r10,%rsi), %r8
shrq $0x37, %r8
movl %edi, %r10d
shll $0xc, %r10d
addq 0x949f(%rip), %r10      # 0x10fb0
movq (%r10,%r8,8), %r8
movq -0xa8(%rbp), %r10
andq %r8, %r10
orq %r9, %r10
leaq 0x4477(%rip), %r9       # 0xbfa0
andq (%r9,%rsi), %rdx
leaq 0x426c(%rip), %r9       # 0xbda0
imulq (%r9,%rsi), %rdx
shrq $0x34, %rdx
shll $0xf, %edi
addq 0x9451(%rip), %rdi      # 0x10f98
movq (%rdi,%rdx,8), %rdx
movq -0xa0(%rbp), %rdi
andq %rdx, %rdi
orq %r10, %rdi
orq %r8, %rdx
leaq 0x9c5e(%rip), %r8       # 0x117c0
andq (%r8,%rsi), %rax
andq -0x98(%rbp), %rdx
orq %rdi, %rax
orq %rdx, %rax
movl $0x2, %r14d
testq %rcx, %rax
jne 0x7baa
movl %ebx, %ecx
negl %ecx
movq -0x48(%rbp), %rdi
movq %r13, %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %r8
callq 0x796d
negl %eax
movl $0x1, %r14d
cmpl -0x2c(%rbp), %eax
jge 0x7baa
cmpl %eax, %ebx
cmovlel %eax, %ebx
xorl %r14d, %r14d
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x7bb8
callq 0x31a0
testb $0x1, %r14b
jne 0x7bee
movq %r15, %rdi
leaq -0x34(%rbp), %rsi
callq 0x78de
movl %eax, %r14d
testl %eax, %eax
jne 0x7a68
jmp 0x7bda
movl %r13d, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x2c(%rbp), %ebx
jmp 0x7bda
leaq 0x4056(%rip), %rdi      # 0xbc50
leaq 0x4052(%rip), %rsi      # 0xbc53
leaq 0x405a(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100
leaq 0x52a7(%rip), %rdi      # 0xcec0
leaq 0x52a3(%rip), %rsi      # 0xcec3
leaq 0x530d(%rip), %rcx      # 0xcf34
movl $0x6a, %edx
callq 0x3100
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x7c42
callq 0x31a0
movq %rbx, %rdi
callq 0x32d0