// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/cactustree.c
// Function: characteristics
struct Characteristics *characteristics(struct Vertex *w, const int treeID, const int wTreeID, struct Characteristics *oldCharacteristics, struct Characteristics *newCharacteristics, struct Vertex *patternVertex, int patternSize, struct GraphPool *gPool){
    struct Characteristics *ret=newCharacteristics;
    struct VertexList *edgehlp, *edgehlp2, *edgehlp3, *edgehlp4, *tmprm=NULL;
    struct Graph *bipartite;
    int i=0, j=0, numTree=0, numPattern, matchingSize, numRem=0;

    //TODO single vertex pattern.
    //printf("gV %i pV %i\n",w->number, patternVertex->number);
    if(isLeaf(patternVertex)){
        //printf("leaf %i\n",w->number);
        for(edgehlp=w->neighborhood; edgehlp; edgehlp=edgehlp->next)
            if(((edgehlp->flag & 1) && (checkCharacteristic(newCharacteristics,edgehlp->endPoint->number,patternVertex->number, patternVertex->neighborhood->endPoint->number, treeID)))
                    ||((edgehlp->flag & 2) && (checkCharacteristic(oldCharacteristics,edgehlp->endPoint->number,patternVertex->number, patternVertex->neighborhood->endPoint->number, wTreeID)))){
                freeCharacteristics(ret);
                return insertCharacteristic(NULL, patternSize, w->number, patternVertex->number, patternVertex->number, treeID);
            }
        return insertCharacteristic(ret,patternSize,w->number, patternVertex->neighborhood->endPoint->number, patternVertex->number, treeID);
    }
    
