// File: /workspace/github_cpp_makefile_star2_O2/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 0x7e4a
leaq -0x49(%rip), %r14       # 0x7a38
pushq $0xf
popq %rdi
movq %r14, %rsi
callq 0x32c0
pushq $0x2
popq %rdi
movq %r14, %rsi
callq 0x32c0
movq 0x8(%rbx), %rsi
leaq 0x78(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30c0
movq 0x10(%rbx), %rsi
leaq 0x38(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30c0
movq 0x18(%rbx), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x30c0
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x369c
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x20f8(%rip), %rsi      # 0x9bfa
leaq 0x38(%rsp), %rdi
callq 0x7f51
testb %al, %al
je 0x7b80
movq 0x58(%rsp), %rsi
leaq 0x138(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x7f5e
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
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 0x7ca6
testb $0x1, 0x77ee(%rip)      # 0xf35b
jne 0x7ca6
movq %r15, %rdi
movq %r14, %rsi
callq 0x3cc0
jmp 0x7b49
leaq 0x20b5(%rip), %rsi      # 0x9c3c
leaq 0x38(%rsp), %rdi
callq 0x7f51
testb %al, %al
je 0x7d1a
leaq 0x138(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x8044
leaq 0x150(%rsp), %rbx
movq %rsp, %r14
movq 0x7408(%rip), %r13      # 0xefc8
pushq $0xc
popq %r15
leaq 0x20a7(%rip), %rbp      # 0x9c72
leaq 0x140(%rsp), %rdi
callq 0x810a
testb %al, %al
jne 0x7de1
leaq 0x138(%rsp), %rdi
callq 0x805c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x66ce
movq %r13, %rdi
movq %r14, %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
movq %r14, %rdi
callq 0x3100
movq %r14, %r12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x81be
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
subq %rcx, %rax
cqto
idivq %r15
cmpq %r14, %rax
jbe 0x7c8e
movl 0x8(%rcx,%rbx), %esi
movq %r13, %rdi
callq 0x31b0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3240
movq (%rsp), %rcx
movl (%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x31b0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3240
movq (%rsp), %rcx
movl 0x4(%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x31b0
movq %rax, %rdi
callq 0x3130
incq %r14
addq $0xc, %rbx
jmp 0x7c26
movq %r12, %r14
movq %r12, %rdi
callq 0x6840
leaq 0x150(%rsp), %rbx
jmp 0x7bcb
xorl %r14d, %r14d
leaq 0x98(%rsp), %rbx
movl %r14d, %r14d
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %r14, %rax
jbe 0x7d00
movq %r14, %rax
shlq $0x5, %rax
addq %rax, %rsi
movq %rbx, %rdi
callq 0x8018
incl %r14d
testb %al, %al
jne 0x7cb1
leaq 0x1f1c(%rip), %rdi      # 0x9c06
leaq 0x1f2c(%rip), %rsi      # 0x9c1d
leaq 0x1f2d(%rip), %rcx      # 0x9c25
pushq $0x33
popq %rdx
callq 0x31a0
movq %rsp, %rdi
callq 0x3100
leaq 0x138(%rsp), %rdi
callq 0x8024
jmp 0x7e01
leaq 0x1f28(%rip), %rsi      # 0x9c49
leaq 0x38(%rsp), %rdi
callq 0x7f51
testb %al, %al
je 0x7df0
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0x4cf4
movq %rax, %rbx
movq %r14, %rdi
callq 0x4d84
movq %rax, %r14
movq 0x7270(%rip), %rdi      # 0xefc8
leaq 0x1ef2(%rip), %rsi      # 0x9c51
callq 0x3240
movq %rax, %rdi
movl %ebx, %esi
callq 0x3400
movq %rax, %rdi
callq 0x3130
movq 0x724b(%rip), %rdi      # 0xefc8
leaq 0x1edc(%rip), %rsi      # 0x9c60
callq 0x3240
movq %rax, %rdi
movl %r14d, %esi
callq 0x3400
movq %rax, %rdi
callq 0x3130
movq 0x7225(%rip), %rdi      # 0xefc8
leaq 0x1eca(%rip), %rsi      # 0x9c74
callq 0x3240
imull $0x64, %ebx, %ecx
cvtsi2sd %ecx, %xmm0
addl %ebx, %r14d
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
callq 0x3130
leaq 0x98(%rsp), %rdi
callq 0x38b8
jmp 0x7e01
leaq 0x138(%rsp), %rdi
callq 0x3d5e
jmp 0x7e01
leaq 0x1e91(%rip), %rsi      # 0x9c88
leaq 0x38(%rsp), %rdi
callq 0x7f51
leaq 0x20(%rsp), %rdi
callq 0x807a
leaq 0x98(%rsp), %rdi
callq 0x378c
leaq 0x58(%rsp), %rdi
callq 0x3100
leaq 0x38(%rsp), %rdi
callq 0x3100
leaq 0x78(%rsp), %rdi
callq 0x3100
xorl %eax, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x717f(%rip), %r14      # 0xefd0
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x1d42(%rip), %rsi      # 0x9ba0
xorl %eax, %eax
callq 0x3350
movq (%r14), %rcx
leaq 0x1d55(%rip), %rdi      # 0x9bc4
pushq $0xb
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x3490
movq (%r14), %rcx
leaq 0x1d49(%rip), %rdi      # 0x9bd0
pushq $0x15
popq %rsi
movq %rbx, %rdx
callq 0x3490
movq (%r14), %rcx
leaq 0x1d4a(%rip), %rdi      # 0x9be6
pushq $0x13
popq %rsi
movq %rbx, %rdx
callq 0x3490
xorl %edi, %edi
callq 0x32d0
jmp 0x7ec3
jmp 0x7ec3
jmp 0x7ec3
movq %rax, %rbx
jmp 0x7f2b
movq %rax, %rbx
jmp 0x7f35
movq %rax, %rbx
jmp 0x7f3f
movq %rax, %rbx
jmp 0x7f14
jmp 0x7edd
jmp 0x7edd
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3100
jmp 0x7f07
jmp 0x7ee2
jmp 0x7ee2
movq %rax, %rbx
jmp 0x7f07
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3100
leaq 0x138(%rsp), %rdi
callq 0x8024
jmp 0x7f14
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6840
leaq 0x138(%rsp), %rdi
callq 0x3d5e
leaq 0x20(%rsp), %rdi
callq 0x807a
leaq 0x98(%rsp), %rdi
callq 0x378c
leaq 0x58(%rsp), %rdi
callq 0x3100
leaq 0x38(%rsp), %rdi
callq 0x3100
leaq 0x78(%rsp), %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3420