// File: /workspace/github_cpp_makefile_star2_O2/ralgond[P]SortedListIntersection/main.cpp
// Function: main
int main(int argc, char* argv[]) {

	string file1 = argv[1];
	string file2 = argv[2];

	uint32_t a_len = 0;
	uint32_t* a = read_sorted_int_from_file(file1, &a_len);
	cout<<"file "<<file1<<": "<<a_len<<endl;

	uint32_t b_len = 0;
	uint32_t* b = read_sorted_int_from_file(file2, &b_len);
	cout<<"file "<<file2<<": "<<b_len<<endl;


	uint32_t rareLen = 0;
	uint32_t* rare = NULL;
	uint32_t freqLen = 0;
	uint32_t* freq = NULL;

	if (a_len < b_len) {
		rareLen = a_len;
		rare = a;
		freqLen = b_len;
		freq = b;
	} else {
		rareLen = b_len;
		rare = b;
		freqLen = a_len;
		freq = a;
	}


	uint32_t* c = new uint32_t[rareLen];

	uint32_t cnt = 0;

	bloom_filter* filter = create_bloom_filter(freq, freqLen);

	long time1, time2;

	int N = 10000;


	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = v1_avx2_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "v1_avx2\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = v3_avx2_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "v3_avx2\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = highlyscalable_SIMD_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "highlyscalable_SIMD\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;
	
	prepare_shuffling_dict32();
	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = highlyscalable_avx2_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "highlyscalable_avx2\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	prepare_shuffling_dict64();
	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = highlyscalable_avx512_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "highlyscalable_avx512\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;




	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = lemire_highlyscalable_SIMD_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "lemire_highlyscalable_SIMD\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = scalar(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "scalar\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = block_merge_intersection(freq, freqLen, rare, rareLen, c);
	time2 = currentTimeMs();
	cout << "block_merge\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

//	time1 = currentTimeMs();
//	for (int i = 0; i < 10000; i++)
//		cnt = bisearch_intersection(freq, freqLen, rare, rareLen, c);
//	time2 = currentTimeMs();
//	cout << "bisearch\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;
	
//	time1 = currentTimeMs();
//	for (int i = 0; i < 10000; i++)
//		cnt = bloomfilter_intersection(filter, freq, freqLen, rare, rareLen, c);
//	time2 = currentTimeMs();
//	cout << "bloom\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;
label1:
	prepare_shuffling_dict16();
	PrefixList* rarePl = buildPrefixList(rare, rareLen);
	PrefixList* freqPl = buildPrefixList(freq, freqLen);

	time1 = currentTimeMs();
	for (int i = 0; i < 10000; i++)
		cnt = intersectPrefixList(freqPl, rarePl, c);
	time2 = currentTimeMs();
	cout << "sttni\t" << (time2-time1) << "ms"<<"\t"<<qps(N, (time2-time1))<<"\t"<<cnt<<endl;

	//for (uint32_t i = 0; i < cnt; i++) {
	//	cout<<c[i]<<endl;
	//}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2b44
movq 0x10(%rbx), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x2b44
andl $0x0, 0x1c(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x21d0
leaq 0x88(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x4d38
leaq 0x88(%rsp), %rdi
movq %rax, %r14
callq 0x20b0
movq 0x4af8(%rip), %rdi      # 0x8fd8
leaq 0x2399(%rip), %rsi      # 0x6880
callq 0x21a0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x2170
leaq 0x2386(%rip), %rsi      # 0x6886
movq %rax, %rdi
callq 0x21a0
movl 0x1c(%rsp), %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
andl $0x0, 0x24(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x21d0
leaq 0x68(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0x4d38
leaq 0x68(%rsp), %rdi
movq %rax, %rbx
callq 0x20b0
movq 0x4a85(%rip), %rdi      # 0x8fd8
leaq 0x2326(%rip), %rsi      # 0x6880
callq 0x21a0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x2170
leaq 0x2313(%rip), %rsi      # 0x6886
movq %rax, %rdi
callq 0x21a0
movl 0x24(%rsp), %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
movl 0x24(%rsp), %r13d
movl 0x1c(%rsp), %eax
movq %r14, %r12
cmpl %r13d, %eax
movl %r13d, %ebp
cmovbq %rbx, %r12
cmovbq %r14, %rbx
cmovbl %eax, %r13d
cmoval %eax, %ebp
movq %rbx, 0x10(%rsp)
leaq (,%r13,4), %rdi
callq 0x2030
movq %rax, %r14
movq %r12, %rdi
movl %ebp, %esi
movl %ebp, 0x20(%rsp)
callq 0x2df3
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl 0x20(%rsp), %ebp
movl $0x2710, %ebx           # imm = 0x2710
xorl %r15d, %r15d
subl $0x1, %ebx
jb 0x4609
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x412c
movq %rax, %r15
jmp 0x45e9
callq 0x4fd4
movq 0x49c3(%rip), %rdi      # 0x8fd8
leaq 0x226d(%rip), %rsi      # 0x6889
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x2257(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x227e(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm0, %xmm0
vdivsd 0x1ae1(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x2211(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x224a(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x46c8
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x4214
movq %rax, %r15
jmp 0x46a8
callq 0x4fd4
movq 0x4904(%rip), %rdi      # 0x8fd8
leaq 0x21ba(%rip), %rsi      # 0x6895
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x2198(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x21bf(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm2, %xmm0
vdivsd 0x1a22(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x2152(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x218b(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x4787
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x395c
movq %rax, %r15
jmp 0x4767
callq 0x4fd4
movq 0x4845(%rip), %rdi      # 0x8fd8
leaq 0x2137(%rip), %rsi      # 0x68d1
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x20d9(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x2100(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm2, %xmm0
vdivsd 0x1963(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x2093(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x20cc(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x3c1c
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x484b
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x3c79
movq %rax, %r15
jmp 0x482b
callq 0x4fd4
movq 0x4781(%rip), %rdi      # 0x8fd8
leaq 0x2040(%rip), %rsi      # 0x689e
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x2015(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x203c(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm2, %xmm0
vdivsd 0x189f(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1fcf(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x2008(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x3e7c
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x490f
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x3ee8
movq %rax, %r15
jmp 0x48ef
callq 0x4fd4
movq 0x46bd(%rip), %rdi      # 0x8fd8
leaq 0x1f91(%rip), %rsi      # 0x68b3
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x1f51(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x1f78(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm2, %xmm0
vdivsd 0x17db(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1f0b(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x1f44(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x49ce
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x3abf
movq %rax, %r15
jmp 0x49ae
callq 0x4fd4
movq 0x45fe(%rip), %rdi      # 0x8fd8
leaq 0x1ee9(%rip), %rsi      # 0x68ca
movq %rax, %rbx
callq 0x21a0
subq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2180
leaq 0x1e92(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x1eb9(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbx, %xmm2, %xmm0
vdivsd 0x171c(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1e4c(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x1e85(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x4a8d
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r14, %r8
callq 0x4054
movq %rax, %r15
jmp 0x4a6d
callq 0x4fd4
movq 0x453f(%rip), %rdi      # 0x8fd8
leaq 0x1e46(%rip), %rsi      # 0x68e6
movq %rax, %rbp
callq 0x21a0
subq 0x8(%rsp), %rbp
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2180
leaq 0x1dd3(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x1dfa(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbp, %xmm2, %xmm0
vdivsd 0x165d(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1d8d(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x1dc6(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x4fd4
movq %rax, 0x8(%rsp)
movl $0x2710, %ebx           # imm = 0x2710
subl $0x1, %ebx
jb 0x4b4d
movl 0x20(%rsp), %esi
movq 0x10(%rsp), %rdx
movq %r12, %rdi
movl %r13d, %ecx
movq %r14, %r8
callq 0x2c78
movl %eax, %r15d
jmp 0x4b2c
callq 0x4fd4
movq 0x447f(%rip), %rdi      # 0x8fd8
leaq 0x1d8e(%rip), %rsi      # 0x68ee
movq %rax, %rbp
callq 0x21a0
subq 0x8(%rsp), %rbp
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2180
leaq 0x1d13(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x1d3a(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %rbp, %xmm2, %xmm0
vdivsd 0x159d(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1ccd(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x1d06(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
callq 0x27b4
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x245c
movl 0x20(%rsp), %esi
movq %r12, %rdi
movq %rax, %r13
callq 0x245c
movq %rax, %r12
callq 0x4fd4
movl $0x2710, %ebp           # imm = 0x2710
movq %rax, %rbx
subl $0x1, %ebp
jb 0x4c26
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2718
movl %eax, %r15d
jmp 0x4c0e
callq 0x4fd4
movq 0x43a6(%rip), %rdi      # 0x8fd8
leaq 0x1cc2(%rip), %rsi      # 0x68fb
movq %rax, %r14
callq 0x21a0
subq %rbx, %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x2180
leaq 0x1c3c(%rip), %rsi      # 0x6892
movq %rax, %rdi
callq 0x21a0
leaq 0x1c63(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
vcvtsi2sd %r14, %xmm2, %xmm0
vdivsd 0x14c6(%rip), %xmm0, %xmm0 # 0x6140
vmovsd 0x1bf6(%rip), %xmm1     # 0x6878
vdivsd %xmm0, %xmm1, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
movq %rax, %rdi
callq 0x2120
leaq 0x1c2f(%rip), %rsi      # 0x68c8
movq %rax, %rdi
callq 0x21a0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20b0
leaq 0x48(%rsp), %rdi
callq 0x20b0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
leaq 0x68(%rsp), %rdi
jmp 0x4cf1
leaq 0x88(%rsp), %rdi
movq %rax, %rbx
callq 0x20b0
jmp 0x4d1b
movq %rax, %rbx
jmp 0x4d25
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
jmp 0x4d18
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20b0
leaq 0x48(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2260
nop