// File: /workspace/github_cpp_makefile_star2_O1/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 0xa44c
movq %r12, 0x28(%rsp)
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb37f
callq 0x3260
callq 0x31b0
movq %rax, %r13
movq 0xac4a(%rip), %r12      # 0x15fd8
leaq 0x5263(%rip), %rsi      # 0x105f8
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 0x4e82(%rip), %rsi      # 0x10253
movl $0xb, %edx
movq %r12, %rdi
callq 0x32e0
subq %r15, %r13
cvtsi2sd %r13, %xmm0
divsd 0x4c1a(%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 0xb5cf
movq %rbx, %rdi
movl $0x20, %esi
leaq 0x50(%rsp), %rdx
callq 0x5666
movq 0x50(%rsp), %rax
movq (%rax), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xb508
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xb515
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0xf8e8
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x98(%rsp), %rsi
cmpq 0xa0(%rsp), %rsi
je 0xb549
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x98(%rsp)
jmp 0xb559
leaq 0x90(%rsp), %rdi
movq %r12, %rdx
callq 0xf8e8
movq 0x50(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x33c0
movl %eax, 0xc(%rsp)
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0xb587
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0xb594
leaq 0x70(%rsp), %rdi
movq %r12, %rdx
callq 0xf8e8
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbp
cmpq %r15, %rbp
je 0xb499
movq %r15, %r13
movq (%r13), %rdi
addq $0x10, %r13
cmpq %r13, %rdi
je 0xb5bc
callq 0x3260
addq $0x10, %r13
cmpq %rbp, %r13
jne 0xb5aa
movq %r15, 0x58(%rsp)
jmp 0xb494
callq 0x31b0
movq %rax, %rbx
movq 0xa9fa(%rip), %r14      # 0x15fd8
leaq 0x502a(%rip), %rsi      # 0x1060f
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 0xa9c8(%rip), %rdi      # 0x15fd8
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0xa9b4(%rip), %rdi      # 0x15fd8
leaq 0x4fff(%rip), %rsi      # 0x1062a
movl $0x16, %edx
callq 0x32e0
subq 0xa8(%rsp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
divsd 0x49bb(%rip), %xmm0     # 0x10008
movq 0xa984(%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, 0xabe2(%rip)      # 0x16298
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3160
movq 0xa90e(%rip), %rdi      # 0x15fd8
leaq 0x4f70(%rip), %rsi      # 0x10641
movl $0x14, %edx
callq 0x32e0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movq 0xa8e8(%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, 0xab77(%rip)      # 0x162a0
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x33f0
movq 0x10(%rsp), %rbx
cmpq 0x18(%rsp), %rbx
je 0xb7a1
movq 0x90(%rsp), %r14
movslq (%rbx), %rax
movslq (%r14), %rcx
cmpl %ecx, %eax
je 0xb792
movq 0xa8(%r13), %rdx
shlq $0x4, %rax
movzwl 0x2(%rdx,%rax), %esi
shlq $0x4, %rcx
cmpw 0x2(%rdx,%rcx), %si
jae 0xb792
addq %rdx, %rax
addq %rdx, %rcx
movzwl (%rax), %eax
cmpw (%rcx), %ax
jbe 0xb792
incl 0xab1b(%rip)            # 0x162a0
movl (%rbx), %esi
movl (%r14), %edx
movq %r13, %rdi
callq 0xbb2c
addq $0x4, %rbx
addq $0x4, %r14
cmpq 0x18(%rsp), %rbx
jne 0xb74c
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0x33f0
movq 0xa821(%rip), %rdi      # 0x15fd8
leaq 0x4a95(%rip), %rsi      # 0x10253
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 0x4c36(%rip), %xmm2     # 0x10430
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0xa7cb(%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, 0xaa5a(%rip)      # 0x162a0
movq 0xaa4b(%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 0xb9cc
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 0xb8da
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 0xb8da
addq %rsi, %rcx
addq %rsi, %rdx
movzwl (%rcx), %ecx
cmpw (%rdx), %cx
jbe 0xb8da
incl 0xa9db(%rip)            # 0x162a0
movl (%r15,%r14), %esi
movl (%r12,%r14), %edx
movq 0x28(%rsp), %rdi
callq 0xbb2c
movzbl %al, %eax
movq 0x70(%rsp), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%r14)
setne %dl
cmpl %edx, %eax
je 0xb9b2
movl $0x3, %edx
movq 0xa6db(%rip), %rdi      # 0x15fd8
leaq 0x4d52(%rip), %rsi      # 0x10656
callq 0x32e0
movq 0xa6c8(%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 0xb87e
movq 0xa605(%rip), %rdi      # 0x15fd8
leaq 0x4c80(%rip), %rsi      # 0x1065a
movl $0xe, %edx
callq 0x32e0
movq 0xa5ed(%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 0xa875(%rip), %rdi      # 0x16298
testq %rdi, %rdi
leaq 0x40(%rsp), %rbx
je 0xba32
callq 0x3320
leaq 0x50(%rsp), %rdi
callq 0xc272
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xba4b
callq 0x3260
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xba5d
callq 0x3260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xba6c
callq 0x3260
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0xba7b
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 0xbb24
callq 0x3260
jmp 0xbb24
movq %rax, %rbx
jmp 0xbb24
jmp 0xbac6
jmp 0xbac6
jmp 0xbac6
jmp 0xbac6
jmp 0xbac6
jmp 0xbac6
movq %rax, %rbx
leaq 0x40(%rsp), %r14
leaq 0x50(%rsp), %rdi
callq 0xc272
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xbae7
callq 0x3260
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xbaf9
callq 0x3260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xbb08
callq 0x3260
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0xbb17
callq 0x3260
leaq 0xd0(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460