// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x2220
movl $0x18, %edi
callq 0x2140
movq %rax, %rbp
movq $-0x1, (%rax)
leaq 0x4(%rax), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x2175(%rip), %rsi      # 0x528b
movq %rbx, %r13
movq %rbx, %rdi
movq %rax, %rdx
movq %rcx, 0x20(%rsp)
xorl %eax, %eax
callq 0x2280
cmpl $0x2, %eax
jne 0x358d
movq %rbp, %rbx
addq $0x8, %rbx
movq 0x4e86(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
leaq 0x217f(%rip), %rsi      # 0x52d1
xorl %eax, %eax
callq 0x21e0
movslq (%rbp), %r15
movl $0x60, %ecx
movq %r15, %rax
mulq %rcx
seto %cl
orq $0x8, %rax
movq $-0x1, %rdi
testb %cl, %cl
cmoveq %rax, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %r15, (%rax)
testq %r15, %r15
je 0x31b5
leaq 0x20(%rax), %rdx
movq %r15, %rsi
shlq $0x5, %rsi
leaq (%rsi,%rsi,2), %rsi
movq %rdx, -0x10(%rdx)
movq $0x0, -0x8(%rdx)
movb $0x0, (%rdx)
addq $0x60, %rdx
addq $-0x60, %rsi
jne 0x319c
movq %rcx, (%rbx)
testl %r15d, %r15d
jle 0x31d8
shlq $0x5, %r15
leaq (%r15,%r15,2), %rcx
xorl %edx, %edx
movl $0x0, 0x34(%rax,%rdx)
addq $0x60, %rdx
cmpq %rdx, %rcx
jne 0x31c7
movslq 0x4(%rbp), %rax
movq %rax, %rcx
shlq $0x4, %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, 0x10(%rbp)
cmpl $0x0, (%rbp)
jle 0x3423
leaq 0x70(%rsp), %r14
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %rbp, 0x58(%rsp)
movq %r13, %rdi
leaq 0x20d3(%rip), %rsi      # 0x52f1
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0xc(%rsp), %r8
xorl %eax, %eax
callq 0x2280
cmpl $0x3, %eax
jne 0x356e
movl 0x1c(%rsp), %eax
cmpq %rax, %r12
jne 0x354f
movl 0xc(%rsp), %eax
addl %r15d, %eax
movq 0x20(%rsp), %rcx
cmpl (%rcx), %eax
jg 0x34f2
movl %r15d, 0x10(%rsp)
movq %r14, %rdi
movl $0x2710, %esi           # imm = 0x2710
movq %r13, %rdx
callq 0x2210
testq %rax, %rax
je 0x3511
movq %r14, %rdi
callq 0x20a0
movb $0x0, -0x1(%rax,%r14)
movq (%rbx), %rax
leaq (%r12,%r12,2), %r15
shlq $0x5, %r15
movl %r12d, (%rax,%r15)
movl 0xc(%rsp), %ecx
movl %ecx, 0x30(%rax,%r15)
movl 0x18(%rsp), %ecx
cmpl $0x4, %ecx
jae 0x3530
addq %r15, %rax
movl %ecx, 0x28(%rax)
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0x20a0
leaq (%rsp,%rax), %rdx
addq $0x70, %rdx
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x36b2
movq (%rbx), %rax
leaq (%rax,%r15), %rdi
addq $0x8, %rdi
leaq 0x38(%rsp), %rsi
callq 0x21a0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x330d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
movq %r12, %rax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rax
movq 0x8(%rbp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x4c(%rcx,%rax)
movups %xmm0, 0x40(%rcx,%rax)
movq 0x10(%rbp), %rax
movq %rax, 0x30(%rsp)
movslq 0x10(%rsp), %rax
shlq $0x4, %rax
movq %rax, 0x28(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x33b3
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx), %rbp
addq $0x4, %rbp
xorl %r14d, %r14d
movq %r13, %rdi
leaq 0x1f25(%rip), %rsi      # 0x528b
leaq 0x38(%rsp), %rdx
leaq 0x14(%rsp), %rcx
xorl %eax, %eax
callq 0x2280
cmpl $0x2, %eax
jne 0x34ac
movl 0x38(%rsp), %eax
movl %eax, -0x4(%rbp)
movl 0x14(%rsp), %eax
cmpq $0x7, %rax
jae 0x34cb
movl %eax, (%rbp)
movq (%rbx), %rcx
addq %r15, %rcx
incl 0x40(%rcx,%rax,4)
incq %r14
movslq 0xc(%rsp), %rax
addq $0x10, %rbp
cmpq %rax, %r14
jl 0x335c
movq 0x30(%rsp), %rdi
addq 0x28(%rsp), %rdi
movl 0xc(%rsp), %eax
testl %eax, %eax
movq 0x58(%rsp), %rbp
jle 0x33fc
movq %rdi, %rcx
xorl %edx, %edx
movl (%rcx), %eax
cmpq %rax, %r12
je 0x34ea
cltq
movq (%rbx), %rsi
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
incl 0x2c(%rsi,%rax)
incq %rdx
movslq 0xc(%rsp), %rax
addq $0x10, %rcx
cmpq %rax, %rdx
jl 0x33cf
movq 0x8(%rbp), %rcx
movq %rdi, 0x38(%rcx,%r15)
addl 0x10(%rsp), %eax
incq %r12
movslq (%rbp), %rcx
movl %eax, %r15d
cmpq %rcx, %r12
leaq 0x70(%rsp), %r14
jl 0x3214
jmp 0x3425
xorl %eax, %eax
movq 0x20(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x35ac
leaq 0x38(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2220
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq 0x60(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x68(%rsp), %rcx
cvtsi2sd %rcx, %xmm1
movsd 0x1d61(%rip), %xmm2     # 0x51c8
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x4b4e(%rip), %rbx      # 0x7fc8
movq (%rbx), %rdi
divsd %xmm2, %xmm0
leaq 0x1ef6(%rip), %rsi      # 0x537e
movb $0x1, %al
callq 0x21e0
movq (%rbx), %rdi
callq 0x2180
movq %rbp, %rax
addq $0x2788, %rsp           # imm = 0x2788
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ddd(%rip), %rdi      # 0x5290
leaq 0x1d4c(%rip), %rsi      # 0x5206
leaq 0x1ddc(%rip), %rcx      # 0x529d
movl $0x51, %edx
callq 0x20d0
leaq 0x1d67(%rip), %rdi      # 0x5239
leaq 0x1d2d(%rip), %rsi      # 0x5206
leaq 0x1d8d(%rip), %rcx      # 0x526d
movl $0x1b, %edx
callq 0x20d0
movq %r12, %rdi
callq 0x22ef
leaq 0x1e18(%rip), %rdi      # 0x5311
leaq 0x1d06(%rip), %rsi      # 0x5206
leaq 0x1d96(%rip), %rcx      # 0x529d
movl $0x41, %edx
callq 0x20d0
leaq 0x1e1e(%rip), %rdi      # 0x5336
leaq 0x1ce7(%rip), %rsi      # 0x5206
leaq 0x1d77(%rip), %rcx      # 0x529d
movl $0x44, %edx
callq 0x20d0
leaq 0x1c99(%rip), %rdi      # 0x51d0
leaq 0x1cc8(%rip), %rsi      # 0x5206
leaq 0x1cd4(%rip), %rcx      # 0x5219
movl $0x16, %edx
callq 0x20d0
leaq 0x1db0(%rip), %rdi      # 0x5306
leaq 0x1ca9(%rip), %rsi      # 0x5206
leaq 0x1d39(%rip), %rcx      # 0x529d
movl $0x40, %edx
callq 0x20d0
leaq 0x1d84(%rip), %rdi      # 0x52f9
leaq 0x1c8a(%rip), %rsi      # 0x5206
leaq 0x1d1a(%rip), %rcx      # 0x529d
movl $0x3f, %edx
callq 0x20d0
leaq 0x1cfc(%rip), %rdi      # 0x5290
leaq 0x1c6b(%rip), %rsi      # 0x5206
leaq 0x1cfb(%rip), %rcx      # 0x529d
movl $0x32, %edx
callq 0x20d0
leaq 0x1daf(%rip), %rdi      # 0x5362
leaq 0x1c4c(%rip), %rsi      # 0x5206
leaq 0x1cdc(%rip), %rcx      # 0x529d
movl $0x65, %edx
callq 0x20d0
nop