// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/executables/outerplanaritytest.c
// Function: main
int main(int argc, char** argv) {

    /* object pools */
    struct ListPool *lp;
    struct VertexPool *vp;
    struct ShallowGraphPool *sgp;
    struct GraphPool *gp;

    /* pointer to the current graph which is returned by the input iterator  */
    struct Graph* g = NULL;

    char extendToHamiltonianBlocks = 0;
    char spiderWeb = 0;
    char shortcutting = 0;
    char isFirstGraph = 1;

    /* parse command line arguments */
    int arg;
    const char* validArgs = "hlsw";
    for (arg=getopt(argc, argv, validArgs); arg!=-1; arg=getopt(argc, argv, validArgs)) {
        switch (arg) {
        case 'h': // Help
            printHelp();
            return EXIT_SUCCESS;
        case 'l': // List Hamiltonian cycles in non-outerplanar Hamiltonian blocks
            extendToHamiltonianBlocks = 1;
            break;
        case 'w': // spider Web connectivity
            spiderWeb = 1;
            break;
        case 's':
            shortcutting = 1;
            break;
        case '?':
            return EXIT_FAILURE;
            break;
        }
    }

    /* init object pools */
    lp = createListPool(10000);
    vp = createVertexPool(10000);
    sgp = createShallowGraphPool(1000, lp);
    gp = createGraphPool(100, vp, lp);

    /* initialize the stream to read graphs from 
        check if there is a filename present in the command line arguments 
        if so, open the file, if not, read from stdin */
    if (optind < argc) {
        char* filename = argv[optind];
        /* if the present filename is not '-' then init a file iterator for that file name */
        if (strcmp(filename, "-") != 0) {
            createFileIterator(filename, gp);
        } else {
            createStdinIterator(gp);
        }
    } else {
        createStdinIterator(gp);
    }

    printf("[");

    /* iterate over all graphs in the database */
    while ((g = iterateFile())) {

        // list handling for graphs
        if (isFirstGraph) {
            isFirstGraph = 0;
        } else {
            printf(",");
        }

        /* if there was an error reading some graph the returned n will be -1 */
        if (g->n != -1) {
            char isOp = 1;
            char firstCC = 1;
            printf("\n{\"graph\": %i, \"ccs\": [", g->number);
            struct Graph* connectedComponents = listConnectedComponents(g, gp);
            for (struct Graph* comp=connectedComponents; comp!=NULL; comp=comp->next) {
                if (firstCC) {
                    firstCC = 0;
                    putc('{', stdout);
                } else {
                    printf(", {");
                }

                if (comp->m > 0) {
                    int* originalIDs = malloc(comp->n * sizeof(int));
                    for (int i=0; i<comp->n; ++i) {
                        originalIDs[i] = comp->vertices[i]->lowPoint;
                        comp->vertices[i]->lowPoint = 0;
                    }
                    
                    struct ShallowGraph* biconnectedComponents = listBiconnectedComponents(comp, sgp);
                    char isOPComp = listHamiltonianCycles(biconnectedComponents, extendToHamiltonianBlocks, originalIDs, gp, sgp);
                    isOp = isOp && isOPComp;

                    if (shortcutting || spiderWeb) {
                        struct BBTree* bbTree = createFancyBlockAndBridgeTree(biconnectedComponents, comp, &originalIDs, gp, sgp);
                        
                        printBlockVertices(bbTree, originalIDs);
                        printBBTreeEdges(bbTree);
                        
                        if (shortcutting) {
                            addShortcutEdges(bbTree, 0);
                        } 
                        if (spiderWeb) {
                            addSpiderWebEdges(bbTree, sgp);
                        }
                        dumpFancyBBTree(gp, sgp, bbTree);
                    } else {
                        /* cleanup */
                        dumpShallowGraphCycle(sgp, biconnectedComponents);
                    }
                    free(originalIDs);
                } else {
                    printf("\"hamiltonianCycles\": {}, \"isOuterplanar\": true");
                    if (shortcutting || spiderWeb) {
                        printf(", \"blocks\": {}, \"CATree\": []");
                        if (shortcutting) {
                            printf(", \"shortcutEdges\": []");
                        }
                        if (spiderWeb) {
                            printf(", \"spiderweb\": {}");

                        }
                    }
                }
                putc('}', stdout);
            }
            dumpGraphList(gp, connectedComponents);
            putc(']', stdout);
            if (isOp) {
                printf(", \"isOuterplanar\": true}");
            } else {
                printf(", \"isOuterplanar\": false}");
            }
        } 

        /* garbage collection */
        dumpGraph(gp, g);
    }

    printf("\n]\n");

    /* global garbage collection */
    destroyFileIterator();
    freeGraphPool(gp);
    freeShallowGraphPool(sgp);
    freeListPool(lp);
    freeVertexPool(vp);

    return EXIT_SUCCESS;
}

