// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
leaq -0x30(%rbp), %rdi
callq 0x2e20
leaq -0x48(%rbp), %rdi
callq 0x2cd0
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2898
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x41e0
movq %rax, -0xa8(%rbp)
jmp 0x27c1
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movslq -0xc(%rbp), %rcx
cvtsi2sdl 0x40(%rax,%rcx,4), %xmm1
movsd 0x2826(%rip), %xmm0     # 0x5008
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x2888
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x2cf0
movl %eax, -0xac(%rbp)
jmp 0x282a
movl -0xac(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x2878
leaq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2e40
jmp 0x2844
movq -0x80(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2d10
jmp 0x2853
jmp 0x2878
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2dc0
leaq -0x30(%rbp), %rdi
callq 0x2ef0
jmp 0x2afa
jmp 0x287a
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x27f2
jmp 0x288a
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x279d
leaq -0x30(%rbp), %rdi
callq 0x2eb0
movl %eax, -0x84(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2eb0
movq %rax, -0xb8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2d80
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jne 0x28d1
jmp 0x28f0
leaq 0x279b(%rip), %rdi      # 0x5073
leaq 0x2754(%rip), %rsi      # 0x5033
movl $0x54, %edx
leaq 0x27a6(%rip), %rcx      # 0x5091
callq 0x20c0
movq -0x18(%rbp), %rcx
leaq -0x84(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
jmp 0x290c
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x2ed0
movq %rax, %rdi
movslq -0x84(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x8, %esi
callq 0x22a0
jmp 0x2933
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x2da0
movq %rax, %rdi
movslq -0x84(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x4, %esi
callq 0x22a0
jmp 0x295a
movq -0x8(%rbp), %rax
movl (%rax), %eax
incl %eax
movl %eax, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0xc0(%rbp)
jmp 0x2993
movq -0xc0(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x90(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x98(%rbp)
movl -0x98(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2a3e
movq -0x8(%rbp), %rdi
movl -0x98(%rbp), %esi
callq 0x41e0
movq %rax, -0xc8(%rbp)
jmp 0x29e8
movq -0xc8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl 0x40(%rax,%rcx,4), %eax
addl -0x94(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %edx
movq -0x90(%rbp), %rax
movl -0x98(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x29c2
movq -0x18(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
jmp 0x2a5a
movq -0x90(%rbp), %rdi
movslq -0x88(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x4, %esi
callq 0x22a0
jmp 0x2a78
movq -0x90(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x2a98
movq -0xd0(%rbp), %rdi
callq 0x21d0
movslq -0x94(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2eb0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jne 0x2ac0
jmp 0x2adf
leaq 0x25f8(%rip), %rdi      # 0x50bf
leaq 0x2565(%rip), %rsi      # 0x5033
movl $0x6b, %edx
leaq 0x25b7(%rip), %rcx      # 0x5091
callq 0x20c0
leaq -0x48(%rbp), %rdi
callq 0x2dc0
leaq -0x30(%rbp), %rdi
callq 0x2ef0
addq $0xe0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)