// File: datourat[P]IP-label-for-graph-reachability/Graph.cpp
// Function: Graph::ComputeLayerLabel()
void Graph::ComputeLayerLabel(){
	int i, k;
	int u,v;
	vector<int> indegreeRecord(vsize);
	uint16_t layer=1;
	int vectorsize, tmpsize;

	TopoOrder.resize(vsize);
	vector<uint16_t>(vsize).swap(layerdown);

	k=0;
	for(i=0; i<vsize; i++){
		indegreeRecord[i]=vl[i].indegree;
		if(indegreeRecord[i]==0){
			TopoOrder[k]=i;
			layerdown[i]=layer;
			k++;
		}
	}


	bool flag=true;
	i=0;
	vectorsize=k;
	while(flag){
		flag=false;
		layer++;
		for(; i<vectorsize; i++){
			u=TopoOrder[i];
			tmpsize=graph[u].outList.size();
			for(int j=0; j<tmpsize; j++){
				v=graph[u].outList[j];
				indegreeRecord[v]--;
				if(indegreeRecord[v]==0){
					TopoOrder[k]=v;
					layerdown[v]=layer;
					k++;
				}
			}
		}

		if(vectorsize!=k){
			vectorsize=k;
			flag=true;
		}
	}

	uint16_t tmp;
	vector<uint16_t>(vsize).swap(layerup);
	for(int i=vsize-1; i>=0; i--){
		u=TopoOrder[i];
		tmp=0;
		for(vector<int>::iterator it=graph[u].outList.begin(); it!=graph[u].outList.end(); it++){
			if( layerup[*it] > tmp){
				tmp = layerup[*it];
			}
		}
		layerup[u]=tmp+1;
	}
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x50(%rsp)
movslq 0xc(%rax), %rax
movq %rax, 0x58(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x12990
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
callq 0x129a0
jmp 0x8350
leaq 0xe7(%rsp), %rdi
callq 0x12a20
movq 0x50(%rsp), %rax
movw $0x1, 0xd2(%rsp)
movq %rax, %rdi
addq $0x60, %rdi
movslq 0xc(%rax), %rsi
callq 0x12a30
jmp 0x837e
movq 0x50(%rsp), %rax
movslq 0xc(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x12ad0
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x12ae0
jmp 0x83b7
movq 0x50(%rsp), %rsi
addq $0xc0, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x12b60
leaq 0xb0(%rsp), %rdi
callq 0x114e0
leaq 0xaf(%rsp), %rdi
callq 0x12bc0
movl $0x0, 0x108(%rsp)
movl $0x0, 0x10c(%rsp)
movq 0x50(%rsp), %rcx
movl 0x10c(%rsp), %eax
cmpl 0xc(%rcx), %eax
jge 0x8550
movq 0x50(%rsp), %rdi
addq $0x30, %rdi
movslq 0x10c(%rsp), %rsi
callq 0x11d40
movl 0x8(%rax), %eax
movl %eax, 0x3c(%rsp)
movslq 0x10c(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x12960
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
movslq 0x10c(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x12960
cmpl $0x0, (%rax)
jne 0x8538
movq 0x50(%rsp), %rdi
movl 0x10c(%rsp), %eax
movl %eax, 0x34(%rsp)
addq $0x60, %rdi
movslq 0x108(%rsp), %rsi
callq 0x12960
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rdi
movl %ecx, (%rax)
movw 0xd2(%rsp), %ax
movw %ax, 0x3a(%rsp)
addq $0xc0, %rdi
movslq 0x10c(%rsp), %rsi
callq 0x12bd0
movw 0x3a(%rsp), %cx
movw %cx, (%rax)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x8538
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe7(%rsp), %rdi
callq 0x12a20
jmp 0x8969
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x895c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xaf(%rsp), %rdi
callq 0x12bc0
jmp 0x895c
jmp 0x853a
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x8400
movb $0x1, 0xae(%rsp)
movl $0x0, 0x10c(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0xcc(%rsp)
testb $0x1, 0xae(%rsp)
je 0x8740
movb $0x0, 0xae(%rsp)
movw 0xd2(%rsp), %ax
addw $0x1, %ax
movw %ax, 0xd2(%rsp)
movl 0x10c(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jge 0x8715
movq 0x50(%rsp), %rdi
addq $0x60, %rdi
movslq 0x10c(%rsp), %rsi
callq 0x12960
movq 0x50(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x104(%rsp)
addq $0x48, %rdi
movslq 0x104(%rsp), %rsi
callq 0x11d60
movq %rax, %rdi
addq $0x18, %rdi
callq 0x4c10
movl %eax, 0xc8(%rsp)
movl $0x0, 0xa8(%rsp)
movl 0xa8(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jge 0x86fd
movq 0x50(%rsp), %rdi
addq $0x48, %rdi
movslq 0x104(%rsp), %rsi
callq 0x11d60
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xa8(%rsp), %rsi
callq 0x12960
movl (%rax), %eax
movl %eax, 0x100(%rsp)
movslq 0x100(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x12960
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movslq 0x100(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x12960
cmpl $0x0, (%rax)
jne 0x86e5
movq 0x50(%rsp), %rdi
movl 0x100(%rsp), %eax
movl %eax, 0x2c(%rsp)
addq $0x60, %rdi
movslq 0x108(%rsp), %rsi
callq 0x12960
movl 0x2c(%rsp), %ecx
movq 0x50(%rsp), %rdi
movl %ecx, (%rax)
movw 0xd2(%rsp), %ax
movw %ax, 0x32(%rsp)
addq $0xc0, %rdi
movslq 0x100(%rsp), %rsi
callq 0x12bd0
movw 0x32(%rsp), %cx
movw %cx, (%rax)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x86e7
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x8602
jmp 0x86ff
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x859b
movl 0xcc(%rsp), %eax
cmpl 0x108(%rsp), %eax
je 0x873b
movl 0x108(%rsp), %eax
movl %eax, 0xcc(%rsp)
movb $0x1, 0xae(%rsp)
jmp 0x8571
movq 0x50(%rsp), %rax
movslq 0xc(%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0x87(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x12ad0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x88(%rsp), %rdi
callq 0x12ae0
jmp 0x8779
movq 0x50(%rsp), %rsi
addq $0xd8, %rsi
leaq 0x88(%rsp), %rdi
callq 0x12b60
leaq 0x88(%rsp), %rdi
callq 0x114e0
leaq 0x87(%rsp), %rdi
callq 0x12bc0
movq 0x50(%rsp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
movl %eax, 0x80(%rsp)
cmpl $0x0, 0x80(%rsp)
jl 0x8947
movq 0x50(%rsp), %rdi
addq $0x60, %rdi
movslq 0x80(%rsp), %rsi
callq 0x12960
movq 0x50(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x104(%rsp)
movw $0x0, 0xa6(%rsp)
addq $0x48, %rdi
movslq 0x104(%rsp), %rsi
callq 0x11d60
movq %rax, %rdi
addq $0x18, %rdi
callq 0x12270
movq %rax, 0x78(%rsp)
movq 0x50(%rsp), %rdi
addq $0x48, %rdi
movslq 0x104(%rsp), %rsi
callq 0x11d60
movq %rax, %rdi
addq $0x18, %rdi
callq 0x122e0
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x122a0
testb $0x1, %al
jne 0x885b
jmp 0x8900
movq 0x50(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x10(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x12310
movq 0x10(%rsp), %rdi
movslq (%rax), %rsi
callq 0x12bd0
movzwl (%rax), %eax
movzwl 0xa6(%rsp), %ecx
cmpl %ecx, %eax
jle 0x88e8
movq 0x50(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x12310
movq 0x8(%rsp), %rdi
movslq (%rax), %rsi
callq 0x12bd0
movw (%rax), %ax
movw %ax, 0xa6(%rsp)
jmp 0x88e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0x87(%rsp), %rdi
callq 0x12bc0
jmp 0x895c
jmp 0x88ea
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
callq 0x12320
movq %rax, 0x68(%rsp)
jmp 0x881c
movq 0x50(%rsp), %rdi
movzwl 0xa6(%rsp), %eax
addl $0x1, %eax
movw %ax, 0x6(%rsp)
addq $0xd8, %rdi
movslq 0x104(%rsp), %rsi
callq 0x12bd0
movw 0x6(%rsp), %cx
movw %cx, (%rax)
movl 0x80(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x87be
leaq 0xe8(%rsp), %rdi
callq 0x115a0
addq $0x118, %rsp            # imm = 0x118
retq
leaq 0xe8(%rsp), %rdi
callq 0x115a0
movq 0xd8(%rsp), %rdi
callq 0x34e0
nopw %cs:(%rax,%rax)