// File: dadocolussi[P]gdc-nanomap/demo/demo.cpp
// Function: main
int
main(int argc, char** argv)
{
	std::vector<int> input
	{
		1, 11, 111, 1111, 11111, 111111, 1111111, 11111111,
		2, 22, 222, 2222, 22222, 222222, 2222222, 22222222
	};
	std::vector<int> haystack(10 * 1000 * 1000);
	std::srand(9203854);
	std::generate(haystack.begin(), haystack.end(), []() { return std::rand(); });
	um um_needles;
	gdc::nanomap_factory<int, int, 16> factory;
	nm& nm_needles = factory.get();
	
	for (auto i : input)
	{
		um_needles[i] = i;
		nm_needles[i] = i;
	}
	
	// Warmup
	run_um(um_needles, haystack);
	run_um(um_needles, haystack);
	// Final run
	auto t0 = std::chrono::high_resolution_clock::now();
	run_um(um_needles, haystack);
	auto t1 = std::chrono::high_resolution_clock::now();
	auto duration_um = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0);
	std::cout << "unordered_map duration: " << duration_um.count() << " ms" << std::endl;
	
	run_nm(nm_needles, haystack);
	run_nm(nm_needles, haystack);
	t0 = std::chrono::high_resolution_clock::now();
	run_nm(nm_needles, haystack);
	t1 = std::chrono::high_resolution_clock::now();
	auto duration_nm = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0);
	std::cout << "gdc::nanomap duration: " << duration_nm.count() << " ms" << std::endl;
}

