// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/cactustree.c
// Function: cactusTreeSubIso
int cactusTreeSubIso(struct Graph * graph, struct Graph *pattern, struct GraphPool *gPool, struct ShallowGraphPool *sgPool){

    struct ShallowGraph *bComponents = listBiconnectedComponents(graph, sgPool);
    int numComponents =0;
    
    // Setting distances to vertex_0.
    struct ShallowGraph *shlp, **rootedComponents;
    struct Graph *componentTree;
    struct VertexList *lhlp;
    struct Vertex ** representatives;
    struct Vertex * componentRepresentative, *rootRepresentative;
    struct Characteristics *res;
    int i = 0;
    representatives = malloc(graph->n * sizeof(struct Vertex *));
    //TODO remove debug
    /*
    printf("MAIN\n");
    for(shlp=bComponents;shlp;shlp=shlp->next){
        printf("Component: %i\n", numComponents++);
        for(lhlp=shlp->edges; lhlp; lhlp=lhlp->next){
            printf ("\t(%i, %i)",lhlp->startPoint->number,lhlp->endPoint->number);
        }
        printf("\n");
    }
    //TODO remove when debug is removed
    numComponents=0;
    */
    if(representatives == NULL){
        //TODO clean up
        return 0;
    }
    for(;i<graph->n;++i){
        representatives[i]=NULL;
        graph->vertices[i]->d=-1;
    }
    for(shlp=bComponents;shlp;shlp=shlp->next){
        ++numComponents;
        componentRepresentative = shlp->edges->startPoint;
        rootRepresentative = representatives[shlp->edges->startPoint->number];
        //We will initialize the LUT from old graph vertices to component numbers.
        for(lhlp=shlp->edges; lhlp; lhlp=lhlp->next){
            representatives[lhlp->endPoint->number]=componentRepresentative;
        }
        //Now reset the representative for the root as we may have set it.
        //This way the representative of a component root will only be set during processing of another component,
        //where it is not a root.
        representatives[shlp->edges->startPoint->number]=rootRepresentative;

    }
    //set entries in the LUT
    //and set all roots to unvisited.
    i=-1;
    for(shlp=bComponents;shlp;shlp=shlp->next){
        if(shlp->edges->startPoint->d< 0) shlp->edges->startPoint->d=++i;
        shlp->edges->startPoint->visited=0;
    }
    //printf("Allocating component tree\n");

    rootedComponents=calloc(numComponents,sizeof(struct ShallowGraph *));
    componentTree=computeComponentTree(representatives, bComponents, numComponents, rootedComponents, gPool);
    free(representatives);
    res=processRootTree(componentTree->vertices[graph->vertices[0]->d], graph, rootedComponents, pattern, gPool, sgPool);
    for(i=0;i<numComponents;++i)
       dumpShallowGraphCycle(sgPool, rootedComponents[i]);
    free(rootedComponents);
    dumpGraph(gPool,componentTree);
    if(hasSolution(res)){
        freeCharacteristics(res);
        return 1;
    }
    freeCharacteristics(res);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, (%rsp)
movq %rsi, %r13
movq %rdi, %r12
movq %rcx, %rsi
callq 0x8ccd
movq %rax, %r15
movslq (%r12), %rbx
leaq (,%rbx,8), %rdi
callq 0x1180
testq %rax, %rax
je 0x21d1
movq %rax, %rbp
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0x20bb
andq $0x0, (%rbp,%rax,8)
movq 0x10(%r12), %rcx
movq (%rcx,%rax,8), %rcx
orl $-0x1, 0x28(%rcx)
incq %rax
jmp 0x209e
movq %r13, 0x10(%rsp)
xorl %r13d, %r13d
movq %r15, %rax
testq %rax, %rax
je 0x2101
movq (%rax), %rsi
movq 0x10(%rsi), %rdi
movslq 0x18(%rdi), %rcx
movq (%rbp,%rcx,8), %rdx
testq %rsi, %rsi
je 0x20f3
movq 0x18(%rsi), %r8
movslq 0x18(%r8), %r8
movq %rdi, (%rbp,%r8,8)
movq 0x8(%rsi), %rsi
jmp 0x20db
incq %r13
movq %rdx, (%rbp,%rcx,8)
movq 0x18(%rax), %rax
jmp 0x20c6
pushq $-0x1
popq %rax
movq %r15, %rcx
testq %rcx, %rcx
je 0x2128
movq (%rcx), %rdx
movq 0x10(%rdx), %rdx
cmpl $0x0, 0x28(%rdx)
jns 0x211e
incl %eax
movl %eax, 0x28(%rdx)
andl $0x0, 0x1c(%rdx)
movq 0x18(%rcx), %rcx
jmp 0x2107
movl %r13d, %edi
pushq $0x8
popq %rsi
callq 0x1110
movq %r15, %rsi
movq %rax, %r15
movq %rbp, %rdi
movl %r13d, %edx
movq %rax, %rcx
movq (%rsp), %r8
callq 0x21e2
movq %rax, %rbx
movq %rbp, %rdi
callq 0x1030
movq %rbx, 0x8(%rsp)
movq 0x10(%rbx), %rax
movq 0x10(%r12), %rcx
movq (%rcx), %rcx
movslq 0x28(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %rcx
movq (%rsp), %r8
movq %r14, %r9
callq 0x22a5
movq %rax, %r12
movq %r15, %rbp
subq $0x1, %r13
jb 0x21a4
movq (%rbp), %rsi
movq %r14, %rdi
callq 0x11888
addq $0x8, %rbp
jmp 0x218c
movq %r15, %rdi
callq 0x1030
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1166e
movq %r12, %rdi
callq 0x23da
movl %eax, %ebx
movq %r12, %rdi
callq 0x2411
movzbl %bl, %eax
jmp 0x21d3
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq