// File: /workspace/github_cpp_makefile_star2_O2/wenleix[P]EdgePPR/src/ParamGraph.cpp
// Function: ParamGraph::ReadTextFile(_IO_FILE*)
ParamGraph* ParamGraph::ReadTextFile(FILE* txtFile) {
	const int MaxLineLen = 10000;
	char lineBuf[MaxLineLen];

    timeval start, end;
    gettimeofday(&start, NULL);

    ParamGraph *g = new ParamGraph();
	int numRead;
    numRead = fscanf(txtFile, "%d%d", &g->numVertex, &g->numEdge);
    assert(numRead == 2);

    fprintf(stdout, "INFO: # Vertex: %d, # Edge: %d\n", g->numVertex, g->numEdge);

    g->vertexList = new ParamVertex[g->numVertex];
	for (int i = 0; i < g->numVertex; i++)
		g->vertexList[i].inDeg = 0;
	g->edgeList = new ParamEdge[g->numEdge];

    int currentOffset = 0;
    for (int i = 0; i < g->numVertex; i++) {
        int vtxID, vtxType, outDeg;
        numRead = fscanf(txtFile, "%d%d%d ", &vtxID, &vtxType, &outDeg);
        assert(numRead == 3);
        assert(vtxID == i);
        assert(currentOffset + outDeg <= g->numEdge);

        char* fgetsRet = fgets(lineBuf, MaxLineLen, txtFile);
        assert(fgetsRet != NULL);
        lineBuf[strlen(lineBuf) - 1] = 0;   //  Delete the last '\n'
        g->vertexList[i].vertexID = i;
        g->vertexList[i].outDeg = outDeg;
        g->vertexList[i].SetVType(vtxType);
        g->vertexList[i].name = string(lineBuf);
        for (int j = 0; j < ParamGraph_NumEdgeTypes; j++)
        	g->vertexList[i].outEdgeTypeCount[j] = 0;

        ParamEdge *edgeStart = g->edgeList + currentOffset;
        for (int j = 0; j < outDeg; j++) {
        	int dstID, edgeType;
        	numRead = fscanf(txtFile, "%d%d", &dstID, &edgeType);
            assert(numRead == 2);
            edgeStart[j].dstId = dstID;
            edgeStart[j].SetEType(edgeType);
            g->vertexList[i].outEdgeTypeCount[edgeType]++;	//	Update the edge type count
        }

        //  Check self-loop and update inDeg
        for (int j = 0; j < outDeg; j++) {
			int dstID = edgeStart[j].dstId;
			if (i == dstID) {
				fprintf(stderr, "Self-loop: %d.\n", i);
			}
            assert(i != dstID);
            g->vertexList[dstID].inDeg++;
		}

        g->vertexList[i].outEdge = edgeStart;
        currentOffset += outDeg;
    }

    assert(currentOffset == g->numEdge);

    gettimeofday(&end, NULL);

    double elapse_ms = (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_usec - start.tv_usec) / 1000.0;
    fprintf(stdout, "INFO: Graph load done, time elapsed: %.2f sec.\n", elapse_ms / 1000.0);
	fflush(stdout);

	return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2788, %rsp           # imm = 0x2788
movq %rdi, %r14
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2230
pushq $0x18
popq %rdi
callq 0x2150
movq %rax, %r12
orq $-0x1, (%rax)
leaq 0x4(%rax), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x2716(%rip), %rsi      # 0x528b
movq %r14, %rdi
movq %rax, %rdx
movq %rcx, 0x28(%rsp)
xorl %eax, %eax
callq 0x2290
cmpl $0x2, %eax
jne 0x2f62
movq %r12, %rbx
addq $0x8, %rbx
movq 0x542a(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
movl (%r12), %edx
movl 0x4(%r12), %ecx
leaq 0x2720(%rip), %rsi      # 0x52d1
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x21f0
movq %r12, 0x18(%rsp)
movslq (%r12), %r12
pushq $0x60
popq %rcx
movq %r12, %rax
mulq %rcx
seto %cl
orq $0x8, %rax
pushq $-0x1
popq %r13
testb %cl, %cl
cmovneq %r13, %rax
movq %rax, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %r12, (%rax)
testq %r12, %r12
je 0x2c10
leaq 0x20(%rax), %rdx
imulq $0x60, %r12, %rsi
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb $0x0, (%rdx)
addq $0x60, %rdx
addq $-0x60, %rsi
jne 0x2bfa
movq %rcx, (%rbx)
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
imulq $0x60, %rcx, %rcx
cmpq %r15, %rcx
je 0x2c34
andl $0x0, 0x34(%rax,%r15)
addq $0x60, %r15
jmp 0x2c23
movq 0x18(%rsp), %rcx
movslq 0x4(%rcx), %rax
movq %rax, %rdi
shlq $0x4, %rdi
testq %rax, %rax
cmovsq %r13, %rdi
movq %rcx, %r13
callq 0x2030
movq %rax, 0x10(%r13)
pushq $0x40
popq %rax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movslq %r12d, %rax
cmpq %rax, %rbp
jge 0x2e29
movq %r14, %rdi
leaq 0x2677(%rip), %rsi      # 0x52f1
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0xc(%rsp), %r8
xorl %eax, %eax
callq 0x2290
cmpl $0x3, %eax
jne 0x2efe
movl 0x24(%rsp), %eax
cmpq %rax, %rbp
leaq 0x70(%rsp), %r12
jne 0x2f49
movl 0xc(%rsp), %eax
addl %r15d, %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jg 0x2f17
movl %r15d, 0x14(%rsp)
movq %r12, %rdi
movl $0x2710, %esi           # imm = 0x2710
movq %r14, %rdx
callq 0x2220
testq %rax, %rax
je 0x2f30
movq %r12, %rdi
callq 0x20a0
movb $0x0, -0x1(%rax,%r12)
movq (%rbx), %rax
imulq $0x60, %rbp, %r15
leaq (%rax,%r15), %rdi
movl %ebp, (%rax,%r15)
movl 0xc(%rsp), %ecx
movl %ecx, 0x30(%rax,%r15)
movl 0x20(%rsp), %esi
callq 0x2ae4
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
callq 0x306a
movq (%rbx), %rax
leaq (%rax,%r15), %rdi
addq $0x8, %rdi
movq %r13, %rsi
callq 0x21b0
movq %r13, %rdi
callq 0x20b0
movq (%rbx), %rax
movq 0x30(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
movq 0x18(%rsp), %r12
cmpq $0x7, %rdx
je 0x2d5d
andl $0x0, (%rcx,%rdx,4)
incq %rdx
jmp 0x2d4e
movslq 0x14(%rsp), %rcx
shlq $0x4, %rcx
addq 0x10(%r12), %rcx
movq %rcx, 0x38(%rsp)
movq %rcx, %r12
xorl %r13d, %r13d
movslq 0xc(%rsp), %rcx
cmpq %rcx, %r13
jge 0x2dd1
movq %r14, %rdi
leaq 0x2501(%rip), %rsi      # 0x528b
leaq 0x50(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x2290
cmpl $0x2, %eax
jne 0x2eae
movl 0x50(%rsp), %eax
movl %eax, (%r12)
movl 0x10(%rsp), %esi
movq %r12, %rdi
callq 0x2b0c
movq (%rbx), %rax
movslq 0x10(%rsp), %rcx
leaq (%rax,%r15), %rdx
incl 0x40(%rdx,%rcx,4)
incq %r13
addq $0x10, %r12
jmp 0x2d76
movq 0x38(%rsp), %r8
movq %r8, %rdx
xorl %esi, %esi
movq 0x18(%rsp), %r13
movslq %ecx, %rdi
cmpq %rdi, %rsi
jge 0x2e0b
movl (%rdx), %ecx
cmpq %rcx, %rbp
je 0x2ec7
movslq %ecx, %rcx
imulq $0x60, %rcx, %rcx
incl 0x2c(%rax,%rcx)
incq %rsi
movl 0xc(%rsp), %ecx
addq $0x10, %rdx
jmp 0x2de0
movq %r8, 0x38(%rax,%r15)
addl 0x14(%rsp), %ecx
incq %rbp
movl (%r13), %r12d
addq $0x60, 0x30(%rsp)
movl %ecx, %r15d
jmp 0x2c64
movq 0x28(%rsp), %rax
cmpl (%rax), %r15d
jne 0x2f7e
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2230
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq 0x40(%rsp), %rax
cvtsi2sd %rax, %xmm0
subq 0x48(%rsp), %rcx
cvtsi2sd %rcx, %xmm1
movsd 0x235f(%rip), %xmm2     # 0x51c8
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x514c(%rip), %rbx      # 0x7fc8
movq (%rbx), %rdi
divsd %xmm2, %xmm0
leaq 0x24f4(%rip), %rsi      # 0x537e
movb $0x1, %al
callq 0x21f0
movq (%rbx), %rdi
callq 0x2190
movq %r13, %rax
addq $0x2788, %rsp           # imm = 0x2788
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23db(%rip), %rdi      # 0x5290
leaq 0x234a(%rip), %rsi      # 0x5206
leaq 0x23da(%rip), %rcx      # 0x529d
pushq $0x51
jmp 0x2ef8
movq 0x5112(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
leaq 0x246f(%rip), %rsi      # 0x5347
movl %ebp, %edx
xorl %eax, %eax
callq 0x21f0
leaq 0x246f(%rip), %rdi      # 0x5357
leaq 0x2317(%rip), %rsi      # 0x5206
leaq 0x23a7(%rip), %rcx      # 0x529d
pushq $0x5d
popq %rdx
callq 0x20e0
leaq 0x23f4(%rip), %rdi      # 0x52f9
leaq 0x22fa(%rip), %rsi      # 0x5206
leaq 0x238a(%rip), %rcx      # 0x529d
pushq $0x3f
jmp 0x2ef8
leaq 0x23f3(%rip), %rdi      # 0x5311
leaq 0x22e1(%rip), %rsi      # 0x5206
leaq 0x2371(%rip), %rcx      # 0x529d
pushq $0x41
jmp 0x2ef8
leaq 0x23ff(%rip), %rdi      # 0x5336
leaq 0x22c8(%rip), %rsi      # 0x5206
leaq 0x2358(%rip), %rcx      # 0x529d
pushq $0x44
jmp 0x2ef8
leaq 0x23b6(%rip), %rdi      # 0x5306
leaq 0x22af(%rip), %rsi      # 0x5206
leaq 0x233f(%rip), %rcx      # 0x529d
pushq $0x40
jmp 0x2ef8
leaq 0x2327(%rip), %rdi      # 0x5290
leaq 0x2296(%rip), %rsi      # 0x5206
leaq 0x2326(%rip), %rcx      # 0x529d
pushq $0x32
jmp 0x2ef8
leaq 0x23dd(%rip), %rdi      # 0x5362
leaq 0x227a(%rip), %rsi      # 0x5206
leaq 0x230a(%rip), %rcx      # 0x529d
pushq $0x65
jmp 0x2ef8