// Assembly:
subq $0x98, %rsp
movl $0x0, 0x94(%rsp)
movl %edi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq $0x0, 0x60(%rsp)
movb $0x0, 0x5f(%rsp)
movb $0x0, 0x5e(%rsp)
movb $0x0, 0x5d(%rsp)
movb $0x1, 0x5c(%rsp)
leaq 0x25d5(%rip), %rax      # 0x3671a
movq %rax, 0x50(%rsp)
movl 0x90(%rsp), %edi
movq 0x88(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x11c0
movl %eax, 0x58(%rsp)
cmpl $-0x1, 0x58(%rsp)
je 0x3420b
movl 0x58(%rsp), %eax
movl %eax, 0x4(%rsp)
subl $0x3f, %eax
je 0x341d7
jmp 0x34181
movl 0x4(%rsp), %eax
subl $0x68, %eax
je 0x341ad
jmp 0x3418c
movl 0x4(%rsp), %eax
subl $0x6c, %eax
je 0x341c2
jmp 0x34197
movl 0x4(%rsp), %eax
subl $0x73, %eax
je 0x341d0
jmp 0x341a2
movl 0x4(%rsp), %eax
subl $0x77, %eax
je 0x341c9
jmp 0x341e7
callq 0x33370
movl $0x0, 0x94(%rsp)
jmp 0x3464f
movb $0x1, 0x5f(%rsp)
jmp 0x341e7
movb $0x1, 0x5e(%rsp)
jmp 0x341e7
movb $0x1, 0x5d(%rsp)
jmp 0x341e7
movl $0x1, 0x94(%rsp)
jmp 0x3464f
jmp 0x341e9
movl 0x90(%rsp), %edi
movq 0x88(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x11c0
movl %eax, 0x58(%rsp)
jmp 0x34167
movl $0x2710, %edi           # imm = 0x2710
callq 0x1f160
movq %rax, 0x80(%rsp)
movl $0x2710, %edi           # imm = 0x2710
callq 0x1f4f0
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rsi
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1fcb0
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl $0x64, %edi
callq 0x1f860
movq %rax, 0x68(%rsp)
movq 0x9d72(%rip), %rax      # 0x3dfd8
movl (%rax), %eax
cmpl 0x90(%rsp), %eax
jge 0x342bf
movq 0x88(%rsp), %rax
movq 0x9d58(%rip), %rcx      # 0x3dfd8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x2487(%rip), %rsi      # 0x3671f
callq 0x1120
cmpl $0x0, %eax
je 0x342b3
movq 0x48(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x13d90
jmp 0x342bd
movq 0x68(%rsp), %rdi
callq 0x13df0
jmp 0x342c9
movq 0x68(%rsp), %rdi
callq 0x13df0
leaq 0x2448(%rip), %rdi      # 0x36718
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x13f30
movq %rax, 0x60(%rsp)
cmpq $0x0, %rax
je 0x34604
cmpb $0x0, 0x5c(%rsp)
je 0x342fb
movb $0x0, 0x5c(%rsp)
jmp 0x34309
leaq 0x241f(%rip), %rdi      # 0x36721
movb $0x0, %al
callq 0x1090
movq 0x60(%rsp), %rax
cmpl $-0x1, (%rax)
je 0x345f0
movb $0x1, 0x47(%rsp)
movb $0x1, 0x46(%rsp)
movq 0x60(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0x23f3(%rip), %rdi      # 0x36723
movb $0x0, %al
callq 0x1090
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x10ab0
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x345a6
cmpb $0x0, 0x46(%rsp)
je 0x34383
movb $0x0, 0x46(%rsp)
movq 0x9c54(%rip), %rax      # 0x3dfc8
movq (%rax), %rsi
movl $0x7b, %edi
callq 0x1110
jmp 0x34391
leaq 0x23b1(%rip), %rdi      # 0x3673b
movb $0x0, %al
callq 0x1090
movq 0x30(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x34521
movq 0x30(%rsp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x34413
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x20(%rax), %edx
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x20(%rax)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x343be
movq 0x30(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x10700
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movb 0x5f(%rsp), %al
movq 0x28(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movsbl %al, %esi
callq 0x33720
movb %al, 0x17(%rsp)
movsbl 0x47(%rsp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x3(%rsp)
je 0x3446a
movsbl 0x17(%rsp), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, 0x47(%rsp)
movsbl 0x5d(%rsp), %eax
cmpl $0x0, %eax
jne 0x3448b
movsbl 0x5e(%rsp), %eax
cmpl $0x0, %eax
je 0x34506
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
leaq 0x28(%rsp), %rdx
callq 0x25a20
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x33f10
movq 0x8(%rsp), %rdi
callq 0x33e50
cmpb $0x0, 0x5d(%rsp)
je 0x344da
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x33cf0
cmpb $0x0, 0x5e(%rsp)
je 0x344f0
movq 0x8(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x33a80
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x24da0
jmp 0x34515
movq 0x70(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x20000
movq 0x28(%rsp), %rdi
callq 0x1030
jmp 0x3457f
leaq 0x2217(%rip), %rdi      # 0x3673f
movb $0x0, %al
callq 0x1090
movsbl 0x5d(%rsp), %eax
cmpl $0x0, %eax
jne 0x34543
movsbl 0x5e(%rsp), %eax
cmpl $0x0, %eax
je 0x3457d
leaq 0x2224(%rip), %rdi      # 0x3676e
movb $0x0, %al
callq 0x1090
cmpb $0x0, 0x5d(%rsp)
je 0x34566
leaq 0x222c(%rip), %rdi      # 0x3678b
movb $0x0, %al
callq 0x1090
cmpb $0x0, 0x5e(%rsp)
je 0x3457b
leaq 0x222d(%rip), %rdi      # 0x367a1
movb $0x0, %al
callq 0x1090
jmp 0x3457d
jmp 0x3457f
movq 0x9a42(%rip), %rax      # 0x3dfc8
movq (%rax), %rsi
movl $0x7d, %edi
callq 0x1110
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x34355
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fc60
movq 0x9a0c(%rip), %rax      # 0x3dfc8
movq (%rax), %rsi
movl $0x5d, %edi
callq 0x1110
cmpb $0x0, 0x47(%rsp)
je 0x345e0
leaq 0x21dc(%rip), %rdi      # 0x367b3
movb $0x0, %al
callq 0x1090
jmp 0x345ee
leaq 0x21e5(%rip), %rdi      # 0x367cc
movb $0x0, %al
callq 0x1090
jmp 0x345f0
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x1fb30
jmp 0x342d7
leaq 0x21db(%rip), %rdi      # 0x367e6
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x13e20
movq 0x68(%rsp), %rdi
callq 0x1f9b0
movq 0x70(%rsp), %rdi
callq 0x1fde0
movq 0x80(%rsp), %rdi
callq 0x1f280
movq 0x78(%rsp), %rdi
callq 0x1f610
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq