// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rdi, %r12
callq 0x31c0
movq %rax, %r14
movq (%r15), %rsi
leaq 0xd0(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x30f0
leaq 0xd0(%rsp), %rsi
movq %r12, 0x8(%rsp)
movq %r12, %rdi
callq 0x81d0
leaq 0xd0(%rsp), %rdi
callq 0x3120
callq 0x31c0
movq %rax, %r15
movq 0xc255(%rip), %r12      # 0x14fd8
leaq 0x57fe(%rip), %rsi      # 0xe588
movq %r12, %rdi
callq 0x3270
movq %rax, %rdi
callq 0x3140
leaq 0x54a6(%rip), %rsi      # 0xe247
movq %r12, %rdi
callq 0x3270
subq %r14, %r15
cvtsi2sd %r15, %xmm0
divsd 0x524f(%rip), %xmm0     # 0xe008
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
callq 0x3140
movq (%rbx), %rsi
leaq 0xd0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x3450
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
leaq 0x70(%rsp), %r13
andq $0x0, 0x10(%r13)
movapd %xmm0, (%rax)
movapd %xmm0, (%r13)
leaq 0x50(%rsp), %rbp
movapd %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0x30(%rsp), %r15
movapd %xmm0, (%r15)
andq $0x0, 0x10(%r15)
callq 0x31c0
movq %rax, 0x48(%rsp)
leaq 0x90(%rsp), %rbx
pushq $0x20
popq %r14
leaq 0x4(%rsp), %r12
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3060
cmpq $0x0, 0x98(%rsp)
je 0x8ed9
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x4b96
movq 0x30(%rsp), %rax
movq (%rax), %rdi
callq 0x33a0
movl %eax, 0x4(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0xd26a
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x33a0
movl %eax, 0x4(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xd26a
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x33a0
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xd26a
movq %r15, %rdi
callq 0x98a4
jmp 0x8e4b
callq 0x31c0
movq %rax, %rbx
movq 0xc0f0(%rip), %rdi      # 0x14fd8
leaq 0x56b0(%rip), %rsi      # 0xe59f
callq 0x3270
movq %rax, %rdi
callq 0x3140
movq 0xc0d5(%rip), %rdi      # 0x14fd8
leaq 0x56b0(%rip), %rsi      # 0xe5ba
callq 0x3270
subq 0x48(%rsp), %rbx
cvtsi2sd %rbx, %xmm0
divsd 0x50e7(%rip), %xmm0     # 0xe008
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
callq 0x3140
leaq 0xd0(%rsp), %rdi
callq 0x3070
movq 0x8(%rsp), %rax
movslq 0xc(%rax), %rax
leaq (,%rax,4), %rbx
testq %rax, %rax
pushq $-0x1
popq %rdi
cmovnsq %rbx, %rdi
callq 0x3030
movq %rax, 0xc323(%rip)      # 0x15288
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3170
movq 0xc05f(%rip), %rdi      # 0x14fd8
leaq 0x5651(%rip), %rsi      # 0xe5d1
callq 0x3270
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x3140
andl $0x0, 0xc2e6(%rip)      # 0x15290
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x33d0
movq 0x10(%rsp), %rbx
movq 0x70(%rsp), %r14
cmpq 0x18(%rsp), %rbx
je 0x9021
movslq (%rbx), %rax
movslq (%r14), %rcx
cmpl %ecx, %eax
je 0x9017
movq 0x8(%rsp), %rdx
movq 0xa8(%rdx), %rdx
shlq $0x4, %rax
movzwl 0x2(%rdx,%rax), %esi
shlq $0x4, %rcx
cmpw 0x2(%rdx,%rcx), %si
jae 0x9017
addq %rdx, %rax
addq %rdx, %rcx
movzwl (%rax), %eax
cmpw (%rcx), %ax
jbe 0x9017
incl 0xc288(%rip)            # 0x15290
movl (%rbx), %esi
movl (%r14), %edx
movq 0x8(%rsp), %rdi
callq 0x92b6
addq $0x4, %rbx
addq $0x4, %r14
jmp 0x8fc3
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0x33d0
movq 0xbfa1(%rip), %rdi      # 0x14fd8
leaq 0x5209(%rip), %rsi      # 0xe247
callq 0x3270
movq 0xb0(%rsp), %rcx
movq 0xb8(%rsp), %rdx
subq 0xc0(%rsp), %rcx
cvtsi2sd %rcx, %xmm0
subq 0xc8(%rsp), %rdx
cvtsi2sd %rdx, %xmm1
movsd 0x534b(%rip), %xmm2     # 0xe3c0
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
callq 0x3140
andl $0x0, 0xc1f8(%rip)      # 0x15290
movq 0xc1e9(%rip), %rdi      # 0x15288
movq 0x8(%rsp), %rax
movslq 0xc(%rax), %rdx
shlq $0x2, %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x3170
movq 0x10(%rsp), %rbx
movq 0x70(%rsp), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
leaq (%rbx,%r13), %r15
cmpq 0x18(%rsp), %r15
je 0x91bc
movslq (%r15), %rcx
movslq (%r12,%r13), %rdx
pushq $0x1
popq %rax
cmpl %edx, %ecx
je 0x912c
movq 0x8(%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 0x912c
addq %rsi, %rcx
addq %rsi, %rdx
movzwl (%rcx), %ecx
cmpw (%rdx), %cx
jbe 0x912c
incl 0xc178(%rip)            # 0x15290
movl (%r15), %esi
movl (%r12,%r13), %edx
movq 0x8(%rsp), %rdi
callq 0x92b6
movzbl %al, %eax
movq 0x50(%rsp), %rcx
xorl %edx, %edx
cmpl $0x0, (%rcx,%r13)
setne %dl
cmpl %edx, %eax
je 0x91b0
movq 0xbe92(%rip), %rdi      # 0x14fd8
leaq 0x5499(%rip), %rsi      # 0xe5e6
callq 0x3270
movq %rax, %rdi
movl %r14d, %esi
callq 0x3420
movq %rax, %rdi
pushq $0x9
popq %rsi
callq 0x32e0
movl (%r15), %esi
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x32e0
movl (%r12,%r13), %esi
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x32e0
movq 0x50(%rsp), %rcx
movl (%rcx,%r13), %esi
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
callq 0x3140
incl %ebp
addq $0x4, %r13
incl %r14d
jmp 0x90c5
movq 0xbe15(%rip), %rdi      # 0x14fd8
leaq 0x5420(%rip), %rsi      # 0xe5ea
callq 0x3270
movq %rax, %rdi
movl %ebp, %esi
callq 0x3420
movq %rax, %rdi
callq 0x3140
movq 0xc0a0(%rip), %rdi      # 0x15288
testq %rdi, %rdi
je 0x91f2
callq 0x3310
leaq 0x30(%rsp), %rdi
callq 0x98ac
leaq 0x50(%rsp), %rdi
callq 0xa406
leaq 0x70(%rsp), %rdi
callq 0xa406
leaq 0x10(%rsp), %rdi
callq 0xa406
leaq 0x90(%rsp), %rdi
callq 0x3120
leaq 0xd0(%rsp), %rdi
callq 0x30a0
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x3120
jmp 0x92ae
movq %rax, %rbx
jmp 0x92ae
jmp 0x9269
jmp 0x9269
jmp 0x9269
jmp 0x9269
jmp 0x9269
jmp 0x9269
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x98ac
leaq 0x50(%rsp), %rdi
callq 0xa406
leaq 0x70(%rsp), %rdi
callq 0xa406
leaq 0x10(%rsp), %rdi
callq 0xa406
leaq 0x90(%rsp), %rdi
callq 0x3120
leaq 0xd0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x3430