// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %r9, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movl %ecx, %r14d
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, 0x68(%rsp)
movabsq $0x3ffffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFFF
callq 0x1720b
movq %rax, %rbx
movl $0x1, %esi
movl $0x28, %edx
movq %rax, %rdi
callq 0x171c8
movq %rax, %r12
movq (%rax), %rax
andq %rbp, %rax
btsq $0x3b, %rax
movq %rax, (%r12)
movq $0x3, 0x10(%r12)
movl $0x20, %esi
movq %rbx, %rdi
callq 0x17335
movq %rax, 0x18(%r12)
movq %rbx, 0x58(%rsp)
movq %rbx, 0x20(%r12)
movq %r12, %rbx
movq %r12, %rdi
callq 0x109c2
movq %r15, (%rax)
movslq %r14d, %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x40(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %eax, %eax
movq %r12, 0x20(%rsp)
movq %r13, 0x70(%rsp)
movq 0x8(%rbx), %r11
testq %r11, %r11
je 0x80a1
movq %rax, 0x28(%rsp)
movq %r15, 0x48(%rsp)
movq (%rbx), %rax
movq 0x18(%rbx), %rcx
movq %rax, %rdx
movabsq $0x3ffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFF
andq %rdi, %rdx
leaq 0x1(%rax), %rsi
andq %rdi, %rsi
movabsq $-0x400000000000000, %rdi # imm = 0xFC00000000000000
andq %rdi, %rax
andq 0x10(%rbx), %rsi
orq %rax, %rsi
movq %rsi, (%rbx)
leaq -0x1(%r11), %rax
movq %rax, 0x8(%rbx)
movq (%rcx,%rdx,8), %rsi
movl (%rsi), %eax
movq 0x68(%rsp), %rdx
movq 0x38(%rdx), %rcx
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
movq %rsi, (%rsp)
je 0x801a
movq 0x30(%rdx), %rcx
movq (%rcx,%rax,8), %rax
leaq (%rax,%rax,2), %r8
shlq $0x4, %r8
addq 0x28(%rdx), %r8
xorl %r15d, %r15d
xorl %ebx, %ebx
movq %rdi, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %r11, 0x50(%rsp)
leaq (%rbx,%rbx,2), %rax
shlq $0x4, %rax
testb $0x40, 0x23(%r8,%rax)
jne 0x800e
addq %r8, %rax
movq 0x8(%rax), %r12
movq 0x10(%r13), %rax
xorl %edx, %edx
movl $0x0, %ebp
testq %rax, %rax
je 0x7ed9
movq %r12, %rsi
shrq %rsi
movb (%r13), %cl
movl $0x1, %ebp
shll %cl, %ebp
movl %esi, %edi
shll $0xf, %edi
notl %edi
addl %esi, %edi
movl %edi, %r8d
shrl $0xa, %r8d
xorl %edi, %r8d
leal (%r8,%r8,8), %edi
movl %edi, %r8d
shrl $0x6, %r8d
xorl %edi, %r8d
movl %r8d, %edi
shll $0xb, %edi
notl %edi
addl %r8d, %edi
movl %edi, %r8d
shrl $0x10, %r8d
xorl %edi, %r8d
imull $0x9e3779b9, %r8d, %edi # imm = 0x9E3779B9
negb %cl
shrl %cl, %edi
leal -0x1(%rbp), %ecx
movq 0x8(%r13), %r9
movl %edi, %r8d
movl %r8d, %r10d
shrl $0x5, %r10d
movl (%r9,%r10,4), %r10d
btl %r8d, %r10d
jae 0x7ecb
movl %r8d, %r10d
cmpl %esi, (%rax,%r10,8)
je 0x7ec8
incl %r8d
andl %ecx, %r8d
cmpl %edi, %r8d
jne 0x7ea1
jmp 0x7ecb
movl %r8d, %ebp
movq (%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
testq %rax, %rax
je 0x7ee9
movb (%r13), %cl
movl $0x1, %edx
shll %cl, %edx
cmpl %edx, %ebp
setb %cl
testq %r15, %r15
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x7f15
movl %ebp, %ecx
movl 0x4(%rax,%rcx,8), %eax
xorl %ecx, %ecx
cmpl %eax, (%r14,%rcx,4)
je 0x800e
incq %rcx
cmpq %rcx, %r15
jne 0x7f03
movq %rsi, %rax
movl (%rax), %ecx
xorl %r12d, %ecx
cmpl $0x2, %ecx
jb 0x800e
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x7f18
cmpl $0x2, %ecx
jb 0x800e
movl $0x28, %edi
callq 0x32f0
movq %rax, %r13
movl %r12d, (%rax)
movq $0x4, 0x10(%rax)
xorl %r12d, %r12d
movq %r12, 0x18(%rax)
movq %r12, 0x8(%rax)
movl $0x20, %edi
callq 0x32f0
movq %rax, 0x20(%r13)
movq (%rsp), %rdi
movq %rdi, 0x8(%r13)
movq %r13, %rsi
callq 0x8120
movq 0x20(%rsp), %rdi
callq 0x109c2
movq %r13, (%rax)
movq 0x70(%rsp), %r13
cmpq %r12, 0x10(%r13)
je 0x7f9e
movb (%r13), %cl
movl $0x1, %r12d
shll %cl, %r12d
cmpl %r12d, %ebp
movq 0x50(%rsp), %r11
movq 0x28(%rsp), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
jae 0x800a
cmpq %rax, %r15
jne 0x7ff3
leaq (%rax,%rax), %r12
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r12
leaq (,%r12,4), %rsi
movq %r14, %rdi
callq 0x3330
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rdi
movq 0x50(%rsp), %r11
movq %rax, %r14
movq %r12, 0x28(%rsp)
movq (%rsp), %rsi
movq 0x10(%r13), %rax
movl %ebp, %ecx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, (%r14,%r15,4)
incq %r15
jmp 0x800e
movq (%rsp), %rsi
incq %rbx
cmpq %rdi, %rbx
jne 0x7e16
cmpq $0x0, 0x18(%rsi)
je 0x802d
movq 0x20(%rsp), %rbx
movq 0x48(%rsp), %r15
jmp 0x808a
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %rax
cmpq %rax, %r15
jne 0x8074
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq 0x8(%rsp), %rdi
movq %r11, %r12
callq 0x3330
movq (%rsp), %rsi
movq %r12, %r11
movq %rbx, 0x40(%rsp)
movq 0x20(%rsp), %rbx
jmp 0x807e
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rsi, (%rax,%r15,8)
incq %r15
movq 0x8(%rbx), %rax
addq %r15, %rax
cmpq 0x60(%rsp), %rax
movq 0x28(%rsp), %rax
jbe 0x7d7a
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq %r11, %r12
callq 0x1726a
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1726a
movq 0x58(%rsp), %rdi
callq 0x1722c
movq %r14, %rdi
callq 0x3060
testq %r12, %r12
je 0x80f9
movq 0x30(%rsp), %rax
movq $0x0, (%rax)
movq 0x38(%rsp), %rax
movl $0x1, (%rax)
movq 0x8(%rsp), %rdi
callq 0x3060
xorl %eax, %eax
jmp 0x8111
movq 0x30(%rsp), %rax
movq %r15, (%rax)
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
movq 0x8(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq