// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r14
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x11c0
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rcx
callq 0x11c0
xorl %r15d, %r15d
movq %r15, 0x20(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq %r15, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
cmpl $0x0, (%r14)
movslq %ebp, %rax
movq %rax, 0x50(%rsp)
jle 0x1812
movq %r13, 0x58(%rsp)
movq %r14, 0x60(%rsp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x1d3c
movq %rax, %r12
movq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x40(%r12,%rax,4), %xmm0
movsd 0x18e1(%rip), %xmm1     # 0x3008
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
cmpl $0x0, 0x30(%r12)
jle 0x17b8
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x38(%r12), %r13
cmpl %ebp, 0x4(%r13,%rbx)
jne 0x17a7
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x176b
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x177a
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x1bfa
addq %rbx, %r13
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x179a
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x17a7
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0x1abe
incq %r14
movslq 0x30(%r12), %rax
addq $0x10, %rbx
cmpq %rax, %r14
jl 0x173e
incl %r15d
movq 0x60(%rsp), %r14
cmpl (%r14), %r15d
jl 0x1702
movq 0x18(%rsp), %rax
movq 0x38(%rsp), %rcx
subq 0x10(%rsp), %rax
subq 0x30(%rsp), %rcx
sarq $0x3, %rax
sarq $0x2, %rcx
movl %eax, 0x8(%rsp)
cmpq %rcx, %rax
movq 0x58(%rsp), %r13
je 0x181a
leaq 0x1877(%rip), %rdi      # 0x3071
leaq 0x1830(%rip), %rsi      # 0x3031
leaq 0x1887(%rip), %rcx      # 0x308f
movl $0x54, %edx
callq 0x1080
movl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rbx
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rcx
callq 0x11c0
movq 0x10(%rsp), %rdi
movslq (%rbx), %rbx
movl $0x8, %esi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x11c0
movq 0x30(%rsp), %rdi
movl $0x4, %esi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x11c0
movq %r14, %rbp
movslq (%r14), %r14
leaq 0x1(%r14), %rax
cmpq $-0x1, %r14
movl %eax, 0x4c(%rsp)
leaq 0x4(,%r14,4), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x1030
movq %rax, %rbx
movl $0x0, (%rax)
xorl %r12d, %r12d
testl %r14d, %r14d
jle 0x18cd
xorl %r15d, %r15d
movq %rbp, %r14
movq %r14, %rdi
movl %r15d, %esi
callq 0x1d3c
movq 0x50(%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 0x18a2
leaq 0x4c(%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 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
cmpq %r12, %rax
jne 0x1958
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1937
movq 0x40(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1949
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x175e(%rip), %rdi      # 0x30bd
leaq 0x16cb(%rip), %rsi      # 0x3031
leaq 0x1722(%rip), %rcx      # 0x308f
movl $0x6b, %edx
callq 0x1080
jmp 0x197d
jmp 0x197d
jmp 0x197d
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1997
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x19ae
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1190