// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/path.c
// Function: graph_path_extension
static llnode **graph_path_extension(asmg_t *g, llnode *root, kh_u32_t *seg_dups, int max_path, uint64_t *n_leaf, int *_exceed_limit)
{
    uint64_t i, j, v, w, nv;
    int skip, exceed_limit;
    llnode *next_node, *node;
    kdq_llnodep_t *node_q;
    void *km;
    asmg_arc_t *av;
    khint32_t k32;

    kvec_t(llnodep) leaf_node;
    kvec_t(uint32_t) dups;

    kv_init(leaf_node);
    kv_init(dups);
    km = km_init();
    node_q = kdq_init_llnodep(km);

    exceed_limit = 0;
    *kdq_pushp_llnodep(node_q) = root;

    while (kdq_size(node_q) > 0) {
        node = *kdq_shift_llnodep(node_q);
        v = node->v;
        nv = asmg_arc_n(g, v);
        av = asmg_arc_a(g, v);
        dups.n = 0;
        for (i = 0; i < nv; ++i) {
            if (av[i].del) continue;

            w = av[i].w;
            skip = 0;
            k32 = kh_u32_get(seg_dups, w >> 1);
            if (k32 < kh_end(seg_dups)) {
                // dup seg
                // check if already processed
                for (j = 0; j < dups.n; ++j) {
                    if (dups.a[j] == kh_val(seg_dups, k32)) {
                        skip = 1;
                        break;
                    }
                }
            }

            if (!skip && !path_contain_vertex(node, w)) {
                next_node = new_node(w);
                next_node->prev = node;
                add_next(node, next_node);
                *kdq_pushp_llnodep(node_q) = next_node;
                
                if (k32 < kh_end(seg_dups))
                    kv_push(uint32_t, dups, kh_val(seg_dups, k32));
            }
        }

        if (node->n_n == 0) {
            // leaf node
            kv_push(llnodep, leaf_node, node);
        }
        
        if (kdq_size(node_q) + leaf_node.n > max_path) {
            exceed_limit = 1;
            break;
        }
    }

    kdq_destroy_llnodep(node_q);
    km_destroy(km);
    kv_destroy(dups);

    if (exceed_limit) {
        *n_leaf = 0;
        *_exceed_limit = 1;
        kv_destroy(leaf_node);
        return 0;
    } else {
        *n_leaf = leaf_node.n;
        *_exceed_limit = 0;
        return leaf_node.a;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movl %ecx, %ebx
movq %rdx, 0x48(%rsp)
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
movabsq $0x3ffffffffffffff, %r12 # imm = 0x3FFFFFFFFFFFFFF
callq 0x18af3
movq %rax, %r15
movl $0x1, %r13d
movl $0x1, %esi
movl $0x28, %edx
movq %rax, %rdi
callq 0x18ab0
movq %rax, %rbp
movq (%rax), %rax
andq %r12, %rax
btsq $0x3b, %rax
movq %rax, (%rbp)
movq $0x3, 0x10(%rbp)
movl $0x20, %esi
movq %r15, %rdi
callq 0x18c11
movq %rax, 0x18(%rbp)
movq %r15, 0x68(%rsp)
movq %r15, 0x20(%rbp)
movq (%rbp), %rsi
movq 0x8(%rbp), %r12
movq %rsi, %rdx
shrq $0x3a, %rdx
movl $0x1, %edi
movl %edx, %ecx
shlq %cl, %rdi
cmpq %rdi, %r12
jne 0x7fc2
leal 0x1(%rdx), %r15d
movl %r15d, %ecx
shlq %cl, %r13
cmpq %r12, %r13
jae 0x7feb
movq $-0x1, %r15
incq %r15
movq %r12, %rdi
movl %r15d, %ecx
shrq %cl, %rdi
cmpq $0x3f, %r15
ja 0x7fbd
testq %rdi, %rdi
jne 0x7fa6
cmpq %r15, %rdx
jne 0x7fd6
movq 0x20(%rsp), %r13
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
jmp 0x80a5
movl $0x1, %r13d
movl %r15d, %ecx
shlq %cl, %r13
cmpq %rdx, %r15
jbe 0x86bb
movl $0x8, %edx
movl %r15d, %ecx
shlq %cl, %rdx
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x18d19
movq %rax, 0x18(%rbp)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
movq %rsi, %rcx
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rcx
addq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x8050
movq %r12, %rdx
subq %rcx, %rdx
movq %r13, %rsi
subq %rdx, %rsi
leaq (%rax,%rsi,8), %rdi
leaq (%rax,%rcx,8), %rsi
shlq $0x3, %rdx
callq 0x3340
subq %r12, %r13
addq (%rbp), %r13
movq %r13, %rsi
jmp 0x8069
subq %r13, %rdx
jbe 0x8069
leaq (%rax,%r13,8), %rsi
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x3340
movq (%rbp), %rsi
movq %r15, %rax
shlq $0x3a, %rax
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
andq %rdx, %rsi
orq %rax, %rsi
movq %rsi, (%rbp)
movq $-0x1, %rax
movl %r15d, %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x10(%rbp)
movq 0x8(%rbp), %r12
movq 0x18(%rbp), %rax
movq 0x20(%rsp), %r13
leaq 0x1(%r12), %rcx
movq %rcx, 0x8(%rbp)
andq %rdx, %rsi
addq %r12, %rsi
andq 0x10(%rbp), %rsi
movq %r14, (%rax,%rsi,8)
movslq %ebx, %rax
movq %rax, 0x90(%rsp)
movq $0x0, 0x18(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
movq $0x0, 0x80(%rsp)
movq 0x48(%rsp), %r9
movq %rbp, 0x8(%rsp)
movq %rcx, %r12
movq 0x18(%rbp), %rsi
testq %rcx, %rcx
je 0x8640
movq %rax, 0x50(%rsp)
movq %r14, 0x70(%rsp)
movq (%rbp), %rax
movq %rax, %rcx
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rcx
leaq 0x1(%rax), %rdx
andq %rdi, %rdx
movabsq $-0x400000000000000, %rdi # imm = 0xFC00000000000000
andq %rdi, %rax
andq 0x10(%rbp), %rdx
orq %rax, %rdx
movq %rdx, (%rbp)
movq %r12, 0x40(%rsp)
leaq -0x1(%r12), %rax
movq %rax, 0x8(%rbp)
movq (%rsi,%rcx,8), %r8
movl (%r8), %eax
movq 0x38(%r13), %rcx
movq (%rcx,%rax,8), %rcx
movq %rcx, 0x28(%rsp)
testq %rcx, %rcx
movq %r8, (%rsp)
je 0x85a6
movq 0x30(%r13), %rcx
movq (%rcx,%rax,8), %rax
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
addq 0x28(%r13), %r14
xorl %esi, %esi
xorl %r12d, %r12d
movq 0x28(%rsp), %r13
movq %r14, 0x30(%rsp)
leaq (%r12,%r12,2), %rax
shlq $0x4, %rax
testb $0x40, 0x23(%r14,%rax)
jne 0x8576
addq %r14, %rax
movq 0x8(%rax), %r14
movq 0x10(%r9), %rdx
testq %rdx, %rdx
movq %rsi, 0x38(%rsp)
je 0x8241
movq %r13, %rbp
movq %r8, %r13
movq %r14, %rsi
shrq %rsi
movl (%r9), %eax
movl $0x1, %r8d
movl %eax, %ecx
shll %cl, %r8d
movl %esi, %ecx
shll $0xf, %ecx
notl %ecx
addl %esi, %ecx
movl %ecx, %edi
shrl $0xa, %edi
xorl %ecx, %edi
leal (%rdi,%rdi,8), %ecx
movl %ecx, %edi
shrl $0x6, %edi
xorl %ecx, %edi
movl %edi, %ecx
shll $0xb, %ecx
notl %ecx
addl %edi, %ecx
movl %ecx, %edi
shrl $0x10, %edi
xorl %ecx, %edi
imull $0x9e3779b9, %edi, %edi # imm = 0x9E3779B9
movl %eax, %ecx
negb %cl
shrl %cl, %edi
movq %r8, %r11
leal -0x1(%r8), %ecx
movq %r9, %r15
movq 0x8(%r9), %r9
movl %edi, %r8d
movl %r8d, %r10d
shrl $0x5, %r10d
movl (%r9,%r10,4), %r10d
btl %r8d, %r10d
jae 0x824f
movl %r8d, %r10d
cmpl %esi, (%rdx,%r10,8)
je 0x824c
incl %r8d
andl %ecx, %r8d
cmpl %edi, %r8d
jne 0x821a
jmp 0x824f
movq %r9, %r13
movq %rbp, %r15
xorl %r11d, %r11d
jmp 0x82a5
movl %r8d, %r11d
movq %r13, %r8
movl %r11d, %esi
movl %eax, %ecx
shrl %cl, %esi
testl %esi, %esi
sete %al
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
movq %r15, %r9
jne 0x829d
movq %rbp, %r13
movl %r11d, %eax
movl 0x4(%rdx,%rax,8), %eax
xorl %ecx, %ecx
movq 0x8(%rsp), %rbp
cmpl %eax, (%rbx,%rcx,4)
je 0x8395
incq %rcx
cmpq %rcx, %rsi
jne 0x8284
movq %r9, %r13
movq %rbp, %r15
jmp 0x82a5
movq %r9, %r13
movq 0x8(%rsp), %r15
movq %r8, %rax
movl (%rax), %ecx
xorl %r14d, %ecx
cmpl $0x2, %ecx
jb 0x838a
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x82a8
movq %r11, 0x10(%rsp)
movq %rbx, 0x88(%rsp)
movl $0x28, %edi
movq %r8, %rbp
callq 0x32f0
movq %rax, %rbx
movl %r14d, (%rax)
movq $0x4, 0x10(%rax)
movq $0x0, 0x18(%rax)
movl $0x20, %edi
callq 0x32f0
movq %rax, 0x20(%rbx)
movq %rbp, 0x8(%rbx)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x86c3
movq (%r15), %rsi
movq 0x8(%r15), %r14
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r14
jne 0x839f
leal 0x1(%rax), %ebp
movl $0x1, %edx
movl %ebp, %ecx
shlq %cl, %rdx
cmpq %r14, %rdx
jae 0x83c2
movq %r13, %r9
movq $-0x1, %rbp
movq (%rsp), %r8
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rdi
incq %rbp
movq %r14, %rdx
movl %ebp, %ecx
shrq %cl, %rdx
cmpq $0x3f, %rbp
ja 0x836d
testq %rdx, %rdx
jne 0x8357
cmpq %rbp, %rax
jne 0x8584
movq 0x8(%rsp), %rbp
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
jmp 0x84d6
movq %r15, %rbp
movq %r13, %r9
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %r14
jmp 0x8576
movq %r15, %rbp
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r8
movq %r13, %r9
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rdi
jmp 0x84d6
movq %rdx, 0x78(%rsp)
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %r15
movq 0x18(%r15), %rsi
movq 0x20(%r15), %rdi
movl $0x8, %edx
movl %ebp, %ecx
shlq %cl, %rdx
callq 0x18d19
movq %rax, 0x18(%r15)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x48(%rsp), %r9
movq (%rsp), %r8
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %r15
movq %rsi, %rax
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
andq %rcx, %rax
addq %rax, %rdx
cmpq %r14, %rdx
jbe 0x846c
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq %r14, %rdx
subq %rax, %rdx
movq %r15, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x3340
movq 0x8(%rsp), %r10
movq 0x48(%rsp), %r9
movq 0x10(%rsp), %rdi
movq (%rsp), %r8
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
subq %r14, %r15
addq (%r10), %r15
movq %r15, %rsi
jmp 0x84a9
subq %r15, %rdx
movq 0x8(%rsp), %r10
jbe 0x84a9
movq 0x18(%r10), %rdi
leaq (%rdi,%r15,8), %rsi
shlq $0x3, %rdx
movq %r9, %r14
movq %r10, %r15
callq 0x3340
movq %r15, %r10
movq %r14, %r9
movq 0x10(%rsp), %rdi
movq (%rsp), %r8
movabsq $0x3ffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFF
movq (%r15), %rsi
movq %rbp, %rax
shlq $0x3a, %rax
andq %rcx, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movq %rcx, %rdx
movl %ebp, %ecx
shlq %cl, %rax
movq %rsi, (%r10)
notq %rax
movq %rax, 0x10(%r10)
movq 0x8(%r10), %r14
movq %r10, %rbp
movq 0x18(%rbp), %rax
leaq 0x1(%r14), %rcx
movq %rcx, 0x8(%rbp)
andq %rdx, %rsi
addq %r14, %rsi
andq 0x10(%rbp), %rsi
movq %rbx, (%rax,%rsi,8)
movq 0x10(%r9), %rax
testq %rax, %rax
je 0x8505
movb (%r9), %cl
movl $0x1, %edx
shll %cl, %edx
jmp 0x8507
xorl %edx, %edx
movq 0x88(%rsp), %rbx
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rsi
cmpl %edx, %edi
jae 0x8576
cmpq 0x80(%rsp), %rsi
jne 0x856a
leaq (%rsi,%rsi), %rcx
testq %rsi, %rsi
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x80(%rsp)
leaq (,%rcx,4), %rsi
movq %rbx, %rdi
movq %r9, %rbx
callq 0x3330
movq %rbx, %r9
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq (%rsp), %r8
movq %rax, %rbx
movq 0x10(%r9), %rax
movl %edi, %ecx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, (%rbx,%rsi,4)
incq %rsi
incq %r12
cmpq %r13, %r12
jne 0x818c
jmp 0x85a6
movl $0x1, %r15d
movl %ebp, %ecx
shlq %cl, %r15
cmpq %rax, %rbp
jbe 0x859e
movq %r15, 0x78(%rsp)
jmp 0x83cc
movq %r14, %rdx
jmp 0x8406
cmpq $0x0, 0x18(%r8)
je 0x85be
movq 0x20(%rsp), %r13
movq 0x70(%rsp), %r14
movq 0x40(%rsp), %r12
jmp 0x8621
movq 0x70(%rsp), %r14
movq 0x50(%rsp), %rax
cmpq %rax, %r14
movq 0x20(%rsp), %r13
jne 0x860b
movq %rbx, %r12
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq 0x18(%rsp), %rdi
movq %r9, %r15
callq 0x3330
movq %r15, %r9
movq (%rsp), %r8
movq %rbx, 0x50(%rsp)
movq %r12, %rbx
jmp 0x8610
movq 0x18(%rsp), %rax
movq 0x40(%rsp), %r12
movq %rax, 0x18(%rsp)
movq %r8, (%rax,%r14,8)
incq %r14
movq 0x8(%rbp), %rcx
leaq (%rcx,%r14), %rax
cmpq 0x90(%rsp), %rax
movq 0x50(%rsp), %rax
jbe 0x80ed
movq 0x18(%rbp), %rsi
movq 0x20(%rbp), %rdi
callq 0x18b4b
movq 0x20(%rbp), %rdi
movq %rbp, %rsi
callq 0x18b4b
movq 0x68(%rsp), %rdi
callq 0x18b0d
movq %rbx, %rdi
callq 0x3060
testq %r12, %r12
je 0x8691
movq 0x58(%rsp), %rax
movq $0x0, (%rax)
movq 0x60(%rsp), %rax
movl $0x1, (%rax)
movq 0x18(%rsp), %rdi
callq 0x3060
xorl %eax, %eax
jmp 0x86a9
movq 0x58(%rsp), %rax
movq %r14, (%rax)
movq 0x60(%rsp), %rax
movl $0x0, (%rax)
movq 0x18(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdx
jmp 0x800f