// File: /workspace/github_cpp_makefile_star2_O1/canzarlab[P]Trajan/src/match.cpp
// Function: tree::tree(char const*, char const*)
tree(const char* filename, const char* mapname) : n(0), nb(0), r(-1)
    {
        ifstream file(filename), mapfile(mapname);
        if (!file || !mapfile)
            die();

        // map string indices to integers
        int node_idx; string node_name;
        while (mapfile >> node_idx >> node_name)
            m[node_name] = node_idx;
        n = m.size();

        // create reverse mapping
        rm.resize(n);
        for (auto [name, idx] : m)
            rm[idx] = name;

        // nroot[x] == 1 means x is not the root
        vector<int> nroot(MAXN);

        // read from file
        string sa, sb, type;
        while (file >> sa >> sb >> type)
        {
            if (type != "default")
                die();

            // directed edge sb->sa
            int x = m[sa], y = m[sb];
            adj[y].push_back(x);
            nroot[x] = 1;
        }

        // tree too big
        if (m.size() > MAXN)
            die();

        // find root
        for (uint i = 0; i < m.size(); ++i)
        {
            // found the root
            if (!nroot[i])
            {
                // multiple roots
                if (r != -1)
                    die();

                r = i;
            }
        }

        // tree has no root
        if (r == -1)
            die();

        // identify branching nodes
        function<void(int)> mark = [&] (int x)
        {
            for (int y : adj[x])
            {
                // fill the parent table
                par[y] = x;
                mark(y);
            }
            // x is a leaf/branching node - record finishing time
            if (adj[x].size() != 1)
                b[nb++] = x;
        };
        // root has no parent
        par[r] = -1;
        mark(r);

        // too many leaf/branching nodes
        if (nb > MAXLB)
            die();

        // obtain topological ordering
        reverse(b, b + nb);

        // create node->leaf/branching node index mapping
        memset(rb, -1, sizeof rb);
        for (int i = 0; i < nb; ++i)
            rb[b[i]] = i;

        // fill the table of immediate leaf/branching descendant masks
        function<mask(int)> child = [&] (int x)
        {
            mask msk = 0;
            for (int y : adj[x])
                msk |= child(y);

            // x is a leaf/branching node
            if (rb[x] != -1)
            {
                // record leaf/branching children mask
                ch[rb[x]] = msk;
                return in(rb[x]);
            }
            return msk;
        };
        child(r);

        // identify branching ancestors
        function<void(int, mask, int)> branch = [&] (int x, mask m, int p)
        {
            // x is a branching or leaf node
            if (rb[x] != -1)
            {
                // set branching ancestor mask
                ba[rb[x]] = m;
                m |= in(rb[x]);
                // set branching parent
                bp[rb[x]] = p;
                p = x;
            }
            for (int y : adj[x])
                branch(y, m, p);
        };
        branch(r, 0, -1);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x538, %rsp            # imm = 0x538
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %r13
movl $0x0, 0x8(%rdi)
movq $0x0, 0x10(%rdi)
movq %r13, 0x18(%rdi)
movq %r13, 0x20(%rdi)
leaq 0x28(%rdi), %r12
leaq 0x30(%rdi), %rax
movq %rax, 0x8(%rsp)
movl $0x5de8, %edx           # imm = 0x5DE8
movq %r12, %rdi
xorl %esi, %esi
callq 0x3150
movl $0xffffffff, 0x5e10(%rbx) # imm = 0xFFFFFFFF
leaq 0x330(%rsp), %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x3400
leaq 0x128(%rsp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x3400
movq %r12, 0xb8(%rsp)
movq 0x330(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x350(%rsp,%rax)
jne 0x612a
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x148(%rsp,%rax)
jne 0x612a
leaq 0x48(%rbx), %rax
movq %rax, 0xc0(%rsp)
leaq 0x118(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x128(%rsp), %r14
leaq 0x1c(%rsp), %r15
leaq 0x108(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x3170
movq %rax, %rdi
movq %r12, %rsi
callq 0x3290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5c3c
movl 0x1c(%rsp), %ebp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6786
movl %ebp, (%rax)
jmp 0x5c05
movq 0x28(%rbx), %rax
movl %eax, 0x5e08(%rbx)
movslq %eax, %rsi
movq 0x8(%rsp), %rdi
callq 0x6802
movq 0x18(%rbx), %r14
cmpq %r13, %r14
je 0x5cc1
leaq 0x58(%rsp), %rbp
leaq 0x48(%rsp), %r15
movq %rbp, 0x48(%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x6bb2
movslq 0x40(%r14), %rdi
movl %edi, 0x68(%rsp)
shlq $0x5, %rdi
movq 0x8(%rsp), %rax
addq (%rax), %rdi
movq %r15, %rsi
callq 0x3140
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5cb1
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
movq %r14, %rdi
callq 0x31a0
movq %rax, %r14
cmpq %r13, %rax
jne 0x5c66
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x3220
xorl %r14d, %r14d
movl $0xfa0, %edx            # imm = 0xFA0
movq %rax, 0x10(%rsp)
movq %rax, %rdi
xorl %esi, %esi
callq 0x3150
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb %r14b, (%rax)
leaq 0x330(%rsp), %rbp
leaq 0x48(%rsp), %r12
leaq 0xe8(%rsp), %r14
leaq 0xc8(%rsp), %r13
leaq 0x53ac(%rip), %r15      # 0xb0e8
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3290
movq %rax, %rdi
movq %r14, %rsi
callq 0x3290
movq %rax, %rdi
movq %r13, %rsi
callq 0x3290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5de7
movq %r13, %rdi
movq %r15, %rsi
callq 0x30b0
testl %eax, %eax
jne 0x60ec
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6786
movl (%rax), %eax
movl %eax, 0x20(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6786
movslq (%rax), %rax
leaq (%rax,%rax,2), %rax
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5dc7
movl 0x20(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5dd1
leaq 0x20(%rsp), %rdx
callq 0x7410
movslq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx,%rax,4)
jmp 0x5d3c
movq 0xb8(%rsp), %rax
movq (%rax), %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
ja 0x6149
testq %rax, %rax
movq 0x10(%rsp), %r12
je 0x5e30
movl 0x5e10(%rbx), %edx
xorl %ecx, %ecx
cmpl $0x0, (%r12,%rcx,4)
jne 0x5e28
cmpl $-0x1, %edx
jne 0x610b
movl %ecx, 0x5e10(%rbx)
movl %ecx, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x5e10
movslq 0x5e10(%rbx), %rax
cmpq $-0x1, %rax
je 0x6168
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %rbx, 0x20(%rsp)
leaq 0x20(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x108a(%rip), %rcx      # 0x6eee
movq %rcx, 0x38(%rsp)
leaq 0x1084(%rip), %rcx      # 0x6ef4
movq %rcx, 0x30(%rsp)
movl $0xffffffff, 0x5f14(%rbx,%rax,4) # imm = 0xFFFFFFFF
movl 0x5e10(%rbx), %eax
leaq 0x90(%rsp), %r14
movl %eax, (%r14)
movq %r14, %rsi
callq 0x6f1c
movslq 0x5e0c(%rbx), %rax
cmpq $0x41, %rax
jge 0x6187
leaq 0x5e14(%rbx), %rcx
testl %eax, %eax
setne %dl
leaq (%rbx,%rax,4), %rax
addq $0x5e10, %rax           # imm = 0x5E10
cmpq %rcx, %rax
seta %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x5eee
leaq 0x5e18(%rbx), %rcx
movl -0x4(%rcx), %edx
movl (%rax), %esi
movl %esi, -0x4(%rcx)
movl %edx, (%rax)
addq $-0x4, %rax
leaq 0x4(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x5ed4
leaq 0x70b8(%rbx), %rdi
movl $0xfa0, %edx            # imm = 0xFA0
movl $0xff, %esi
callq 0x3150
cmpl $0x0, 0x5e0c(%rbx)
jle 0x5f2d
xorl %eax, %eax
movslq 0x5e14(%rbx,%rax,4), %rcx
movl %eax, 0x70b8(%rbx,%rcx,4)
incq %rax
movslq 0x5e0c(%rbx), %rcx
cmpq %rcx, %rax
jl 0x5f0f
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq %rbx, 0x90(%rsp)
movq %r14, 0x98(%rsp)
leaq 0x106d(%rip), %rax      # 0x6fc4
movq %rax, 0xa8(%rsp)
leaq 0x1064(%rip), %rax      # 0x6fca
movq %rax, 0xa0(%rsp)
movl 0x5e10(%rbx), %eax
leaq 0x70(%rsp), %r15
movl %eax, (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x6ff2
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
movq %r15, 0x78(%rsp)
leaq 0x10e2(%rip), %rax      # 0x708a
movq %rax, 0x88(%rsp)
leaq 0x10d9(%rip), %rax      # 0x7090
movq %rax, 0x80(%rsp)
movl 0x5e10(%rbx), %esi
movq %r15, %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x6832
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x5ff0
leaq 0x70(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0x600f
leaq 0x90(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x6028
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x604d
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x6072
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x608e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
movl $0xfa0, %esi            # imm = 0xFA0
movq %r12, %rdi
callq 0x3230
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x60c0
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x3230
leaq 0x128(%rsp), %rdi
callq 0x3090
leaq 0x330(%rsp), %rdi
callq 0x3090
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4fc8(%rip), %rdi      # 0xb0bb
leaq 0x4f8a(%rip), %rsi      # 0xb084
leaq 0x4fc0(%rip), %rcx      # 0xb0c1
movl $0x93, %edx
callq 0x3180
leaq 0x4fa9(%rip), %rdi      # 0xb0bb
leaq 0x4f6b(%rip), %rsi      # 0xb084
leaq 0x4fa1(%rip), %rcx      # 0xb0c1
movl $0xa7, %edx
callq 0x3180
leaq 0x4f8a(%rip), %rdi      # 0xb0bb
leaq 0x4f4c(%rip), %rsi      # 0xb084
leaq 0x4f82(%rip), %rcx      # 0xb0c1
movl $0x7e, %edx
callq 0x3180
leaq 0x4f6b(%rip), %rdi      # 0xb0bb
leaq 0x4f2d(%rip), %rsi      # 0xb084
leaq 0x4f63(%rip), %rcx      # 0xb0c1
movl $0x9d, %edx
callq 0x3180
leaq 0x4f4c(%rip), %rdi      # 0xb0bb
leaq 0x4f0e(%rip), %rsi      # 0xb084
leaq 0x4f44(%rip), %rcx      # 0xb0c1
movl $0xaf, %edx
callq 0x3180
leaq 0x4f2d(%rip), %rdi      # 0xb0bb
leaq 0x4eef(%rip), %rsi      # 0xb084
leaq 0x4f25(%rip), %rcx      # 0xb0c1
movl $0xc4, %edx
callq 0x3180
jmp 0x6213
jmp 0x6213
jmp 0x6213
movq %rax, %r12
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x61d2
leaq 0x70(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x61d2
jmp 0x6213
movq %rax, %r12
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0x61f8
leaq 0x90(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x61f8
jmp 0x6213
movq %rax, %r12
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x6258
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x6258
movq %rax, %rdi
callq 0x651f
jmp 0x6250
jmp 0x6250
movq %rax, %r12
jmp 0x6302
movq %rax, %r12
jmp 0x630f
jmp 0x6250
movq %rax, %r12
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x62d0
movq 0x58(%rsp), %rsi
incq %rsi
jmp 0x62cb
jmp 0x6255
jmp 0x6255
movq %rax, %r12
jmp 0x62d0
movq %rax, %r12
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
movq 0x10(%rsp), %r14
je 0x6282
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x62a7
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x62c3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
movl $0xfa0, %esi            # imm = 0xFA0
movq %r14, %rdi
callq 0x3230
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x62f5
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x3230
leaq 0x128(%rsp), %rdi
callq 0x3090
leaq 0x330(%rsp), %rdi
callq 0x3090
movl $0x5e00, %r14d          # imm = 0x5E00
movq -0x10(%rbx,%r14), %rdi
testq %rdi, %rdi
je 0x632b
movq (%rbx,%r14), %rsi
subq %rdi, %rsi
callq 0x3230
addq $-0x18, %r14
cmpq $0x40, %r14
jne 0x6315
movq 0x8(%rsp), %rdi
callq 0x6866
movq %rbx, %rdi
callq 0x7128
movq %r12, %rdi
callq 0x33e0
nop