// File: /workspace/github_cpp_makefile_star2_O1/iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::Graph(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool const&)
Graph::Graph(const string &inputFile, const bool &checkIndependentSet) : mapping(false), idToPos(NULL), posToId(NULL) {
    /* Open graph input file */
    FILE *f;
    f = fopen(inputFile.c_str(), "r");
    if (f == NULL) {
        cerr << "Error in opening input file " << inputFile << endl;
        exit(EXIT_FAILURE);
    }
    char buf[MAXLINE];

    /* Skip info lines */
    for (int i = 0 ; i < 3 ; i++) {
        if (fgets(buf, MAXLINE, f) == NULL) {
            cerr << "Error in parsing input file " << inputFile << endl;
            exit(EXIT_FAILURE);
        }
    }

    /* Get total node and edge numbers */
    char *ptr = strstr(buf, "Nodes:");
    uint32_t nodes = atoi(ptr + 7);
    ptr = strstr(buf, "Edges:");
    uint32_t edges = atoi(ptr + 7);
    if (fgets(buf, MAXLINE, f) == NULL) {
        cerr << "Error in parsing input file " << inputFile << endl;
        exit(EXIT_FAILURE);
    }

    try {
        nodeIndex.reserve(nodes);
    }
    catch (const length_error &le) {
        cerr << "NodeIndex length error: " << le.what() << endl;
        exit(EXIT_FAILURE);
    }

    edgeBuffer = new vector<uint32_t>();
    try {
        edgeBuffer->reserve(edges * 2);
    }
    catch (const length_error &le) {
        cerr << "EdgeBuffer length error: " << le.what() << endl;
        exit(EXIT_FAILURE);
    }

    /* Hold reverse direction edges temporarily */
    vector<vector<uint32_t> > reverseEdges(nodes);

    /* Build graph with both edge directions, keep them sorted */
    uint32_t sourceNode, targetNode, previousNode, straightEdges, offset;
    previousNode = NONE;
    straightEdges = 0;
    offset = 0;
    while(fgets(buf, MAXLINE, f) != NULL) {
        parseNodeIDs(buf, &sourceNode, &targetNode);
        if (sourceNode >= nodes || targetNode >= nodes) {
            cerr << "Error: received a node id equal or larger than the total nodes number specified at the beginning of the file" << endl;
            exit(EXIT_FAILURE);
        }
        /* Add smaller nodes than first source node */
        if (previousNode == NONE && sourceNode) {
            this->fill(sourceNode, checkIndependentSet);
        }
        if (previousNode != sourceNode && previousNode != NONE) {
            /* At new source node, add previous nodes' (including those who don't appear as source nodes) smaller neighbors */
            for (uint32_t node = previousNode + 1 ; node <= sourceNode ; node++) {
                uint32_t previousEdges = straightEdges + reverseEdges[node - 1].size();
                nodeIndex.push_back(Graph::NodeInfo(offset, previousEdges));
                if (!previousEdges && !checkIndependentSet) {
                    zeroDegreeNodes.push_back(nodeIndex.size()-1);
                    nodeIndex[nodeIndex.size()-1].removed = true;
                }
                offset += previousEdges;
                edgeBuffer->insert(edgeBuffer->end(), reverseEdges[node].begin(), reverseEdges[node].end());
                straightEdges = 0;
                if (node < sourceNode) {
                    //cout << "in between missing node " << node << endl;
                }
            }
        }
        /* Add source node's bigger neighbors */
        edgeBuffer->push_back(targetNode);
        straightEdges++;
        reverseEdges[targetNode].push_back(sourceNode);
        previousNode = sourceNode;
    }
    /* Add final source node's info */
    uint32_t previousEdges = straightEdges + reverseEdges[previousNode].size();
    nodeIndex.push_back(Graph::NodeInfo(offset, previousEdges));
    if (!previousEdges && !checkIndependentSet) {
        zeroDegreeNodes.push_back(nodeIndex.size()-1);
        nodeIndex[nodeIndex.size()-1].removed = true;
    }
    offset += previousEdges;
    /* Add smaller neighbors of the nodes left that don't appear as source nodes */
    for (uint32_t missingNode = nodeIndex.size() ; missingNode < nodes ; missingNode++) {
        //cout << "end missing node " << missingNode << endl;
        previousEdges = reverseEdges[missingNode].size();
        nodeIndex.push_back(Graph::NodeInfo(offset, previousEdges));
        if (!previousEdges && !checkIndependentSet) {
            zeroDegreeNodes.push_back(nodeIndex.size()-1);
            nodeIndex[nodeIndex.size()-1].removed = true;
        }
        offset += previousEdges;
        edgeBuffer->insert(edgeBuffer->end(), reverseEdges[missingNode].begin(), reverseEdges[missingNode].end());
    }
    nextUnusedId = nodeIndex.size();
    fclose(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
leaq 0x20(%rdi), %rcx
movq %rcx, 0x20(%rsp)
movups %xmm0, 0x20(%rdi)
movq %rax, 0x30(%rdi)
movb $0x0, 0x3c(%rdi)
movq %rdi, (%rsp)
movups %xmm0, 0x40(%rdi)
movq (%rsi), %rdi
leaq 0xf128(%rip), %rsi      # 0x1a596
callq 0x2230
testq %rax, %rax
je 0xba24
movq %rax, %r15
movl $0x3, %ebx
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22e0
testq %rax, %rax
je 0xb9c1
decl %ebx
jne 0xb489
leaq 0xf125(%rip), %rsi      # 0x1a5d2
leaq 0x60(%rsp), %r13
movq %r13, %rdi
callq 0x2050
leaq 0x7(%rax), %rdi
callq 0x22d0
movl %eax, %ebp
leaq 0xf10d(%rip), %rsi      # 0x1a5d9
movq %r13, %rdi
callq 0x2050
leaq 0x7(%rax), %rdi
callq 0x22d0
movl %eax, %r12d
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdx
callq 0x22e0
testq %rax, %rax
je 0xba59
movl %ebp, %ebx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0xc38e
movl %ebp, %r14d
movl $0x18, %edi
callq 0x21e0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq (%rsp), %rcx
movq %rax, 0x18(%rcx)
addl %r12d, %r12d
movq %rax, %rdi
movq %r12, %rsi
callq 0xc44a
leaq 0x40(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %rbx, %rsi
callq 0xcc56
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r15, 0x38(%rsp)
movq %r15, %rdx
callq 0x22e0
testq %rax, %rax
je 0xb7b0
movq %rbx, 0x58(%rsp)
movq %r12, %rbx
xorl %r12d, %r12d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movabsq $0x100000601, %r13      # imm = 0x100000601
xorl %ebp, %ebp
movl %r14d, 0x34(%rsp)
xorl %eax, %eax
leaq 0x18(%rsp), %rdx
xorl %esi, %esi
movzbl (%rbx), %edi
cmpq $0x20, %rdi
ja 0xb5a7
btq %rdi, %r13
jb 0xb5b9
movsbl %dil, %edi
leal (%rsi,%rsi,4), %esi
leal (%rdi,%rsi,2), %esi
addl $-0x30, %esi
incq %rbx
jmp 0xb598
movl %esi, (%rdx)
movzbl (%rbx), %edx
cmpl $0x20, %edx
je 0xb5c8
cmpl $0x9, %edx
jne 0xb5cd
incq %rbx
jmp 0xb5bb
leal 0x1(%rax), %esi
leaq 0x1c(%rsp), %rdx
testl %eax, %eax
movl %esi, %eax
je 0xb596
movl 0x18(%rsp), %eax
cmpl %r14d, %eax
jae 0xb9f6
cmpl %r14d, 0x1c(%rsp)
jae 0xb9f6
cmpl $-0x1, %r15d
setne %cl
testl %eax, %eax
sete %al
orb %cl, %al
jne 0xb616
movq (%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0xbc18
cmpl 0x18(%rsp), %r15d
jae 0xb71b
movl %ebp, %r14d
movl %r15d, %eax
movq 0x40(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq 0x8(%rcx,%rax,8), %rbp
subq (%rcx,%rax,8), %rbp
shrq $0x2, %rbp
addl %r12d, %ebp
movl %r14d, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
movb $0x0, 0x14(%rsp)
movq (%rsp), %r12
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0xb675
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0xc(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%r12)
jmp 0xb682
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
callq 0xe250
testl %ebp, %ebp
jne 0xb6da
movq 0x28(%rsp), %rax
cmpb $0x0, (%rax)
jne 0xb6da
movq 0x8(%r12), %rax
subq (%r12), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
decl %eax
movl %eax, 0xc(%rsp)
movq 0x28(%r12), %rsi
cmpq 0x30(%r12), %rsi
je 0xb6c2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%r12)
jmp 0xb6d1
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0xfbfa
movq 0x8(%r12), %rax
movb $0x1, -0x4(%rax)
leal 0x1(%r15), %ebx
movq 0x18(%r12), %rdi
movq 0x8(%rdi), %rsi
movl %ebx, %eax
movq 0x40(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rdx
movq 0x8(%rcx,%rax,8), %rcx
callq 0xeb0c
addl %r14d, %ebp
addl $0x2, %r15d
xorl %r12d, %r12d
movl %ebp, %r14d
cmpl 0x18(%rsp), %r15d
movl %ebx, %r15d
jbe 0xb624
movq (%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
movl 0x34(%rsp), %r14d
je 0xb742
movl 0x1c(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xb74c
leaq 0x1c(%rsp), %rdx
callq 0xdeac
movl 0x1c(%rsp), %eax
movq 0x40(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xb777
movl 0x18(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xb781
leaq 0x18(%rsp), %rdx
callq 0xdeac
incl %r12d
movl 0x18(%rsp), %r15d
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x38(%rsp), %rdx
callq 0x22e0
testq %rax, %rax
jne 0xb58f
movq 0x58(%rsp), %rbx
jmp 0xb7bb
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
leaq (%r15,%r15,2), %rcx
movq 0x8(%rax,%rcx,8), %r15
subq (%rax,%rcx,8), %r15
shrq $0x2, %r15
addl %r12d, %r15d
movl %ebp, 0xc(%rsp)
movl %r15d, 0x10(%rsp)
movb $0x0, 0x14(%rsp)
movq (%rsp), %r12
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0xb809
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0xc(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%r12)
jmp 0xb816
leaq 0xc(%rsp), %rdx
movq %r12, %rdi
callq 0xe250
testl %r15d, %r15d
jne 0xb86f
movq 0x28(%rsp), %rax
cmpb $0x0, (%rax)
jne 0xb86f
movq 0x8(%r12), %rax
subq (%r12), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
decl %eax
movl %eax, 0xc(%rsp)
movq 0x28(%r12), %rsi
cmpq 0x30(%r12), %rsi
je 0xb857
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%r12)
jmp 0xb866
leaq 0xc(%rsp), %rdx
movq 0x20(%rsp), %rdi
callq 0xfbfa
movq 0x8(%r12), %rax
movb $0x1, -0x4(%rax)
movq 0x8(%r12), %rcx
subq (%r12), %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpl %eax, %r14d
jbe 0xb983
addl %ebp, %r15d
movl %eax, %eax
leaq (%rax,%rax,2), %rcx
leaq 0x8(,%rcx,8), %r12
subq %rax, %rbx
leaq 0xc(%rsp), %r14
movq %rbx, %rbp
movq 0x40(%rsp), %rax
movq (%rax,%r12), %r13
subq -0x8(%rax,%r12), %r13
shrq $0x2, %r13
movl %r15d, 0xc(%rsp)
movl %r13d, 0x10(%rsp)
movb $0x0, 0x14(%rsp)
movq (%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xb8f4
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0xc(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%rdi)
jmp 0xb8fc
movq %r14, %rdx
callq 0xe250
testl %r13d, %r13d
jne 0xb951
movq 0x28(%rsp), %rax
cmpb $0x0, (%rax)
jne 0xb951
movq (%rsp), %rbx
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
decl %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0xb93c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0xb949
movq 0x20(%rsp), %rdi
movq %r14, %rdx
callq 0xfbfa
movq 0x8(%rbx), %rax
movb $0x1, -0x4(%rax)
movq (%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8(%rdi), %rsi
movq 0x40(%rsp), %rax
movq -0x8(%rax,%r12), %rdx
movq (%rax,%r12), %rcx
callq 0xeb0c
addl %r13d, %r15d
addq $0x18, %r12
movq %rbp, %rbx
decq %rbx
jne 0xb8ac
movq (%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl %eax, 0x38(%rcx)
movq 0x38(%rsp), %rdi
callq 0x21d0
leaq 0x40(%rsp), %rdi
callq 0xccde
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x17628(%rip), %rdi     # 0x22ff0
leaq 0xebe6(%rip), %rsi      # 0x1a5b5
movl $0x1c, %edx
callq 0x2200
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x17609(%rip), %rdi     # 0x22ff0
callq 0x2200
movq %rax, %rdi
callq 0x20b0
jmp 0xba1a
movq 0x175f3(%rip), %rdi     # 0x22ff0
leaq 0xec0f(%rip), %rsi      # 0x1a613
movl $0x6c, %edx
callq 0x2200
movq 0x175db(%rip), %rdi     # 0x22ff0
callq 0x20b0
movl $0x1, %edi
callq 0x2240
movq 0x175c5(%rip), %rdi     # 0x22ff0
leaq 0xeb66(%rip), %rsi      # 0x1a598
movl $0x1c, %edx
callq 0x2200
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x175a6(%rip), %rdi     # 0x22ff0
callq 0x2200
movq %rax, %rdi
callq 0x20b0
jmp 0xba1a
movq 0x17590(%rip), %rdi     # 0x22ff0
leaq 0xeb4e(%rip), %rsi      # 0x1a5b5
movl $0x1c, %edx
callq 0x2200
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x17571(%rip), %rdi     # 0x22ff0
callq 0x2200
movq %rax, %rdi
callq 0x20b0
jmp 0xba1a
jmp 0xbb8b
jmp 0xbb8b
jmp 0xbb80
jmp 0xbb80
movq %rax, %r14
cmpl $0x1, %edx
jne 0xbb83
movq %r14, %rdi
callq 0x2090
movq %rax, %r14
movq 0x17530(%rip), %rdi     # 0x22ff0
leaq 0xeb32(%rip), %rsi      # 0x1a5f9
movl $0x19, %edx
callq 0x2200
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x1750f(%rip), %rdi     # 0x22ff0
movq %rax, %rsi
callq 0x21c0
movq %rax, %rdi
callq 0x20b0
jmp 0xba1a
movq %rax, %r14
callq 0x2300
jmp 0xbb83
movq %rax, %r14
cmpl $0x1, %edx
jne 0xbb83
movq %r14, %rdi
callq 0x2090
movq %rax, %r14
movq 0x174d3(%rip), %rdi     # 0x22ff0
leaq 0xeabc(%rip), %rsi      # 0x1a5e0
movl $0x18, %edx
callq 0x2200
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x174b2(%rip), %rdi     # 0x22ff0
movq %rax, %rsi
callq 0x21c0
movq %rax, %rdi
callq 0x20b0
jmp 0xba1a
movq %rax, %r14
callq 0x2300
jmp 0xbb83
movq %rax, %rdi
callq 0xcc4b
movq %rax, %r14
movq %rbx, %r12
jmp 0xbb8e
jmp 0xbb80
jmp 0xbb77
jmp 0xbb77
jmp 0xbb77
jmp 0xbb8b
movq %rax, %r14
movq (%rsp), %r12
jmp 0xbb8e
movq %rax, %r14
movq (%rsp), %r12
jmp 0xbb98
jmp 0xbb8b
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0xccde
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0xbbaa
callq 0x21a0
movq (%r12), %rdi
testq %rdi, %rdi
je 0xbbb8
callq 0x21a0
movq %r14, %rdi
callq 0x2320