// File: /workspace/github_c_makefile_star2_O3/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, %r13d
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x2081(%rip), %r14      # 0x216d0
movl $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movl %r13d, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x11e0
cmpl $0x6b, %eax
jg 0x1f684
cmpl $-0x1, %eax
je 0x1f6b0
cmpl $0x3f, %eax
je 0x1f751
cmpl $0x68, %eax
jne 0x1f659
jmp 0x1f71f
cmpl $0x6c, %eax
je 0x1f69b
cmpl $0x73, %eax
je 0x1f6a0
cmpl $0x77, %eax
jne 0x1f659
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x1f659
movb $0x1, %bpl
jmp 0x1f659
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x1f659
movl $0x2710, %edi           # imm = 0x2710
callq 0x14060
movq %rax, %r14
movl $0x2710, %edi           # imm = 0x2710
callq 0x142ed
movq %rax, %r12
movl $0x3e8, %edi            # imm = 0x3E8
movq %r14, %rsi
callq 0x147f6
movq %rax, %r15
movl $0x64, %edi
movq %r12, 0x28(%rsp)
movq %r12, %rsi
movq %r14, 0x30(%rsp)
movq %r14, %rdx
callq 0x1451a
movq %rax, %r14
movq 0xd8da(%rip), %rax      # 0x2cfd8
movslq (%rax), %rax
cmpl %r13d, %eax
jge 0x1f75c
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x1f715
cmpb $0x0, 0x1(%rdi)
je 0x1f75c
movq %r14, %rsi
callq 0xd169
jmp 0x1f764
xorl %r12d, %r12d
leaq 0x19b7(%rip), %rbx      # 0x210e0
movq 0xd898(%rip), %r14      # 0x2cfc8
xorl %r15d, %r15d
movzbl (%r15,%rbx), %edi
movq (%r14), %rsi
callq 0x1110
incq %r15
cmpq $0x4a7, %r15            # imm = 0x4A7
jne 0x1f733
jmp 0x1fa4d
movl $0x1, %r12d
jmp 0x1fa4d
movq %r14, %rdi
callq 0xd1b6
movl $0x5b, %edi
callq 0x1040
xorl %eax, %eax
callq 0xd2be
testq %rax, %rax
je 0x1fa13
movq %rax, %rbx
cmpb $0x0, 0x8(%rsp)
setne %al
movl 0x4(%rsp), %ecx
orb %al, %cl
movl %ecx, 0x4(%rsp)
movq 0xd82e(%rip), %r12      # 0x2cfc8
movsbl %bpl, %eax
movl %eax, 0x24(%rsp)
xorl %eax, %eax
movq %r14, 0x18(%rsp)
testb $0x1, %al
je 0x1f7b7
movl $0x2c, %edi
callq 0x1040
cmpl $-0x1, (%rbx)
je 0x1f9f3
movl 0x8(%rbx), %esi
leaq 0x1f0b(%rip), %rdi      # 0x216d5
xorl %eax, %eax
callq 0x10b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb40f
movq %rax, %rsi
testq %rax, %rax
je 0x1f9cf
movq %rbx, 0x40(%rsp)
movb $0x1, %bpl
xorl %eax, %eax
movq %rsi, 0x38(%rsp)
movq %rsi, %r14
testb $0x1, %al
je 0x1f80e
leaq 0x1ee8(%rip), %rdi      # 0x216ed
xorl %eax, %eax
callq 0x10b0
jmp 0x1f81c
movq (%r12), %rsi
movl $0x7b, %edi
callq 0x1130
cmpl $0x0, 0x4(%r14)
jle 0x1f908
movslq (%r14), %rbx
leaq (,%rbx,4), %rdi
callq 0x1190
movq %rax, 0x10(%rsp)
testq %rbx, %rbx
jle 0x1f863
movq 0x10(%r14), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl 0x20(%rsi), %edi
movl %edi, (%rax,%rdx,4)
movl $0x0, 0x20(%rsi)
incq %rdx
movslq (%r14), %rsi
cmpq %rsi, %rdx
jl 0x1f847
movq %r14, %rdi
movq %r15, %rsi
callq 0xb23b
movq %rax, %rbx
movq 0x10(%rsp), %rdx
movq %rax, %rdi
movl 0x24(%rsp), %esi
movq 0x18(%rsp), %r12
movq %r12, %rcx
movq %r15, %r8
callq 0x1ef7c
testb %bpl, %bpl
setne %bpl
testb %al, %al
setne %r13b
testb $0x1, 0x4(%rsp)
je 0x1f957
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x179b6
movq %rax, %rbx
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x1f4af
movq %rbx, %rdi
callq 0x1f44a
testb $0x1, 0xc(%rsp)
jne 0x1f8e4
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f381
cmpb $0x0, 0x8(%rsp)
je 0x1f8f6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1f221
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17328
jmp 0x1f962
leaq 0x1de2(%rip), %rdi      # 0x216f1
xorl %eax, %eax
callq 0x10b0
testb $0x1, 0x4(%rsp)
je 0x1f976
leaq 0x1dfc(%rip), %rdi      # 0x21720
xorl %eax, %eax
callq 0x10b0
testb $0x1, 0xc(%rsp)
jne 0x1f940
leaq 0x1e04(%rip), %rdi      # 0x2173d
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0x8(%rsp)
je 0x1f976
leaq 0x1e05(%rip), %rdi      # 0x21753
xorl %eax, %eax
callq 0x10b0
jmp 0x1f976
movq %r15, %rdi
movq %rbx, %rsi
callq 0x14a56
andb %r13b, %bpl
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0xd652(%rip), %r12      # 0x2cfc8
movq (%r12), %rsi
movl $0x7d, %edi
callq 0x1130
movq 0x18(%r14), %r14
movb $0x1, %al
testq %r14, %r14
jne 0x1f7fa
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x147c9
movq (%r12), %rsi
movl $0x5d, %edi
callq 0x1130
testb %bpl, %bpl
leaq 0x1da8(%rip), %rdi      # 0x21765
leaq 0x1dba(%rip), %rax      # 0x2177e
cmoveq %rax, %rdi
movq 0x40(%rsp), %rbx
jmp 0x1f9ec
movq %r14, %rdi
callq 0x147c9
movq (%r12), %rsi
movl $0x5d, %edi
callq 0x1130
leaq 0x1d79(%rip), %rdi      # 0x21765
xorl %eax, %eax
callq 0x10b0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x14700
xorl %eax, %eax
callq 0xd2be
movq %rax, %rbx
movb $0x1, %al
testq %rbx, %rbx
jne 0x1f7a9
leaq 0x1d7e(%rip), %rdi      # 0x21798
callq 0x1070
xorl %eax, %eax
callq 0xd1d3
movq %r14, %rdi
callq 0x14655
movq %r15, %rdi
callq 0x14935
movq 0x30(%rsp), %rdi
callq 0x14199
movq 0x28(%rsp), %rdi
callq 0x14426
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq