// File: /workspace/github_cpp_makefile_star2_O3/davidgfnet[P]dns-db/main.cc
// Function: main
int main(int argc, char ** argv) {
	if (argc < 4) {
		fprintf(stderr, "Usage: %s dbpath command (args...)\n", argv[0]);
		fprintf(stderr, " Commands:\n");
		fprintf(stderr, "  * add-domains file\n");
		fprintf(stderr, "  * crawl bw(kbps)\n");
		exit(0);
	}

	signal(SIGTERM, sigterm);
	signal(SIGINT,  sigterm);

	std::string pathdb  = std::string(argv[1]);
	std::string command = std::string(argv[2]);
	std::string arg0    = std::string(argv[3]);

	DNS_DB db(pathdb);

	std::vector <std::string> check;
	
	if (command == "add-domains") {
		igzstream fin (arg0.c_str());
		std::string domain;
		while (fin >> domain && !doexit) {
			DNS_DB::queryError r = db.addDomain(domain);
			#ifdef EXTRA_CHECK
			assert(r == DNS_DB::resOK || r == DNS_DB::resAlreadyExists || r == DNS_DB::resDomainTooLong);
			if (r == DNS_DB::resOK)
				check.push_back(domain);
			#endif
		}

		for (unsigned int i = 0; i < check.size(); i++)
			assert(db.hasDomain(check[i]));
	}
	else if (command == "list-domains") {
		DNS_DB::DomainIterator it = db.getDomainIterator();
		while (!it.end()) {
			it.next();
			std::cout << it.getDomain() << std::endl;
			std::vector <IPv4_Record> r = it.getIpsv4();
			for (int i = 0; i < r.size(); i++) {
				std::cout << r[i].ip << " " << r[i].first_seen << " " << r[i].last_seen <<  std::endl;
			}
		}
	}
	else if (command == "summary") {
		int r = db.getNumberRecords();
		int f = db.getNumberFreeRecords();
		std::cout << "Total records " << r << std::endl;
		std::cout << "Total free records " << f << std::endl;
		std::cout << "Storage efficiency " << double(100*r)/(r+f) << std::endl;
		db.check();
	}
	else if (command == "crawl") {
		
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rsi, %rbx
cmpl $0x3, %edi
jle 0x893f
leaq -0x70(%rip), %r14       # 0x8344
movl $0xf, %edi
movq %r14, %rsi
callq 0x32c0
movl $0x2, %edi
movq %r14, %rsi
callq 0x32c0
movq 0x8(%rbx), %rsi
leaq 0x78(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30d0
movq 0x10(%rbx), %rsi
leaq 0x38(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30d0
movq 0x18(%rbx), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30d0
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x38dc
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x27ee(%rip), %rsi      # 0xac2a
leaq 0x38(%rsp), %rdi
callq 0x3070
testl %eax, %eax
je 0x8492
leaq 0x281b(%rip), %rsi      # 0xac6c
leaq 0x38(%rsp), %rdi
callq 0x3070
testl %eax, %eax
je 0x85a4
leaq 0x280f(%rip), %rsi      # 0xac79
leaq 0x38(%rsp), %rdi
callq 0x3070
testl %eax, %eax
je 0x878c
leaq 0x2835(%rip), %rsi      # 0xacb8
leaq 0x38(%rsp), %rdi
callq 0x3070
jmp 0x88b9
movq 0x58(%rsp), %rsi
leaq 0x138(%rsp), %rdi
movl $0x8, %edx
callq 0x8a24
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x2c0(%rsp), %rbx
movq %rsp, %r14
leaq 0x98(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32f0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x8503
testb $0x1, 0x6e57(%rip)      # 0xf34b
jne 0x8503
movq %r15, %rdi
movq %r14, %rsi
callq 0x4482
jmp 0x84d4
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x8550
movl $0x1, %ebp
leaq 0xd8(%rsp), %rbx
xorl %ecx, %ecx
shlq $0x5, %rcx
movq (%rax,%rcx), %rsi
movq %rbx, %rdi
callq 0x54e0
testb %al, %al
je 0x8920
movl %ebp, %ecx
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x851e
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x855e
callq 0x3220
leaq 0x668b(%rip), %rax      # 0xebf0
leaq 0x2d0(%rsp), %rbx
movq %rax, -0x10(%rbx)
leaq 0x66a0(%rip), %rax      # 0xec18
movq %rax, (%rbx)
movq $0x0, -0x8(%rbx)
leaq 0x65ce(%rip), %rsi      # 0xeb58
leaq 0x138(%rsp), %rdi
callq 0x9222
movq %rbx, %rdi
callq 0x30a0
jmp 0x88b9
leaq 0xd8(%rsp), %rsi
leaq 0x138(%rsp), %rdi
leaq 0x98(%rsp), %rcx
xorl %edx, %edx
callq 0x44dc
leaq 0x150(%rsp), %rbx
movq %rsp, %r12
movq 0x69f3(%rip), %r13      # 0xefc8
leaq 0x26c6(%rip), %rbp      # 0xaca2
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
movq %rbx, %rdi
callq 0x6f1e
testb %al, %al
je 0x8625
movl 0x140(%rsp), %eax
movq 0x148(%rsp), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq %rdx
movabsq $0x14c1bacf914c1bad, %rcx # imm = 0x14C1BACF914C1BAD
imulq %rcx, %rdx
decq %rdx
cmpq %rax, %rdx
je 0x877a
leaq 0x140(%rsp), %rdi
callq 0x8d3c
movq %rbx, %rdi
leaq 0x170(%rsp), %rsi
callq 0x7000
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6fa4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x3290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x869b
callq 0x3220
movq %r12, %rdi
movq %rbx, %rsi
callq 0x8dde
movq (%rsp), %rdi
cmpq %rdi, 0x8(%rsp)
je 0x875c
xorl %r12d, %r12d
xorl %ebx, %ebx
movl 0x8(%rdi,%r12), %esi
movq %r13, %rdi
callq 0x3190
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
movq (%rsp), %rax
movl (%rax,%r12), %esi
movq %r14, %rdi
callq 0x3190
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
movq (%rsp), %rax
movl 0x4(%rax,%r12), %esi
movq %r14, %rdi
callq 0x3190
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
incq %rbx
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
sarq $0x2, %rax
imulq %r15, %rax
addq $0xc, %r12
cmpq %rbx, %rax
ja 0x86ba
testq %rdi, %rdi
leaq 0x150(%rsp), %rbx
movq %rsp, %r12
je 0x85e6
callq 0x3220
jmp 0x85e6
leaq 0x138(%rsp), %rdi
callq 0x4540
jmp 0x88b9
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0x5794
movq %rax, %rbx
movq %r14, %rdi
callq 0x5858
movq %rax, %r14
movq 0x6817(%rip), %rdi      # 0xefc8
leaq 0x24c9(%rip), %rsi      # 0xac81
movl $0xe, %edx
callq 0x3290
movq 0x67ff(%rip), %rdi      # 0xefc8
movl %ebx, %esi
callq 0x33f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x67c7(%rip), %rdi      # 0xefc8
leaq 0x2488(%rip), %rsi      # 0xac90
movl $0x13, %edx
callq 0x3290
movq 0x67af(%rip), %rdi      # 0xefc8
movl %r14d, %esi
callq 0x33f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x6776(%rip), %rdi      # 0xefc8
leaq 0x244b(%rip), %rsi      # 0xaca4
movl $0x13, %edx
callq 0x3290
imull $0x64, %ebx, %eax
cvtsi2sd %eax, %xmm0
addl %ebx, %r14d
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
movq 0x674b(%rip), %rdi      # 0xefc8
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0x98(%rsp), %rdi
callq 0x3c2c
leaq 0x20(%rsp), %rdi
callq 0x8b62
leaq 0x98(%rsp), %rdi
callq 0x3a0a
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x88e3
callq 0x3220
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x88f6
callq 0x3220
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x890c
callq 0x3220
xorl %eax, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x230f(%rip), %rdi      # 0xac36
leaq 0x231f(%rip), %rsi      # 0xac4d
leaq 0x2320(%rip), %rcx      # 0xac55
movl $0x33, %edx
callq 0x3180
movq %rbx, %rdi
callq 0x36bc
jmp 0x8965
jmp 0x8965
jmp 0x8965
movq %rax, %rbx
jmp 0x89df
movq %rax, %rbx
jmp 0x89f2
movq %rax, %rbx
jmp 0x8a05
movq %rax, %rbx
jmp 0x89c8
jmp 0x896e
jmp 0x896e
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x897f
callq 0x3220
leaq 0x138(%rsp), %rdi
callq 0x8b1e
jmp 0x89c8
jmp 0x8992
jmp 0x8992
movq %rax, %rbx
jmp 0x89bb
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
jne 0x89b6
jmp 0x89bb
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x89bb
callq 0x3220
leaq 0x138(%rsp), %rdi
callq 0x4540
leaq 0x20(%rsp), %rdi
callq 0x8b62
leaq 0x98(%rsp), %rdi
callq 0x3a0a
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x89f2
callq 0x3220
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8a05
callq 0x3220
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8a1b
callq 0x3220
movq %rbx, %rdi
callq 0x3400
nop