// File: /workspace/github_cpp_makefile_star2_O3/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 $0x2778, %rsp           # imm = 0x2778
movq %rdi, %rbx
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x2220
movl $0x18, %edi
callq 0x2140
movq %rax, %r14
movq $-0x1, (%rax)
leaq 0x4(%rax), %rcx
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rax)
leaq 0x20ff(%rip), %rsi      # 0x52e3
movq %rbx, %rbp
movq %rbx, %rdi
movq %rax, %rdx
movq %rcx, 0x20(%rsp)
xorl %eax, %eax
callq 0x2280
cmpl $0x2, %eax
jne 0x3763
movq %r14, %r13
addq $0x8, %r13
movq 0x4db8(%rip), %r15      # 0x7fc8
movq (%r15), %rdi
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x2108(%rip), %rsi      # 0x5329
xorl %eax, %eax
callq 0x21e0
movslq (%r14), %rbx
movl $0x60, %ecx
movq %rbx, %rax
mulq %rcx
seto %cl
orq $0x8, %rax
movq $-0x1, %rdi
testb %cl, %cl
cmoveq %rax, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %rbx, (%rax)
testq %rbx, %rbx
je 0x33a9
movq %rax, %rdx
addq $0x20, %rdx
movq %rbx, %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 0x3271
movq %rcx, (%r13)
testl %ebx, %ebx
setg %r12b
jle 0x33ad
leal 0x3(%rbx), %ecx
decq %rbx
movq %rbx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
shlq $0x7, %rcx
leaq (%rcx,%rcx,2), %rcx
movdqa 0x1f43(%rip), %xmm1     # 0x5200
movdqa 0x1d4b(%rip), %xmm2     # 0x5010
xorl %edx, %edx
movdqa 0x1d51(%rip), %xmm3     # 0x5020
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x1f31(%rip), %xmm5     # 0x5210
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x331c
movl $0x0, 0x34(%rax,%rdx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x3336
movl $0x0, 0x94(%rax,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0x3379
movl $0x0, 0xf4(%rax,%rdx)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x338f
movl $0x0, 0x154(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x180, %rdx            # imm = 0x180
cmpq %rdx, %rcx
jne 0x32df
jmp 0x33b0
movq %rcx, (%r13)
xorl %r12d, %r12d
movslq 0x4(%r14), %rbx
movq %rbx, %rax
shlq $0x4, %rax
testq %rbx, %rbx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, 0x10(%r14)
testb %r12b, %r12b
je 0x3602
leaq 0x60(%rsp), %rbx
xorl %r12d, %r12d
xorl %ecx, %ecx
movq %r14, 0x18(%rsp)
movl %ecx, %r15d
movq %rbp, %rdi
leaq 0x1f52(%rip), %rsi      # 0x5349
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x4(%rsp), %r8
xorl %eax, %eax
callq 0x2280
cmpl $0x3, %eax
jne 0x3706
movl 0x14(%rsp), %eax
cmpq %rax, %r12
jne 0x36e7
movl 0x4(%rsp), %eax
addl %r15d, %eax
movq 0x20(%rsp), %rcx
cmpl (%rcx), %eax
jg 0x3725
movl %r15d, 0x8(%rsp)
movq %rbx, %rdi
movl $0x2710, %esi           # imm = 0x2710
movq %rbp, %rdx
callq 0x2210
testq %rax, %rax
je 0x3744
movq %rbx, %rdi
callq 0x20a0
movb $0x0, -0x1(%rax,%rbx)
movq (%r13), %rax
leaq (%r12,%r12,2), %r15
shlq $0x5, %r15
movl %r12d, (%rax,%r15)
movl 0x4(%rsp), %ecx
movl %ecx, 0x30(%rax,%r15)
movl 0x10(%rsp), %ecx
cmpl $0x4, %ecx
jae 0x36c8
addq %r15, %rax
movl %ecx, 0x28(%rax)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
callq 0x20a0
leaq (%rsp,%rax), %rdx
addq $0x60, %rdx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3888
movq (%r13), %rax
leaq (%rax,%r15), %rdi
addq $0x8, %rdi
leaq 0x30(%rsp), %rsi
callq 0x21a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x34e7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2150
movq %r12, %rax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rcx
movq 0x8(%r14), %rax
pxor %xmm0, %xmm0
movdqu %xmm0, 0x4c(%rax,%rcx)
movdqu %xmm0, 0x40(%rax,%rcx)
movq 0x10(%r14), %rdx
movslq 0x8(%rsp), %rsi
shlq $0x4, %rsi
leaq (%rdx,%rsi), %rdi
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
jle 0x35d5
movq %rdi, 0x28(%rsp)
leaq (%rdx,%rsi), %rbx
addq $0x4, %rbx
xorl %r14d, %r14d
movq %rbp, %rdi
leaq 0x1da6(%rip), %rsi      # 0x52e3
leaq 0x30(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %eax, %eax
callq 0x2280
cmpl $0x2, %eax
jne 0x3682
movl 0x30(%rsp), %eax
movl %eax, -0x4(%rbx)
movl 0xc(%rsp), %ecx
cmpq $0x7, %rcx
jae 0x36a1
movl %ecx, (%rbx)
movq (%r13), %rax
leaq (%rax,%r15), %rdx
incl 0x40(%rdx,%rcx,4)
incq %r14
movslq 0x4(%rsp), %rcx
addq $0x10, %rbx
cmpq %rcx, %r14
jl 0x3533
testl %ecx, %ecx
jle 0x35cb
movq 0x28(%rsp), %rdi
movq %rdi, %rdx
xorl %esi, %esi
movq 0x18(%rsp), %r14
movl (%rdx), %ecx
cmpq %rcx, %r12
je 0x36c0
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
incl 0x2c(%rax,%rcx)
incq %rsi
movslq 0x4(%rsp), %rcx
addq $0x10, %rdx
cmpq %rcx, %rsi
jl 0x359e
jmp 0x35d5
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %rdi
movq %rdi, 0x38(%rax,%r15)
addl 0x8(%rsp), %ecx
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
leaq 0x60(%rsp), %rbx
jl 0x33ea
movq 0x20(%rsp), %rax
movl (%rax), %ebx
movq 0x49c8(%rip), %r15      # 0x7fc8
jmp 0x3604
xorl %ecx, %ecx
cmpl %ebx, %ecx
jne 0x3782
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2220
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x58(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movsd 0x1bdc(%rip), %xmm2     # 0x5220
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq (%r15), %rdi
divsd %xmm2, %xmm0
leaq 0x1d78(%rip), %rsi      # 0x53d6
movb $0x1, %al
callq 0x21e0
movq (%r15), %rdi
callq 0x2180
movq %r14, %rax
addq $0x2778, %rsp           # imm = 0x2778
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c5f(%rip), %rdi      # 0x52e8
leaq 0x1bce(%rip), %rsi      # 0x525e
leaq 0x1c5e(%rip), %rcx      # 0x52f5
movl $0x51, %edx
callq 0x20d0
leaq 0x1be9(%rip), %rdi      # 0x5291
leaq 0x1baf(%rip), %rsi      # 0x525e
leaq 0x1c0f(%rip), %rcx      # 0x52c5
movl $0x1b, %edx
callq 0x20d0
movl %r12d, %edi
callq 0x22ef
leaq 0x1b59(%rip), %rdi      # 0x5228
leaq 0x1b88(%rip), %rsi      # 0x525e
leaq 0x1b94(%rip), %rcx      # 0x5271
movl $0x16, %edx
callq 0x20d0
leaq 0x1c70(%rip), %rdi      # 0x535e
leaq 0x1b69(%rip), %rsi      # 0x525e
leaq 0x1bf9(%rip), %rcx      # 0x52f5
movl $0x40, %edx
callq 0x20d0
leaq 0x1c44(%rip), %rdi      # 0x5351
leaq 0x1b4a(%rip), %rsi      # 0x525e
leaq 0x1bda(%rip), %rcx      # 0x52f5
movl $0x3f, %edx
callq 0x20d0
leaq 0x1c3d(%rip), %rdi      # 0x5369
leaq 0x1b2b(%rip), %rsi      # 0x525e
leaq 0x1bbb(%rip), %rcx      # 0x52f5
movl $0x41, %edx
callq 0x20d0
leaq 0x1c43(%rip), %rdi      # 0x538e
leaq 0x1b0c(%rip), %rsi      # 0x525e
leaq 0x1b9c(%rip), %rcx      # 0x52f5
movl $0x44, %edx
callq 0x20d0
leaq 0x1b7e(%rip), %rdi      # 0x52e8
leaq 0x1aed(%rip), %rsi      # 0x525e
leaq 0x1b7d(%rip), %rcx      # 0x52f5
movl $0x32, %edx
callq 0x20d0
leaq 0x1c31(%rip), %rdi      # 0x53ba
leaq 0x1ace(%rip), %rsi      # 0x525e
leaq 0x1b5e(%rip), %rcx      # 0x52f5
movl $0x65, %edx
callq 0x20d0
nop