// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x1e23(%rip), %r15      # 0x1e670
movl $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11d0
cmpl $-0x1, %eax
je 0x1c8b2
cmpl $0x3f, %eax
je 0x1c91e
cmpl $0x77, %eax
je 0x1c899
cmpl $0x6c, %eax
je 0x1c8a1
cmpl $0x73, %eax
je 0x1c889
cmpl $0x68, %eax
jne 0x1c858
jmp 0x1c8a6
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x1c858
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x1c858
movb $0x1, %r14b
jmp 0x1c858
callq 0x1c058
xorl %ebx, %ebx
jmp 0x1cbe3
movl $0x2710, %edi           # imm = 0x2710
callq 0x11240
movq %rax, %r12
movl $0x2710, %edi           # imm = 0x2710
callq 0x113de
movq %rax, %r13
movl $0x3e8, %edi            # imm = 0x3E8
movq %r12, %rsi
callq 0x1171c
movq %rax, %r15
pushq $0x64
popq %rdi
movq %r13, 0x28(%rsp)
movq %r13, %rsi
movq %r12, 0x30(%rsp)
movq %r12, %rdx
callq 0x1153c
movq %rax, %r12
movq 0xd6da(%rip), %rax      # 0x29fd8
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x1c926
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x1c914
cmpb $0x0, 0x1(%rdi)
je 0x1c926
movq %r12, %rsi
callq 0xab15
jmp 0x1c92e
pushq $0x1
popq %rbx
jmp 0x1cbe3
movq %r12, %rdi
callq 0xab62
pushq $0x5b
popq %rdi
callq 0x1040
cmpb $0x0, 0x8(%rsp)
setne %al
movl 0x4(%rsp), %ecx
orb %al, %cl
movl %ecx, 0x4(%rsp)
xorl %ebx, %ebx
movq 0xd677(%rip), %rbp      # 0x29fc8
movsbl %r14b, %eax
movl %eax, 0x24(%rsp)
movq %r12, 0x18(%rsp)
xorl %eax, %eax
callq 0xac6e
testq %rax, %rax
je 0x1cbaa
movq %rax, %r14
testb $0x1, %bl
je 0x1c97e
pushq $0x2c
popq %rdi
callq 0x1040
cmpl $-0x1, (%r14)
je 0x1cb98
movl 0x8(%r14), %esi
xorl %ebx, %ebx
leaq 0x1ce0(%rip), %rdi      # 0x1e675
xorl %eax, %eax
callq 0x10b0
movq %r14, 0x40(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x8ea8
movq %rax, %r13
movb $0x1, %r14b
movq %rax, 0x38(%rsp)
testq %r13, %r13
je 0x1cb59
testb $0x1, %bl
je 0x1c9d5
leaq 0x1cc1(%rip), %rdi      # 0x1e68d
xorl %eax, %eax
callq 0x10b0
jmp 0x1c9e1
movq (%rbp), %rsi
pushq $0x7b
popq %rdi
callq 0x1120
cmpl $0x0, 0x4(%r13)
jle 0x1cad1
movslq (%r13), %rbx
movq %rbx, %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movslq %ebx, %rdx
cmpq %rdx, %rcx
jge 0x1ca26
movq 0x10(%r13), %rdx
movq (%rdx,%rcx,8), %rdx
movl 0x20(%rdx), %esi
movl %esi, (%rax,%rcx,4)
andl $0x0, 0x20(%rdx)
incq %rcx
movl (%r13), %ebx
jmp 0x1ca03
movq %r13, %rdi
movq %r15, %rsi
callq 0x8ccd
movq %rax, %rbx
movq 0x10(%rsp), %rdx
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl %r14d, %ebp
movq 0x18(%rsp), %r14
movq %r14, %rcx
movq %r15, %r8
callq 0x1c1fc
testb %bpl, %bpl
setne %r12b
testb %al, %al
setne %bpl
testb $0x1, 0x4(%rsp)
je 0x1cb20
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x14a4f
movq %rax, %rbx
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x1c6c9
movq %rbx, %rdi
callq 0x1c66b
testb $0x1, 0xc(%rsp)
jne 0x1caaa
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1c5af
cmpb $0x0, 0x8(%rsp)
movl %r12d, %r14d
je 0x1cabf
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c45f
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1442c
jmp 0x1cb2e
leaq 0x1bb9(%rip), %rdi      # 0x1e691
xorl %eax, %eax
callq 0x10b0
testb $0x1, 0x4(%rsp)
je 0x1cb42
leaq 0x1bd3(%rip), %rdi      # 0x1e6c0
xorl %eax, %eax
callq 0x10b0
testb $0x1, 0xc(%rsp)
jne 0x1cb09
leaq 0x1bdb(%rip), %rdi      # 0x1e6dd
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0x8(%rsp)
je 0x1cb42
leaq 0x1bdc(%rip), %rdi      # 0x1e6f3
xorl %eax, %eax
callq 0x10b0
jmp 0x1cb42
movq %r15, %rdi
movq %rbx, %rsi
callq 0x11888
movl %r12d, %r14d
andb %bpl, %r14b
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0xd486(%rip), %rbp      # 0x29fc8
movq (%rbp), %rsi
pushq $0x7d
popq %rdi
callq 0x1120
movq 0x18(%r13), %r13
movb $0x1, %bl
jmp 0x1c9b7
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq 0x38(%rsp), %rsi
callq 0x116ef
movq (%rbp), %rsi
pushq $0x5d
popq %rdi
callq 0x1120
testb %r14b, %r14b
leaq 0x1b84(%rip), %rdi      # 0x1e705
leaq 0x1b96(%rip), %rax      # 0x1e71e
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x10b0
movq 0x40(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x1166e
movb $0x1, %bl
jmp 0x1c95e
leaq 0x1b87(%rip), %rdi      # 0x1e738
callq 0x1070
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xab7f
movq %r12, %rdi
callq 0x115c8
movq %r15, %rdi
callq 0x11798
movq 0x30(%rsp), %rdi
callq 0x112b6
movq 0x28(%rsp), %rdi
callq 0x11454
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq