// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
callq 0x31b0
movq %rax, %r15
movq (%r14), %rsi
leaq 0xd0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3100
leaq 0xd0(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0xa340
movq %r12, 0x28(%rsp)
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb2b1
callq 0x3260
callq 0x31b0
movq %rax, %r13
movq 0xad18(%rip), %r12      # 0x15fd8
leaq 0x5321(%rip), %rsi      # 0x105e8
movl $0x16, %edx
movq %r12, %rdi
callq 0x32e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
leaq 0x4f44(%rip), %rsi      # 0x10247
movl $0xb, %edx
movq %r12, %rdi
callq 0x32e0
subq %r15, %r13
cvtsi2sd %r13, %xmm0
divsd 0x4ce8(%rip), %xmm0     # 0x10008
movq %r12, %rdi
callq 0x33e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq (%rbx), %rsi
movq %r14, %rdi
movl $0x8, %edx
callq 0x3490
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leaq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rcx)
leaq 0x90(%rsp), %rcx
movq %rax, 0x10(%rcx)
movapd %xmm0, (%rcx)
leaq 0x70(%rsp), %rcx
movq %rax, 0x10(%rcx)
movapd %xmm0, (%rcx)
leaq 0x50(%rsp), %rcx
movq %rax, 0x10(%rcx)
movapd %xmm0, (%rcx)
callq 0x31b0
movq %rax, 0xa8(%rsp)
leaq 0x30(%rsp), %rbx
leaq 0xc(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0xd0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x34a0
cmpq $0x0, 0x38(%rsp)
je 0xb501
movq %rbx, %rdi
movl $0x20, %esi
leaq 0x50(%rsp), %rdx
callq 0x5658
movq 0x50(%rsp), %r15
movq (%r15), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xb43a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xb44c
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0xf7ac
movq 0x50(%rsp), %r15
movq 0x20(%r15), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x98(%rsp), %rsi
cmpq 0xa0(%rsp), %rsi
je 0xb47b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x98(%rsp)
jmp 0xb490
leaq 0x90(%rsp), %rdi
movq %r12, %rdx
callq 0xf7ac
movq 0x50(%rsp), %r15
movq 0x40(%r15), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0xb4b9
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0xb4cb
leaq 0x70(%rsp), %rdi
movq %r12, %rdx
callq 0xf7ac
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbp
cmpq %r15, %rbp
je 0xb3cb
movq %r15, %r13
movq (%r13), %rdi
addq $0x10, %r13
cmpq %r13, %rdi
je 0xb4ee
callq 0x3260
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xb4dc
movq %r15, 0x58(%rsp)
jmp 0xb3c6
callq 0x31b0
movq %rax, %rbx
movq 0xaac8(%rip), %r14      # 0x15fd8
leaq 0x50e8(%rip), %rsi      # 0x105ff
movl $0x1a, %edx
movq %r14, %rdi
callq 0x32e0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xaa96(%rip), %rdi      # 0x15fd8
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0xaa82(%rip), %rdi      # 0x15fd8
leaq 0x50bd(%rip), %rsi      # 0x1061a
movl $0x16, %edx
callq 0x32e0
subq 0xa8(%rsp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
divsd 0x4a89(%rip), %xmm0     # 0x10008
movq 0xaa52(%rip), %rdi      # 0x15fd8
callq 0x33e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
leaq 0xd0(%rsp), %rdi
callq 0x3070
movslq 0xc(%r13), %rax
leaq (,%rax,4), %rbx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rbx, %rdi
callq 0x3030
movq %rax, 0xacb0(%rip)      # 0x16298
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3160
movq 0xa9dc(%rip), %rdi      # 0x15fd8
leaq 0x502e(%rip), %rsi      # 0x10631
movl $0x14, %edx
callq 0x32e0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movq 0xa9b6(%rip), %rdi      # 0x15fd8
callq 0x31c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movl $0x0, 0xac45(%rip)      # 0x162a0
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x33f0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
cmpq %rax, %rbx
je 0xb6d9
movq 0x90(%rsp), %r14
movslq (%rbx), %rcx
movslq (%r14), %rdx
cmpl %edx, %ecx
je 0xb6cc
movq 0xa8(%r13), %rsi
shlq $0x4, %rcx
movzwl 0x2(%rsi,%rcx), %edi
shlq $0x4, %rdx
cmpw 0x2(%rsi,%rdx), %di
jae 0xb6cc
addq %rsi, %rcx
addq %rsi, %rdx
movzwl (%rcx), %ecx
cmpw (%rdx), %cx
jbe 0xb6cc
incl 0xabe6(%rip)            # 0x162a0
movl (%rbx), %esi
movl (%r14), %edx
movq %r13, %rdi
callq 0xba64
movq 0x18(%rsp), %rax
addq $0x4, %rbx
addq $0x4, %r14
cmpq %rax, %rbx
jne 0xb681
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0x33f0
movq 0xa8e9(%rip), %rdi      # 0x15fd8
leaq 0x4b51(%rip), %rsi      # 0x10247
movl $0xb, %edx
callq 0x32e0
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
subq 0xc0(%rsp), %rax
cvtsi2sd %rax, %xmm0
subq 0xc8(%rsp), %rcx
cvtsi2sd %rcx, %xmm1
movsd 0x4cee(%rip), %xmm2     # 0x10420
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0xa893(%rip), %rdi      # 0x15fd8
callq 0x33e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movl $0x0, 0xab22(%rip)      # 0x162a0
movq 0xab13(%rip), %rdi      # 0x16298
movslq 0xc(%r13), %rdx
shlq $0x2, %rdx
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x3160
movq 0x10(%rsp), %r15
cmpq 0x18(%rsp), %r15
je 0xb904
xorl %r14d, %r14d
movq 0x90(%rsp), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq (%r15,%r14), %rcx
movslq (%r12,%r14), %rdx
movl $0x1, %eax
cmpl %edx, %ecx
je 0xb812
movq 0x28(%rsp), %rax
movq 0xa8(%rax), %rsi
shlq $0x4, %rcx
movzwl 0x2(%rsi,%rcx), %edi
shlq $0x4, %rdx
xorl %eax, %eax
cmpw 0x2(%rsi,%rdx), %di
jae 0xb812
addq %rsi, %rcx
addq %rsi, %rdx
movzwl (%rcx), %ecx
cmpw (%rdx), %cx
jbe 0xb812
incl 0xaaa3(%rip)            # 0x162a0
movl (%r15,%r14), %esi
movl (%r12,%r14), %edx
movq 0x28(%rsp), %rdi
callq 0xba64
movzbl %al, %eax
movq 0x70(%rsp), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%r14)
setne %dl
cmpl %edx, %eax
je 0xb8ea
movl $0x3, %edx
movq 0xa7a3(%rip), %rdi      # 0x15fd8
leaq 0x4e0a(%rip), %rsi      # 0x10646
callq 0x32e0
movq 0xa790(%rip), %rdi      # 0x15fd8
movl %r13d, %esi
callq 0x3440
movb $0x9, 0xc(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x32e0
movl (%r15,%r14), %esi
movq %rax, %rdi
callq 0x3440
movb $0x20, 0xc(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x32e0
movl (%r12,%r14), %esi
movq %rax, %rdi
callq 0x3440
movb $0x20, 0xc(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
callq 0x32e0
movq 0x70(%rsp), %rcx
movl (%rcx,%r14), %esi
movq %rax, %rdi
callq 0x3440
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
incl %ebp
incl %r13d
leaq (%r15,%r14), %rax
addq $0x4, %rax
addq $0x4, %r14
cmpq 0x18(%rsp), %rax
jne 0xb7b6
movq 0xa6cd(%rip), %rdi      # 0x15fd8
leaq 0x4d38(%rip), %rsi      # 0x1064a
movl $0xe, %edx
callq 0x32e0
movq 0xa6b5(%rip), %rdi      # 0x15fd8
movl %ebp, %esi
callq 0x3440
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0xa93d(%rip), %rdi      # 0x16298
testq %rdi, %rdi
leaq 0x40(%rsp), %rbx
je 0xb96a
callq 0x3320
leaq 0x50(%rsp), %rdi
callq 0xc1a8
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xb983
callq 0x3260
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xb995
callq 0x3260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xb9a4
callq 0x3260
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb9b3
callq 0x3260
leaq 0xd0(%rsp), %rdi
callq 0x3090
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xba5c
callq 0x3260
jmp 0xba5c
movq %rax, %rbx
jmp 0xba5c
jmp 0xb9fe
jmp 0xb9fe
jmp 0xb9fe
jmp 0xb9fe
jmp 0xb9fe
jmp 0xb9fe
movq %rax, %rbx
leaq 0x40(%rsp), %r14
leaq 0x50(%rsp), %rdi
callq 0xc1a8
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xba1f
callq 0x3260
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xba31
callq 0x3260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xba40
callq 0x3260
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0xba4f
callq 0x3260
leaq 0xd0(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460