    //printf("Checking neighbours of gV\n");
    for(edgehlp=w->neighborhood; edgehlp;edgehlp=edgehlp->next){
        //printf("\t(%i %i)" ,edgehlp->endPoint->number, edgehlp->flag);
        if((edgehlp->flag)){//part of the tree
           ++numTree;
        }
    }
    //printf("\n");
    numPattern=degree(patternVertex);
    if(numPattern-1>numTree) return ret;
    edgehlp=patternVertex->neighborhood;
    bipartite=createGraph(numPattern+numTree, gPool);
    //printf("\n nP %i nt %i  T %i wT %i\n",numPattern, numTree, treeID, wTreeID);
    for(;i<numPattern;++i){
        bipartite->vertices[i]->lowPoint =0;
        //setting vertexnumber for neighborhood.
        edgehlp->endPoint->d=i;
        edgehlp2=w->neighborhood;
        bipartite->vertices[i]->d=edgehlp->endPoint->number;
        for(j=0;j<numTree;++j){
            while(!(edgehlp2->flag)) edgehlp2=edgehlp2->next;
            /*
            printf("checking edge ");
            if(edgehlp2) printf(" (gN %i %i) ", edgehlp2->endPoint->number ,edgehlp2->flag);
            if((edgehlp)) printf(" (pN %i) ", edgehlp->endPoint->number);
            printf("\n");
            */
            if( (((edgehlp2->flag & 1) && checkCharacteristic(newCharacteristics,edgehlp2->endPoint->number,patternVertex->number, edgehlp->endPoint->number,treeID))
                    ||((edgehlp2->flag & 2) && checkCharacteristic(oldCharacteristics, edgehlp2->endPoint->number, patternVertex->number, edgehlp->endPoint->number,wTreeID)))){
                edgehlp3=getVertexList(gPool->listPool);
                edgehlp4=getVertexList(gPool->listPool);
                edgehlp3->label = (char *)edgehlp4;
                edgehlp3->startPoint=bipartite->vertices[i];
                ++(bipartite->vertices[i]->lowPoint);
                edgehlp3->endPoint=bipartite->vertices[numPattern+j];
                addEdge(edgehlp3->startPoint,edgehlp3);
                edgehlp4->label = (char *)edgehlp3;
                edgehlp4->endPoint=bipartite->vertices[i];
                edgehlp4->startPoint=bipartite->vertices[numPattern+j];
                addEdge(edgehlp4->startPoint,edgehlp4);
                ++(bipartite->m);
                //printf("bedge %i,%i\t\n",i,numPattern+j);
            }
            edgehlp2=edgehlp2->next;
        }
        //printf("%i=%i\n",degree(bipartite->vertices[i]),bipartite->vertices[i]->lowPoint);
        edgehlp=edgehlp->next;
    }
    //printf("\n");
    if(bipartite->m<numPattern-1){
        dumpGraph(gPool, bipartite);
        return ret;
    }
    bipartite->number=numPattern;
    initBipartite(bipartite);
    matchingSize=bipartiteMatchingFastAndDirty(bipartite, gPool); 
    //printf("\nmatching size is %i\n", matchingSize);
    if(matchingSize==numPattern){//we have a matching that covers.
        //printf("\n\n\nAND IT MATCHES!!!!111elf\n\n\n");
        freeCharacteristics(ret);
        dumpGraph(gPool,bipartite);
        return insertCharacteristic(NULL, patternSize, w->number, patternVertex->number, patternVertex->number, treeID);
    }
    // now start removing neighbours.
    /*
    int p;
    struct VertexList *debug;
    printf("\n complete bipartie\n");
        for(p=0;p<numPattern+numTree;++p){
            printf("%i",bipartite->vertices[p]->number);
            for(debug=bipartite->vertices[p]->neighborhood;debug;debug=debug->next) printf("  (%i cb  %i)", debug->startPoint->number, debug->endPoint->number);
        }
    */
    for(j=0;j<numPattern;++j){
        //printf("rem vert %i ",j);
        //printf("%i %i \n",bipartite->vertices[j]->lowPoint , degree(bipartite->vertices[i]));
        if(bipartite->m - bipartite->vertices[j]->lowPoint >= numPattern-1){
            tmprm=bipartite->vertices[j]->neighborhood;
            bipartite->vertices[j]->neighborhood=NULL;
            for(edgehlp=tmprm;edgehlp;edgehlp=edgehlp->next){
                deleteEdge(bipartite, edgehlp->endPoint->number, j);
                ++numRem;
            }
            
            bipartite->m -= numRem;
            /*
            printf("after removal " );
            for(p=0;p<numPattern+numTree;++p){
                printf("%i",bipartite->vertices[p]->number);
                for(debug=bipartite->vertices[p]->neighborhood;debug;debug=debug->next) printf("  (%i ar %i)", debug->startPoint->number, debug->endPoint->number);
            }
            */
            initBipartite(bipartite);
            matchingSize=bipartiteMatchingFastAndDirty(bipartite, gPool);
            //printf("\nmatching size is %i\n", matchingSize);
            if(matchingSize ==numPattern-1){//we have a matching that covers.
                //printf("\nsmall matching\n");
                ret=insertCharacteristic(ret, patternSize, w->number, bipartite->vertices[j]->d, patternVertex->number, treeID);
            }
        
        //reinsert removed Edges.
            bipartite->vertices[j]->neighborhood=tmprm;
            for(edgehlp=tmprm;edgehlp;edgehlp=edgehlp->next){
                edgehlp2=(struct VertexList *)edgehlp->label;
                addEdge(edgehlp2->startPoint,edgehlp2);
            }
            /*
            printf("\nAfter reinsertion: \n");
            for(p=0;p<numPattern+numTree;++p){
                printf("%i",bipartite->vertices[p]->number);
                for(debug=bipartite->vertices[p]->neighborhood;debug;debug=debug->next) printf("  (%i ai %i)", debug->startPoint->number, debug->endPoint->number);
            }
            */
            bipartite->m += numRem;
            numRem=0;
        }
    }
    dumpGraph(gPool,bipartite);
    return ret;
}

