// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movl %esi, %ebp
movq %rdi, %r12
pushq $0x4
popq %rbx
pushq $0x1
popq %r14
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11f0
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, 0x30(%rsp)
movq %r15, %rcx
callq 0x11f0
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movslq %ebp, %rax
movq %rax, 0x38(%rsp)
xorl %esi, %esi
movq %rsp, %rbx
movq %r12, 0x58(%rsp)
cmpl (%r12), %esi
jge 0x164f
movq %r12, %rdi
movq %rsi, 0x60(%rsp)
callq 0x1c74
movq %rax, %r14
movq 0x38(%rsp), %rax
cvtsi2sdl 0x40(%r14,%rax,4), %xmm0
movsd 0x1a13(%rip), %xmm1     # 0x3008
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0x30(%r14), %rax
cmpq %rax, %r12
jge 0x163e
movq 0x38(%r14), %r13
cmpl %ebp, 0x4(%r13,%r15)
jne 0x1635
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x1954
addq %r15, %r13
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x1936
incq %r12
addq $0x10, %r15
jmp 0x1604
movq 0x60(%rsp), %rsi
incl %esi
movq 0x58(%rsp), %r12
jmp 0x15cb
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x3, %rax
movl %eax, (%rsp)
movq 0x48(%rsp), %rcx
subq 0x40(%rsp), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rax
jne 0x1787
movq %rsp, %rbx
pushq $0x4
popq %r14
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rcx
callq 0x11f0
movq 0x10(%rsp), %rdi
movslq (%rbx), %rbx
pushq $0x8
popq %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11f0
movq 0x40(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11f0
movslq (%r12), %r15
leaq 0x1(%r15), %rax
cmpq $-0x1, %r15
movl %eax, 0xc(%rsp)
leaq 0x4(,%r15,4), %rax
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x1030
movq %rax, %rbx
andl $0x0, (%rax)
xorl %r14d, %r14d
xorl %ebp, %ebp
movslq %r15d, %rax
cmpq %rax, %r14
jge 0x1716
movq %r12, %rdi
movl %r14d, %esi
callq 0x1c74
movq 0x38(%rsp), %rcx
addl 0x40(%rax,%rcx,4), %ebp
movl %ebp, 0x4(%rbx,%r14,4)
incq %r14
movl (%r12), %r15d
jmp 0x16ec
leaq 0xc(%rsp), %r14
pushq $0x4
popq %r15
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %r12
movq %r12, %rcx
callq 0x11f0
movslq (%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x11f0
movq %rbx, %rdi
callq 0x1160
movslq %ebp, %rax
movq 0x18(%rsp), %rcx
subq 0x10(%rsp), %rcx
sarq $0x3, %rcx
cmpq %rax, %rcx
jne 0x17a0
leaq 0x40(%rsp), %rdi
callq 0x1982
leaq 0x10(%rsp), %rdi
callq 0x1af8
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18e3(%rip), %rdi      # 0x3071
leaq 0x189c(%rip), %rsi      # 0x3031
leaq 0x18f3(%rip), %rcx      # 0x308f
pushq $0x54
jmp 0x17b7
leaq 0x1916(%rip), %rdi      # 0x30bd
leaq 0x1883(%rip), %rsi      # 0x3031
leaq 0x18da(%rip), %rcx      # 0x308f
pushq $0x6b
popq %rdx
callq 0x10b0
jmp 0x17c3
jmp 0x17c3
jmp 0x17c3
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x1982
leaq 0x10(%rsp), %rdi
callq 0x1af8
movq %rbx, %rdi
callq 0x11c0