// File: datourat[P]IP-label-for-graph-reachability/Graph.cpp
// Function: Graph::IndexQueryTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Graph::IndexQueryTest(const string& indexfilename, const string& queryfilename){
	int u, v;
	bool ProLflag;
	clock_t start, end;
	struct timeval querystart, queryend;


	start=clock();
	ReadIndex(indexfilename.c_str());
	end=clock();
	cout << "ReadIndex is complete." << endl;
	cout << "Time Cost: " << (double)(end-start)/CLOCKS_PER_SEC << endl;

	ifstream queryfile(queryfilename.c_str());
	string line;
//	vector< pair<int, int> > qpair;
	vector<int> src;
	vector<int> dest;
	vector<int> reachflag;
	vector<string> tmps;
	int i=0;
	start=clock();
	while(getline(queryfile, line), line.size()){
		split(line, ' ', tmps);
		src.push_back(atoi(tmps[0].c_str()));
		dest.push_back(atoi(tmps[1].c_str()));
//		qpair.push_back( make_pair(atoi(tmps[0].c_str()), atoi(tmps[1].c_str())) );
		reachflag.push_back(atoi(tmps[2].c_str()));
		i++;
		tmps.clear();
	}
	end=clock();
	cout << "ReadQueryfile is complete." << endl;
        cout << "Read Query File Cost: " << (double)(end-start)/CLOCKS_PER_SEC << endl;
	queryfile.close();


//	vector<int> flag(vsize, 0);
	flag=new int[vsize];
	memset(flag, 0, sizeof(int)*vsize);
	cout << "Total Query number: " << src.size() << endl;
	
	querycnt=0;
	gettimeofday(&querystart, NULL);
//	for(vector< pair<int, int> >::iterator qit=qpair.begin(); qit!=qpair.end(); qit++){
	for(vector<int>::iterator uit=src.begin(), vit=dest.begin(); uit!=src.end(); uit++, vit++){
//	for(i=0; i<src.size(); i++){
//		u=src[i];
//		v=dest[i];
		

		if(*uit==*vit)
			ProLflag=true;
		else if(reachindex[*uit].layerdown>=reachindex[*vit].layerdown || reachindex[*uit].layerup<=reachindex[*vit].layerup)
			ProLflag=false;
		else{
			querycnt++;
			ProLabelQueryDFS2(*uit, *vit);
		}

/*
                if((*qit).first==(*qit).second)
                        ProLflag=true;
		else if(reachindex[(*qit).first].layerdown>=reachindex[(*qit).second].layerdown || reachindex[(*qit).first].layerup<=reachindex[(*qit).second].layerup)
                        ProLflag=false;
		else{
                        querycnt++;
                        ProLabelQueryDFS2((*qit).first, (*qit).second);
		}
*/
//		cout << ProLflag << endl;
//
	}
	gettimeofday(&queryend, NULL);
        cout << "Time Cost: " << (queryend.tv_sec - querystart.tv_sec)*1000.0 + (queryend.tv_usec - querystart.tv_usec)*1.0/1000.0 << endl;

	int count=0;
	i=0;
	querycnt=0;
	memset(flag, 0, sizeof(int)*vsize);
//	for(vector< pair<int, int> >::iterator qit=qpair.begin(); qit!=qpair.end(); qit++, i++){
	for(vector<int>::iterator uit=src.begin(), vit=dest.begin(); uit!=src.end(); uit++, vit++, i++){

                if(*uit==*vit)
                        ProLflag=true;
                else if(reachindex[*uit].layerdown>=reachindex[*vit].layerdown || reachindex[*uit].layerup<=reachindex[*vit].layerup)
                        ProLflag=false;
		else{
			querycnt++;
			ProLflag=ProLabelQueryDFS2(*uit, *vit);
		}

/*
                if((*qit).first==(*qit).second)
                        ProLflag=true;
                else if(reachindex[(*qit).first].layerdown>=reachindex[(*qit).second].layerdown || reachindex[(*qit).first].layerup<=reachindex[(*qit).second].layerup)
                        ProLflag=false;
                else{
                        querycnt++;
                        ProLflag=ProLabelQueryDFS2((*qit).first, (*qit).second);
                }
*/
		if((bool)reachflag[i]!=ProLflag){
//			cout << "i: " << i << '\t' << (*qit).first << ' ' << (*qit).second << ' ' << reachflag[i] << endl;
			cout << "i: " << i << '\t' << *uit << ' ' << *vit << ' ' << reachflag[i] << endl;
			count++;
		}
	}

	cout << "False number: " << count << endl;

	delete[] flag;
}