// Assembly:
subq $0x88, %rsp
movq 0x98(%rsp), %rax
movl 0x90(%rsp), %eax
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movl %edx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x58(%rsp), %rdi
callq 0xa490
cmpb $0x0, %al
je 0x4109
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x40c5
movq 0x48(%rsp), %rax
movl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x401c
movq 0x60(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq 0x58(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movl 0x74(%rsp), %r8d
callq 0x46e0
movsbl %al, %eax
cmpl $0x0, %eax
jne 0x406b
movq 0x48(%rsp), %rax
movl 0x24(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x40b0
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq 0x58(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movl 0x70(%rsp), %r8d
callq 0x46e0
movsbl %al, %eax
cmpl $0x0, %eax
je 0x40b0
movq 0x50(%rsp), %rdi
callq 0x3550
movl 0x90(%rsp), %esi
movq 0x78(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %r8d
movl 0x74(%rsp), %r9d
xorl %eax, %eax
movl %eax, %edi
callq 0x4790
movq %rax, 0x80(%rsp)
jmp 0x46c5
jmp 0x40b2
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x3fc5
movq 0x50(%rsp), %rdi
movl 0x90(%rsp), %esi
movq 0x78(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %r8d
movl 0x74(%rsp), %r9d
callq 0x4790
movq %rax, 0x80(%rsp)
jmp 0x46c5
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x4147
movq 0x48(%rsp), %rax
cmpl $0x0, 0x24(%rax)
je 0x4135
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x4137
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x4117
movq 0x58(%rsp), %rdi
callq 0xa440
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
subl $0x1, %eax
cmpl 0x14(%rsp), %eax
jle 0x4174
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x46c5
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movl 0x10(%rsp), %edi
addl 0x14(%rsp), %edi
movq 0x98(%rsp), %rsi
callq 0xb850
movq %rax, 0x20(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x10(%rsp), %eax
jge 0x441d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x20(%rax)
movl 0x1c(%rsp), %ecx
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x28(%rax)
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x28(%rax)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x14(%rsp), %eax
jge 0x43ff
jmp 0x421a
movq 0x40(%rsp), %rax
cmpl $0x0, 0x24(%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x422e
jmp 0x423e
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x421a
movq 0x40(%rsp), %rax
movl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4285
movq 0x60(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq 0x58(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movl 0x74(%rsp), %r8d
callq 0x46e0
movsbl %al, %eax
cmpl $0x0, %eax
jne 0x42d4
movq 0x40(%rsp), %rax
movl 0x24(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x43e1
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq 0x58(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
movl 0x70(%rsp), %r8d
callq 0x46e0
movsbl %al, %eax
cmpl $0x0, %eax
je 0x43e1
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x10(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0xa660
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x10(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rsi
callq 0xa660
movq 0x20(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x420a
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x419c
movq 0x20(%rsp), %rax
movl 0x4(%rax), %eax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4454
movq 0x98(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x1fb30
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x46c5
movl 0x10(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x20(%rsp), %rdi
callq 0x1f20
movq 0x20(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x20a0
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x10(%rsp), %eax
jne 0x44e1
movq 0x50(%rsp), %rdi
callq 0x3550
movq 0x98(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x1fb30
movl 0x90(%rsp), %esi
movq 0x78(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %r8d
movl 0x74(%rsp), %r9d
xorl %eax, %eax
movl %eax, %edi
callq 0x4790
movq %rax, 0x80(%rsp)
jmp 0x46c5
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x10(%rsp), %eax
jge 0x46a6
movq 0x20(%rsp), %rax
movl 0x4(%rax), %eax
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
subl 0x20(%rcx), %eax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x4694
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x8(%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x459f
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movl 0x18(%rsp), %edx
callq 0xaaa0
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x4562
movl 0x8(%rsp), %edx
movq 0x20(%rsp), %rax
movl 0x4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x4(%rax)
movq 0x20(%rsp), %rdi
callq 0x1f20
movq 0x20(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x20a0
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4620
movq 0x50(%rsp), %rdi
movl 0x90(%rsp), %esi
movq 0x78(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
movq 0x58(%rsp), %rax
movl 0x18(%rax), %r8d
movl 0x74(%rsp), %r9d
callq 0x4790
movq %rax, 0x50(%rsp)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x467d
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x40(%rsp), %rsi
callq 0xa660
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x4645
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movl $0x0, 0x8(%rsp)
jmp 0x4696
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x44e9
movq 0x98(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x1fb30
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)