// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x611d
cmpq $0x0, -0x28(%rbp)
jne 0x6122
jmp 0x66da
leaq 0x281d7(%rip), %rdi     # 0x2e300
leaq -0x20(%rbp), %rsi
callq 0x7e20
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x7f30
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8550
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8570
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8590
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x85b0
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x85d0
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x85f0
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8610
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8630
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8650
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8670
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
testl %eax, %eax
je 0x61fb
jmp 0x61d6
movl -0xcc(%rbp), %eax
subl $0x1, %eax
je 0x628d
jmp 0x61e7
movl -0xcc(%rbp), %eax
subl $0x2, %eax
je 0x632d
jmp 0x66da
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %edi
callq 0x79f0
movq -0xf0(%rbp), %rdi
xorq %rax, %rdi
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
xorq 0x6eb8(%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
movq 0x8058(%rax,%rcx,8), %rsi
callq 0x81f0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq %rax, %rcx
movq -0x28(%rbp), %r8
callq 0x60f0
jmp 0x66da
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %edi
callq 0x79f0
movq -0x118(%rbp), %rdi
xorq %rax, %rdi
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
xorq 0x6eb8(%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
movq 0x8058(%rax,%rcx,8), %rsi
callq 0x81f0
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
movq -0xf8(%rbp), %rcx
movq %rax, %r8
callq 0x60f0
jmp 0x66da
movl $0x0, -0x84(%rbp)
movslq -0x84(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x50(%rbp), %rdi
callq 0x8210
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x66d8
movq -0x50(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x8690
cmpl $-0x1, (%rax)
jne 0x637b
jmp 0x66c4
movq -0x50(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x8690
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x8690
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x60(%rbp), %rdi
movslq -0x88(%rbp), %rsi
callq 0x8690
movl (%rax), %eax
movl %eax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl 0x5e14(%rax,%rcx,4), %eax
movl %eax, -0x94(%rbp)
movq -0x68(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x8690
movl (%rax), %eax
movl %eax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl 0x5e14(%rax,%rcx,4), %eax
movl %eax, -0x9c(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x88(%rbp), %rsi
callq 0x8690
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0x80(%rbp), %rdi
movl -0x84(%rbp), %esi
movl -0x88(%rbp), %edx
callq 0x79b0
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x78(%rbp), %rdi
movl -0x84(%rbp), %esi
movl -0x88(%rbp), %edx
callq 0x79b0
movl (%rax), %eax
movl %eax, -0x124(%rbp)
testl %eax, %eax
je 0x6488
jmp 0x6463
movl -0x124(%rbp), %eax
subl $0x1, %eax
je 0x6542
jmp 0x6474
movl -0x124(%rbp), %eax
subl $0x2, %eax
je 0x65f6
jmp 0x66c2
movq -0x8(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x8c(%rbp), %edi
callq 0x79f0
movq %rax, -0x150(%rbp)
movl -0xa4(%rbp), %edi
callq 0x79f0
movq %rax, %rcx
movq -0x150(%rbp), %rax
orq %rcx, %rax
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rdx
movslq -0x8c(%rbp), %rsi
andq 0x8058(%rdx,%rsi,8), %rcx
orq %rcx, %rax
movq %rax, -0x130(%rbp)
movl -0x90(%rbp), %edi
callq 0x79f0
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
movq -0x130(%rbp), %rcx
movq %rax, %r8
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %r9
movslq -0x90(%rbp), %r10
andq 0x8058(%r9,%r10,8), %rax
orq %rax, %r8
callq 0x60f0
jmp 0x66c2
movq -0x8(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x8c(%rbp), %edi
callq 0x79f0
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rdx
movslq -0x8c(%rbp), %rsi
andq 0x8058(%rdx,%rsi,8), %rcx
orq %rcx, %rax
movq %rax, -0x158(%rbp)
movl -0x90(%rbp), %edi
callq 0x79f0
movq %rax, -0x178(%rbp)
movl -0xa4(%rbp), %edi
callq 0x79f0
movq -0x178(%rbp), %r8
movq -0x170(%rbp), %rdi
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
movq -0x158(%rbp), %rcx
orq %rax, %r8
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %r9
movslq -0x90(%rbp), %r10
andq 0x8058(%r9,%r10,8), %rax
orq %rax, %r8
callq 0x60f0
jmp 0x66c2
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x8260
leaq 0x27d21(%rip), %rdi     # 0x2e338
leaq -0xb8(%rbp), %rsi
callq 0x8340
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x86b0
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x86d0
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0xc8(%rbp), %rcx
movl -0x98(%rbp), %r8d
movl -0xa0(%rbp), %r9d
movl -0x94(%rbp), %r10d
movl -0x9c(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x5fb0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq 0x6eb8(%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movslq -0x90(%rbp), %r8
movq 0x6eb8(%rax,%r8,8), %r8
callq 0x60f0
jmp 0x66c4
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x6337
jmp 0x66da
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)