// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/src/match.cpp
// Function: recover_matching(tree const&, tree const&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&, unsigned long long, unsigned long long)
void recover_matching(const tree& t1, const tree& t2, vector<pair<int, int>>& matching, mask rx, mask ry)
{
    // trivial case: empty forest
    if (rx == 0 || ry == 0)
        return;

    // score, transition type, transition destination, bipartite matching
    // (branching) roots of trees in t1 and t2 respectively
    // roots of paths in va and vb respectively
    // bipartite matching transition table
    // branch choice table
    const auto& [sol, trs, dst, bdp, va, vb, ra, rb, btr, bst] = fdp[rx][ry];

    switch (trs)
    {
        case DEL_1:
            recover_matching(t1, t2, matching, em(rx ^ in(dst) ^ t1.ch[dst], t1.ba[dst]), ry);
            break;
        case DEL_2:
            recover_matching(t1, t2, matching, rx, em(ry ^ in(dst) ^ t2.ch[dst], t2.ba[dst]));
            break;
        case MATCH:
            for (int i = 0; i < bdp.size(); ++i)
            {
                // ith tree isn't matched with anyone
                if (bdp[i] == -1)
                    continue;

                // ith tree is matched with jth tree
                int j = bdp[i];
                // branching node index
                int u = va[i], v = vb[j];
                // path  x..z in t1
                int z = t1.b[u];
                int x = ra[i];
                // path y..w in t2
                int w = t2.b[v];
                int y = rb[j];
                // branch choice
                int s = bst(i, j);

                switch (btr(i, j))
                {
                    case DEL_1:
                        recover_matching(t1, t2, matching, in(u) | in(s) | (rx & t1.ba[u]), in(v) | (ry & t2.ba[v]));
                        break;
                    case DEL_2:
                        recover_matching(t1, t2, matching, in(u) | (rx & t1.ba[u]), in(v) | in(s) | (ry & t2.ba[v]));
                        break;
                    case MATCH:
                        const auto& [dp, tdp] = pdp[{x, y}];
                        recover_matching_aux(t1, t2, matching, tdp, x, y, z, w);
                        recover_matching(t1, t2, matching, t1.ch[u], t2.ch[v]);
                        break;
                }
            }
            break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, (%rsp)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x10(%rsp)
testq %rcx, %rcx
sete %al
testq %r8, %r8
sete %cl
orb %al, %cl
jne 0x4862
movq %rsi, %r13
leaq 0xbc39(%rip), %rdi      # 0x10248
leaq 0x18(%rsp), %rsi
callq 0x6d4a
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x716a
movq %rax, %r12
movl 0xbc(%rax), %eax
testl %eax, %eax
je 0x4825
cmpl $0x1, %eax
je 0x47f2
cmpl $0x2, %eax
jne 0x4862
xorl %ebx, %ebx
pushq $0x1
popq %rbp
movq %r13, 0x28(%rsp)
movq 0xa0(%r12), %rax
movq 0xa8(%r12), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x4862
movslq (%rax,%rbx,4), %rax
cmpq $-0x1, %rax
je 0x47ea
movq 0x88(%r12), %rcx
movslq (%rcx,%rbx,4), %r15
movq 0x70(%r12), %rcx
movslq (%rcx,%rax,4), %r14
movq 0x28(%r12), %rcx
movl 0x24(%r12), %edx
imull %ebx, %edx
addl %eax, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %edx
cmpl $0x2, %edx
je 0x474d
movl 0x4(%r12), %ecx
imull %ebx, %ecx
addl %eax, %ecx
movslq %ecx, %rax
movq 0x8(%r12), %rcx
movl (%rcx,%rax,4), %ecx
cmpl $0x1, %edx
je 0x470e
testl %edx, %edx
jne 0x47ea
movq %rbp, %rax
shlq %cl, %rax
btsq %r15, %rax
movq 0x8(%rsp), %rdi
movq 0x8058(%rdi,%r15,8), %rcx
andq 0x18(%rsp), %rcx
orq %rax, %rcx
movq %r13, %rsi
movq 0x8058(%r13,%r14,8), %r8
andq 0x10(%rsp), %r8
btsq %r14, %r8
jmp 0x47e1
movq 0x8(%rsp), %rdi
movq 0x8058(%rdi,%r15,8), %rax
andq 0x18(%rsp), %rax
btsq %r15, %rax
movq %rbp, %rdx
shlq %cl, %rdx
btsq %r14, %rdx
movq %r13, %rsi
movq 0x8058(%r13,%r14,8), %r8
andq 0x10(%rsp), %r8
orq %rdx, %r8
movq (%rsp), %rdx
movq %rax, %rcx
jmp 0x47e5
movq 0x40(%r12), %rcx
movq 0x58(%r12), %rdx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x24(%rsp)
movl 0x5e14(%r13,%r14,4), %eax
movq %rax, 0x38(%rsp)
movl (%rdx,%rbx,4), %ebp
movq 0x8(%rsp), %r13
movl 0x5e14(%r13,%r15,4), %eax
movq %rax, 0x40(%rsp)
movl %ecx, 0x30(%rsp)
movl %ebp, 0x34(%rsp)
leaq 0xbaf1(%rip), %rdi      # 0x10280
leaq 0x30(%rsp), %rsi
callq 0x532e
leaq 0x20(%rax), %rcx
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq (%rsp), %rdx
movl %ebp, %r8d
movq 0x28(%rsp), %rbp
movl 0x24(%rsp), %r9d
pushq 0x38(%rsp)
pushq 0x48(%rsp)
callq 0x44fe
popq %rax
popq %rcx
movq 0x6eb8(%r13,%r15,8), %rcx
movq 0x6eb8(%rbp,%r14,8), %r8
movq %r13, %rdi
movq %rbp, %r13
movq %rbp, %rsi
pushq $0x1
popq %rbp
movq (%rsp), %rdx
callq 0x45d0
incq %rbx
jmp 0x4653
movq 0x18(%rsp), %rcx
movslq 0xb8(%r12), %rax
movq 0x6eb8(%r13,%rax,8), %rdx
xorq 0x10(%rsp), %rdx
btcq %rax, %rdx
movq 0x8058(%r13,%rax,8), %r8
notq %r8
andq %rdx, %r8
movq 0x8(%rsp), %rdi
jmp 0x4856
movslq 0xb8(%r12), %rax
movq 0x8(%rsp), %rdi
movq 0x6eb8(%rdi,%rax,8), %rdx
xorq 0x18(%rsp), %rdx
btcq %rax, %rdx
movq 0x8058(%rdi,%rax,8), %rcx
notq %rcx
andq %rdx, %rcx
movq 0x10(%rsp), %r8
movq %r13, %rsi
movq (%rsp), %rdx
callq 0x45d0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq