// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq 0x78(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x10700
movq %rax, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
callq 0x1170
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x2e5d
movl $0x0, 0x84(%rsp)
jmp 0x30d8
jmp 0x2e5f
movl 0xc(%rsp), %eax
movq 0x78(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x2ea4
movq 0x28(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x2e5f
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x2f65
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x2f34
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x2f01
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x2eae
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x2fce
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
cmpl $0x0, 0x28(%rax)
jge 0x2fab
movl 0xc(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x28(%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x1c(%rax)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x2f77
movslq 0x54(%rsp), %rdi
movl $0x8, %esi
callq 0x1100
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl 0x54(%rsp), %edx
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r8
callq 0x30f0
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rdi
callq 0x1030
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x78(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
movslq 0x28(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x78(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x3280
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x3085
movq 0x60(%rsp), %rdi
movq 0x40(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x20000
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3056
movq 0x40(%rsp), %rdi
callq 0x1030
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movq 0x10(%rsp), %rdi
callq 0x34d0
cmpb $0x0, %al
je 0x30c3
movq 0x10(%rsp), %rdi
callq 0x3550
movl $0x1, 0x84(%rsp)
jmp 0x30d8
movq 0x10(%rsp), %rdi
callq 0x3550
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw (%rax,%rax)