// Assembly:
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rdi, 0x4a0(%rsp)
movq %rsi, 0x498(%rsp)
movq %rdx, 0x490(%rsp)
movq 0x4a0(%rsp), %rax
movq %rax, 0x110(%rsp)
callq 0x31f0
movq %rax, 0x478(%rsp)
movq 0x498(%rsp), %rdi
callq 0x3120
movq %rax, 0x118(%rsp)
leaq 0x42f(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x34f0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x430(%rsp), %rdi
callq 0x33d0
jmp 0xfba5
movq 0x110(%rsp), %rdi
leaq 0x430(%rsp), %rsi
callq 0xe0a0
jmp 0xfbbc
leaq 0x430(%rsp), %rdi
callq 0x31b0
leaq 0x42f(%rsp), %rdi
callq 0x3310
callq 0x31f0
movq %rax, 0x470(%rsp)
movq 0x253ee(%rip), %rdi     # 0x34fd8
leaq 0x18997(%rip), %rsi     # 0x28588
callq 0x32c0
movq %rax, %rdi
movq 0x253c8(%rip), %rsi     # 0x34fc8
callq 0x3300
movq 0x253cc(%rip), %rdi     # 0x34fd8
leaq 0x18640(%rip), %rsi     # 0x28253
callq 0x32c0
movq %rax, %rdi
movq 0x470(%rsp), %rax
subq 0x478(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x183d0(%rip), %xmm1    # 0x28008
divsd %xmm1, %xmm0
callq 0x3540
movq %rax, %rdi
movq 0x2537d(%rip), %rsi     # 0x34fc8
callq 0x3300
movq 0x490(%rsp), %rdi
callq 0x3120
movq %rax, %rsi
leaq 0x210(%rsp), %rdi
movl $0x8, %edx
callq 0x3510
leaq 0x1f0(%rsp), %rdi
callq 0x33e0
leaq 0x1d8(%rsp), %rdi
callq 0x11160
leaq 0x1c0(%rsp), %rdi
callq 0x11160
leaq 0x1a8(%rsp), %rdi
callq 0x11160
leaq 0x190(%rsp), %rdi
callq 0x11d10
movl $0x0, 0x18c(%rsp)
callq 0x31f0
movq %rax, 0x478(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x3070
jmp 0xfce2
leaq 0x1f0(%rsp), %rdi
callq 0x3200
cmpq $0x0, %rax
je 0xfea7
leaq 0x1f0(%rsp), %rdi
movl $0x20, %esi
leaq 0x190(%rsp), %rdx
callq 0x6000
jmp 0xfd15
xorl %eax, %eax
movl %eax, %esi
leaq 0x190(%rsp), %rdi
callq 0x11e90
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x3440
movl %eax, 0x188(%rsp)
leaq 0x1d8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x14340
jmp 0xfd54
leaq 0x190(%rsp), %rdi
movl $0x1, %esi
callq 0x11e90
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x3440
movl %eax, 0x184(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x184(%rsp), %rsi
callq 0x14340
jmp 0xfd94
leaq 0x190(%rsp), %rdi
movl $0x2, %esi
callq 0x11e90
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
callq 0x3440
movl %eax, 0x180(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x14340
jmp 0xfdd4
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x11eb0
jmp 0xfccb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
jmp 0xfe2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
leaq 0x430(%rsp), %rdi
callq 0x31b0
leaq 0x42f(%rsp), %rdi
callq 0x3310
jmp 0x1076e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x11ed0
leaq 0x1a8(%rsp), %rdi
callq 0x115a0
leaq 0x1c0(%rsp), %rdi
callq 0x115a0
leaq 0x1d8(%rsp), %rdi
callq 0x115a0
leaq 0x1f0(%rsp), %rdi
callq 0x31b0
leaq 0x210(%rsp), %rdi
callq 0x30b0
jmp 0x1076e
callq 0x31f0
movq %rax, 0x470(%rsp)
movq 0x2511d(%rip), %rdi     # 0x34fd8
leaq 0x186dd(%rip), %rsi     # 0x2859f
callq 0x32c0
movq %rax, 0x108(%rsp)
jmp 0xfed1
movq 0x108(%rsp), %rdi
movq 0x250e8(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0xfee7
movq 0x250ea(%rip), %rdi     # 0x34fd8
leaq 0x186c5(%rip), %rsi     # 0x285ba
callq 0x32c0
movq %rax, 0x100(%rsp)
jmp 0xff04
movq 0x100(%rsp), %rdi
movq 0x470(%rsp), %rax
movq 0x478(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x180dc(%rip), %xmm1    # 0x28008
divsd %xmm1, %xmm0
callq 0x3540
movq %rax, 0xf8(%rsp)
jmp 0xff3f
movq 0xf8(%rsp), %rdi
movq 0x2507a(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0xff55
leaq 0x210(%rsp), %rdi
callq 0x3080
jmp 0xff64
movq 0x110(%rsp), %rax
movslq 0xc(%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, 0xf0(%rsp)
jmp 0xff95
movq 0x110(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, 0x25344(%rip)     # 0x352f0
movq 0x2533d(%rip), %rdi     # 0x352f0
movslq 0xc(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3170
movq 0x2500f(%rip), %rdi     # 0x34fd8
leaq 0x18601(%rip), %rsi     # 0x285d1
callq 0x32c0
movq %rax, 0xe8(%rsp)
jmp 0xffdf
leaq 0x1d8(%rsp), %rdi
callq 0x4c10
movq 0xe8(%rsp), %rdi
movq %rax, %rsi
callq 0x30a0
movq %rax, 0xe0(%rsp)
jmp 0x10006
movq 0xe0(%rsp), %rdi
movq 0x24fb3(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0x1001c
movl $0x0, 0x252d2(%rip)     # 0x352f8
leaq 0x460(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3470
leaq 0x1d8(%rsp), %rdi
callq 0x12270
movq %rax, 0x178(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x12270
movq %rax, 0x170(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x122e0
movq %rax, 0x168(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x122a0
testb $0x1, %al
jne 0x10094
jmp 0x1026c
leaq 0x178(%rsp), %rdi
callq 0x12310
movl (%rax), %eax
movl %eax, 0xdc(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x12310
movq %rax, %rcx
movl 0xdc(%rsp), %eax
cmpl (%rcx), %eax
jne 0x100d2
movb $0x1, 0x487(%rsp)
jmp 0x10237
movq 0x110(%rsp), %rax
addq $0xa8, %rax
movq %rax, 0xc8(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x12310
movq 0xc8(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movq 0x110(%rsp), %rax
movzwl 0x2(%rcx), %ecx
movl %ecx, 0xd8(%rsp)
addq $0xa8, %rax
movq %rax, 0xd0(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x12310
movq 0xd0(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movl 0xd8(%rsp), %eax
movzwl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x101e0
movq 0x110(%rsp), %rax
addq $0xa8, %rax
movq %rax, 0xb0(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x12310
movq 0xb0(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movq 0x110(%rsp), %rax
movzwl (%rcx), %ecx
movl %ecx, 0xc4(%rsp)
addq $0xa8, %rax
movq %rax, 0xb8(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x12310
movq 0xb8(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movl 0xc4(%rsp), %eax
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jg 0x101ea
movb $0x0, 0x487(%rsp)
jmp 0x10235
movl 0x25108(%rip), %eax     # 0x352f8
incl %eax
movl %eax, 0x25100(%rip)     # 0x352f8
leaq 0x178(%rsp), %rdi
callq 0x12310
movl (%rax), %eax
movl %eax, 0xac(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x12310
movq 0x110(%rsp), %rdi
movl 0xac(%rsp), %esi
movl (%rax), %edx
callq 0x10780
jmp 0x10233
jmp 0x10235
jmp 0x10237
jmp 0x10239
leaq 0x178(%rsp), %rdi
xorl %esi, %esi
callq 0x12320
movq %rax, 0x160(%rsp)
leaq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x12320
movq %rax, 0x158(%rsp)
jmp 0x10061
xorl %eax, %eax
movl %eax, %esi
leaq 0x450(%rsp), %rdi
callq 0x3470
movq 0x24d54(%rip), %rdi     # 0x34fd8
leaq 0x17fc8(%rip), %rsi     # 0x28253
callq 0x32c0
movq %rax, 0xa0(%rsp)
jmp 0x1029a
movq 0xa0(%rsp), %rdi
movq 0x450(%rsp), %rdx
movq 0x458(%rsp), %rax
movq 0x460(%rsp), %rsi
movq 0x468(%rsp), %rcx
subq %rsi, %rdx
cvtsi2sd %rdx, %xmm0
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x180e6(%rip), %xmm2    # 0x283c0
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x3540
movq %rax, 0x98(%rsp)
jmp 0x102f5
movq 0x98(%rsp), %rdi
movq 0x24cc4(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0x1030b
movq 0x110(%rsp), %rax
movl $0x0, 0x154(%rsp)
movl $0x0, 0x18c(%rsp)
movl $0x0, 0x24fc5(%rip)     # 0x352f8
movq 0x24fb6(%rip), %rdi     # 0x352f0
movslq 0xc(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3170
leaq 0x1d8(%rsp), %rdi
callq 0x12270
movq %rax, 0x148(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x12270
movq %rax, 0x140(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x122e0
movq %rax, 0x138(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x122a0
testb $0x1, %al
jne 0x103a6
jmp 0x106b7
leaq 0x148(%rsp), %rdi
callq 0x12310
movl (%rax), %eax
movl %eax, 0x94(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x12310
movq %rax, %rcx
movl 0x94(%rsp), %eax
cmpl (%rcx), %eax
jne 0x103e4
movb $0x1, 0x487(%rsp)
jmp 0x1053c
movq 0x110(%rsp), %rax
addq $0xa8, %rax
movq %rax, 0x80(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x12310
movq 0x80(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movq 0x110(%rsp), %rax
movzwl 0x2(%rcx), %ecx
movl %ecx, 0x90(%rsp)
addq $0xa8, %rax
movq %rax, 0x88(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x12310
movq 0x88(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movl 0x90(%rsp), %eax
movzwl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x104dc
movq 0x110(%rsp), %rax
addq $0xa8, %rax
movq %rax, 0x68(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x12310
movq 0x68(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movq 0x110(%rsp), %rax
movzwl (%rcx), %ecx
movl %ecx, 0x7c(%rsp)
addq $0xa8, %rax
movq %rax, 0x70(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x12310
movq 0x70(%rsp), %rdi
movslq (%rax), %rsi
callq 0x142b0
movq %rax, %rcx
movl 0x7c(%rsp), %eax
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jg 0x104e6
movb $0x0, 0x487(%rsp)
jmp 0x1053a
movl 0x24e0c(%rip), %eax     # 0x352f8
incl %eax
movl %eax, 0x24e04(%rip)     # 0x352f8
leaq 0x148(%rsp), %rdi
callq 0x12310
movl (%rax), %eax
movl %eax, 0x60(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x12310
movq 0x110(%rsp), %rdi
movl 0x60(%rsp), %esi
movl (%rax), %edx
callq 0x10780
movb %al, 0x67(%rsp)
jmp 0x1052d
movb 0x67(%rsp), %al
andb $0x1, %al
movb %al, 0x487(%rsp)
jmp 0x1053c
movslq 0x18c(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x12960
cmpl $0x0, (%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movb 0x487(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x10671
movq 0x24a60(%rip), %rdi     # 0x34fd8
leaq 0x18067(%rip), %rsi     # 0x285e6
callq 0x32c0
movq %rax, 0x58(%rsp)
jmp 0x1058b
movq 0x58(%rsp), %rdi
movl 0x18c(%rsp), %esi
callq 0x34d0
movq %rax, 0x50(%rsp)
jmp 0x105a3
movq 0x50(%rsp), %rdi
movl $0x9, %esi
callq 0x3350
movq %rax, 0x48(%rsp)
jmp 0x105b9
leaq 0x148(%rsp), %rdi
callq 0x12310
movq 0x48(%rsp), %rdi
movl (%rax), %esi
callq 0x34d0
movq %rax, 0x40(%rsp)
jmp 0x105d9
movq 0x40(%rsp), %rdi
movl $0x20, %esi
callq 0x3350
movq %rax, 0x38(%rsp)
jmp 0x105ef
leaq 0x140(%rsp), %rdi
callq 0x12310
movq 0x38(%rsp), %rdi
movl (%rax), %esi
callq 0x34d0
movq %rax, 0x30(%rsp)
jmp 0x1060f
movq 0x30(%rsp), %rdi
movl $0x20, %esi
callq 0x3350
movq %rax, 0x28(%rsp)
jmp 0x10625
movslq 0x18c(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x12960
movq 0x28(%rsp), %rdi
movl (%rax), %esi
callq 0x34d0
movq %rax, 0x20(%rsp)
jmp 0x1064d
movq 0x20(%rsp), %rdi
movq 0x2496f(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0x10660
movl 0x154(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x154(%rsp)
jmp 0x10673
leaq 0x148(%rsp), %rdi
xorl %esi, %esi
callq 0x12320
movq %rax, 0x130(%rsp)
leaq 0x140(%rsp), %rdi
xorl %esi, %esi
callq 0x12320
movq %rax, 0x128(%rsp)
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
jmp 0x10373
movq 0x2491a(%rip), %rdi     # 0x34fd8
leaq 0x17f25(%rip), %rsi     # 0x285ea
callq 0x32c0
movq %rax, 0x18(%rsp)
jmp 0x106d1
movq 0x18(%rsp), %rdi
movl 0x154(%rsp), %esi
callq 0x34d0
movq %rax, 0x10(%rsp)
jmp 0x106e9
movq 0x10(%rsp), %rdi
movq 0x248d3(%rip), %rsi     # 0x34fc8
callq 0x3300
jmp 0x106fc
movq 0x24bed(%rip), %rax     # 0x352f0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x10718
movq 0x8(%rsp), %rdi
callq 0x3390
leaq 0x190(%rsp), %rdi
callq 0x11ed0
leaq 0x1a8(%rsp), %rdi
callq 0x115a0
leaq 0x1c0(%rsp), %rdi
callq 0x115a0
leaq 0x1d8(%rsp), %rdi
callq 0x115a0
leaq 0x1f0(%rsp), %rdi
callq 0x31b0
leaq 0x210(%rsp), %rdi
callq 0x30b0
addq $0x4a8, %rsp            # imm = 0x4A8
retq
movq 0x420(%rsp), %rdi
callq 0x34e0
nopl (%rax,%rax)