// File: /workspace/github_cpp_makefile_star2_O1/wenleix[P]EdgePPR/src/GenCSRMatrix.cpp
// Function: GenBinCscFile(ParamGraph*, int, _IO_FILE*)
void GenBinCscFile(ParamGraph* g, int etype, FILE *cscFile) {
	//	Print the matrix size
    fwrite(&g->numVertex, sizeof(int), 1, cscFile);
    fwrite(&g->numVertex, sizeof(int), 1, cscFile);

	vector<double> data;
	vector<int> indices;

	for (int i = 0; i < g->numVertex; i++) {
		ParamVertex *vtx = g->GetVertex(i);
		double w = 1.0 / vtx->outEdgeTypeCount[etype];
		for (int j = 0; j < vtx->outDeg; j++) {
			ParamEdge *e = &vtx->outEdge[j];
			if (e->GetIntEType() == etype) {
				data.push_back(w);
				indices.push_back(e->dstId);
			}
		}
	}

    int numEntry = data.size();
    assert(data.size() == indices.size());

	//	data
    fwrite(&numEntry, sizeof(int), 1, cscFile);
    fwrite(&data[0], sizeof(double), numEntry, cscFile);

	//	indices
    fwrite(&indices[0], sizeof(int), numEntry, cscFile);
	
    //	indptr
    int numIndPtr = g->numVertex + 1;   //  Temporal var for output
    int* tmpIndPtr = new int[numIndPtr];
	int acc = 0;
    tmpIndPtr[0] = 0;
    for (int i = 0; i < g->numVertex; i++) {
		ParamVertex *vtx = g->GetVertex(i);
		acc += vtx->outEdgeTypeCount[etype];
        tmpIndPtr[i + 1] = acc;
    }

    fwrite(&numIndPtr, sizeof(int), 1, cscFile);
    fwrite(tmpIndPtr, sizeof(int), numIndPtr, cscFile);
    delete [] tmpIndPtr;
	assert(acc == data.size());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, 0x48(%rsp)
movq %rbx, %rcx
callq 0x11c0
xorl %r15d, %r15d
movq %r15, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq %r15, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
cmpl $0x0, (%r14)
movslq %ebp, %rax
movq %rax, 0x40(%rsp)
jle 0x17b2
movq %r14, 0x50(%rsp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x1d10
movq %rax, %r12
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x40(%r12,%rax,4), %xmm0
movsd 0x18f6(%rip), %xmm1     # 0x3008
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
cmpl $0x0, 0x30(%r12)
jle 0x17a1
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x38(%r12), %r13
cmpl %ebp, 0x4(%r13,%rbx)
jne 0x1790
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x1756
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1763
movq %rsp, %rdi
leaq 0x18(%rsp), %rdx
callq 0x1bd0
addq %rbx, %r13
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x1783
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x1790
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
callq 0x1a94
incq %r14
movslq 0x30(%r12), %rax
addq $0x10, %rbx
cmpq %rax, %r14
jl 0x1729
incl %r15d
movq 0x50(%rsp), %r14
cmpl (%r14), %r15d
jl 0x16ed
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
movl %eax, 0x18(%rsp)
movq 0x28(%rsp), %rcx
subq 0x20(%rsp), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rax
jne 0x190f
leaq 0x18(%rsp), %rbx
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq 0x48(%rsp), %r13
movq %r13, %rcx
callq 0x11c0
movq (%rsp), %rdi
movslq (%rbx), %rbx
movl $0x8, %esi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x11c0
movq 0x20(%rsp), %rdi
movl $0x4, %esi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x11c0
movslq (%r14), %rax
leaq 0x1(%rax), %rcx
cmpq $-0x1, %rax
movl %ecx, 0x3c(%rsp)
leaq 0x4(,%rax,4), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x1030
movq %rax, %rbx
movl $0x0, (%rax)
xorl %r12d, %r12d
cmpl $0x0, (%r14)
jle 0x188c
xorl %r15d, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x1d10
movq 0x40(%rsp), %rcx
movslq 0x40(%rax,%rcx,4), %rax
movslq %r12d, %r12
addq %rax, %r12
movl %r12d, 0x4(%rbx,%r15,4)
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x1861
leaq 0x3c(%rsp), %r14
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rcx
callq 0x11c0
movslq (%r14), %rdx
movl $0x4, %esi
movq %rbx, %rdi
movq %r13, %rcx
callq 0x11c0
movq %rbx, %rdi
callq 0x1130
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
cmpq %r12, %rax
jne 0x192e
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x18ea
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1900
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x175b(%rip), %rdi      # 0x3071
leaq 0x1714(%rip), %rsi      # 0x3031
leaq 0x176b(%rip), %rcx      # 0x308f
movl $0x54, %edx
callq 0x1080
leaq 0x1788(%rip), %rdi      # 0x30bd
leaq 0x16f5(%rip), %rsi      # 0x3031
leaq 0x174c(%rip), %rcx      # 0x308f
movl $0x6b, %edx
callq 0x1080
jmp 0x1953
jmp 0x1953
jmp 0x1953
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x196d
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1983
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1190