// Assembly:
subq $0x2a8, %rsp            # imm = 0x2A8
movl $0x0, 0x2a4(%rsp)
movl %edi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
movups 0x3ba0(%rip), %xmm0     # 0x5038
movaps %xmm0, 0x260(%rsp)
movups 0x3b81(%rip), %xmm0     # 0x5028
movaps %xmm0, 0x250(%rsp)
movups 0x3b62(%rip), %xmm0     # 0x5018
movaps %xmm0, 0x240(%rsp)
movups 0x3b43(%rip), %xmm0     # 0x5008
movaps %xmm0, 0x230(%rsp)
leaq 0x230(%rsp), %rax
movq %rax, 0x270(%rsp)
movq $0x10, 0x278(%rsp)
leaq 0x22f(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x1d60
movq 0xa0(%rsp), %rcx
movq 0x270(%rsp), %rsi
movq 0x278(%rsp), %rdx
leaq 0x280(%rsp), %rdi
callq 0x1d70
jmp 0x1525
leaq 0x22f(%rsp), %rdi
callq 0x1e00
leaq 0x1ff(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x1d60
movq 0x98(%rsp), %rdx
leaq 0x200(%rsp), %rdi
movl $0x989680, %esi         # imm = 0x989680
callq 0x1e10
jmp 0x1563
leaq 0x1ff(%rsp), %rdi
callq 0x1e00
movl $0x8c708e, %edi         # imm = 0x8C708E
callq 0x10f0
leaq 0x200(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x1e90
movq 0x90(%rsp), %rdi
movq %rax, 0x1f0(%rsp)
callq 0x1ec0
movq %rax, 0x1e8(%rsp)
movq 0x1f0(%rsp), %rdi
movq 0x1e8(%rsp), %rsi
callq 0x1a60
jmp 0x15c3
leaq 0x1a8(%rsp), %rdi
callq 0x1ef0
leaq 0x110(%rsp), %rdi
callq 0x1f00
jmp 0x15df
leaq 0x110(%rsp), %rdi
callq 0x1f30
movq %rax, 0x88(%rsp)
jmp 0x15f6
movq 0x88(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x280(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0x1e90
movq %rax, 0xf8(%rsp)
movq 0x100(%rsp), %rdi
callq 0x1ec0
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x1f40
testb $0x1, %al
jne 0x165e
jmp 0x1794
leaq 0xf8(%rsp), %rdi
callq 0x1f80
movl (%rax), %eax
movl %eax, 0xec(%rsp)
movl 0xec(%rsp), %eax
movl %eax, 0x7c(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0xec(%rsp), %rsi
callq 0x1f90
movq %rax, 0x80(%rsp)
jmp 0x169e
movq 0x80(%rsp), %rax
movl 0x7c(%rsp), %ecx
movl %ecx, (%rax)
movl 0xec(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x108(%rsp), %rdi
leaq 0xec(%rsp), %rsi
callq 0x1fc0
movq %rax, 0x70(%rsp)
jmp 0x16d3
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, (%rax)
leaq 0xf8(%rsp), %rdi
callq 0x2110
jmp 0x1640
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x22f(%rsp), %rdi
callq 0x1e00
jmp 0x1a4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x1ff(%rsp), %rdi
callq 0x1e00
jmp 0x1a41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0x1a34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0x1a27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x21c0
jmp 0x1a27
leaq 0x1a8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x1300
jmp 0x17ab
leaq 0x1a8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x1300
jmp 0x17c2
callq 0x1030
movq %rax, 0xe0(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x1300
jmp 0x17e6
callq 0x1030
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2160
movq %rax, 0x60(%rsp)
jmp 0x180f
movq 0x60(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x2130
movq %rax, 0x58(%rsp)
jmp 0x1830
movq 0x58(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x7794(%rip), %rdi      # 0x8fd8
leaq 0x37fd(%rip), %rsi      # 0x5048
callq 0x1100
movq %rax, 0x50(%rsp)
jmp 0x1857
leaq 0xd0(%rsp), %rdi
callq 0x21b0
movq %rax, 0x48(%rsp)
jmp 0x186b
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x11b0
movq %rax, 0x40(%rsp)
jmp 0x1881
movq 0x40(%rsp), %rdi
leaq 0x37d4(%rip), %rsi      # 0x5061
callq 0x1100
movq %rax, 0x38(%rsp)
jmp 0x1899
movq 0x38(%rsp), %rdi
movq 0x7713(%rip), %rsi      # 0x8fb8
callq 0x1130
jmp 0x18ac
movq 0x108(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x13c0
jmp 0x18c3
movq 0x108(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x13c0
jmp 0x18da
callq 0x1030
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x108(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x13c0
jmp 0x190e
callq 0x1030
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2160
movq %rax, 0x30(%rsp)
jmp 0x1947
movq 0x30(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x2130
movq %rax, 0x28(%rsp)
jmp 0x1968
movq 0x28(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x765c(%rip), %rdi      # 0x8fd8
leaq 0x36e2(%rip), %rsi      # 0x5065
callq 0x1100
movq %rax, 0x20(%rsp)
jmp 0x198f
leaq 0xb0(%rsp), %rdi
callq 0x21b0
movq %rax, 0x18(%rsp)
jmp 0x19a3
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x11b0
movq %rax, 0x10(%rsp)
jmp 0x19b9
movq 0x10(%rsp), %rdi
leaq 0x369c(%rip), %rsi      # 0x5061
callq 0x1100
movq %rax, 0x8(%rsp)
jmp 0x19d1
movq 0x8(%rsp), %rdi
movq 0x75db(%rip), %rsi      # 0x8fb8
callq 0x1130
jmp 0x19e4
leaq 0x110(%rsp), %rdi
callq 0x21c0
leaq 0x1a8(%rsp), %rdi
callq 0x21d0
leaq 0x200(%rsp), %rdi
callq 0x21e0
leaq 0x280(%rsp), %rdi
callq 0x21e0
movl 0x2a4(%rsp), %eax
addq $0x2a8, %rsp            # imm = 0x2A8
retq
leaq 0x1a8(%rsp), %rdi
callq 0x21d0
leaq 0x200(%rsp), %rdi
callq 0x21e0
leaq 0x280(%rsp), %rdi
callq 0x21e0
movq 0x220(%rsp), %rdi
callq 0x11a0
nopl (%rax,%rax)