// File: davidgfnet[P]dns-db/dns_db.cc
// Function: DNS_DB::getNewBlock(int)
DNS_DB::DnsBlock * DNS_DB::getNewBlock(int blockid) {
	// Generate path in a hierachical way, to prevent many files in a directory
	// This should be beneficial on most file systems
	std::string filename = to_string(blockid,16);
	std::string dir1 = filename.substr(filename.size()-1,1) + "/";
	std::string dir2 = filename.substr(filename.size()-2,1) + "/";
	std::string blockfile = db_path + "/" + dir1 + dir2 + filename + ".blk";

	if (!FileMapper::getInstance().fileExists(blockfile)) {
		mkdir((db_path).c_str(),                           S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
		mkdir((db_path + "/" + dir1).c_str(),              S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
		mkdir((db_path + "/" + dir1 + "/" + dir2).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
	}

	return new DNS_DB::DnsBlock(blockfile, blockid);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
movl -0xc(%rbp), %esi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x228(%rbp)
movl $0x10, %edx
callq 0x49c0
movq -0x228(%rbp), %rdi
callq 0x4210
movq -0x228(%rbp), %rsi
movq %rax, %rdx
decq %rdx
leaq -0x70(%rbp), %rdi
movl $0x1, %ecx
callq 0x42d0
jmp 0x4b5e
leaq 0xe4a6(%rip), %rdx      # 0x1300b
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x55f0
jmp 0x4b74
leaq -0x70(%rbp), %rdi
callq 0x41c0
leaq -0x30(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x4210
movq -0x238(%rbp), %rsi
movq %rax, %rdx
addq $-0x2, %rdx
leaq -0xc0(%rbp), %rdi
movl $0x1, %ecx
callq 0x42d0
jmp 0x4bae
leaq 0xe456(%rip), %rdx      # 0x1300b
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x55f0
jmp 0x4bca
leaq -0xc0(%rbp), %rdi
callq 0x41c0
movq -0x230(%rbp), %rsi
addq $0x68, %rsi
leaq 0xe423(%rip), %rdx      # 0x1300b
leaq -0x160(%rbp), %rdi
callq 0x5390
jmp 0x4bf6
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x54c0
jmp 0x4c0f
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x54c0
jmp 0x4c2b
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x54c0
jmp 0x4c44
leaq 0xe3c2(%rip), %rdx      # 0x1300d
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x55f0
jmp 0x4c60
leaq -0x100(%rbp), %rdi
callq 0x41c0
leaq -0x120(%rbp), %rdi
callq 0x41c0
leaq -0x140(%rbp), %rdi
callq 0x41c0
leaq -0x160(%rbp), %rdi
callq 0x41c0
callq 0x5640
movq %rax, -0x240(%rbp)
jmp 0x4c9e
movq -0x240(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xde30
movb %al, -0x241(%rbp)
jmp 0x4cb9
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0x4f6a
jmp 0x4cc9
movq -0x230(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x250(%rbp)
callq 0x4100
movq %rax, %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x4140
movq -0x250(%rbp), %rsi
leaq 0xe310(%rip), %rdx      # 0x1300b
leaq -0x1a0(%rbp), %rdi
callq 0x5390
jmp 0x4d09
leaq -0x180(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x54c0
jmp 0x4d22
leaq -0x180(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x4100
movq %rax, %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x4140
movq -0x258(%rbp), %rdi
callq 0x41c0
leaq -0x1a0(%rbp), %rdi
callq 0x41c0
movq -0x230(%rbp), %rsi
addq $0x68, %rsi
leaq 0xe29f(%rip), %rdx      # 0x1300b
leaq -0x220(%rbp), %rdi
callq 0x5390
jmp 0x4d7a
leaq -0x200(%rbp), %rdi
leaq -0x220(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x54c0
jmp 0x4d93
leaq 0xe271(%rip), %rdx      # 0x1300b
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x55f0
jmp 0x4daf
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x54c0
jmp 0x4dcb
leaq -0x1c0(%rbp), %rdi
callq 0x4100
movq %rax, %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x4140
leaq -0x1c0(%rbp), %rdi
callq 0x41c0
leaq -0x1e0(%rbp), %rdi
callq 0x41c0
leaq -0x200(%rbp), %rdi
callq 0x41c0
leaq -0x220(%rbp), %rdi
callq 0x41c0
jmp 0x4f6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x5008
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x41c0
jmp 0x5008
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4fff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x41c0
jmp 0x4fff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4ff3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4edd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4ed1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4ec5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x41c0
leaq -0x120(%rbp), %rdi
callq 0x41c0
leaq -0x140(%rbp), %rdi
callq 0x41c0
leaq -0x160(%rbp), %rdi
callq 0x41c0
jmp 0x4ff3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4fe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x41c0
jmp 0x4fe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4f5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4f50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x41c0
leaq -0x200(%rbp), %rdi
callq 0x41c0
leaq -0x220(%rbp), %rdi
callq 0x41c0
jmp 0x4fe7
movl $0x28, %edi
callq 0x42c0
movq %rax, -0x260(%rbp)
jmp 0x4f7d
movq -0x260(%rbp), %rdi
movl -0xc(%rbp), %edx
leaq -0xe0(%rbp), %rsi
callq 0xa9c0
jmp 0x4f95
leaq -0xe0(%rbp), %rdi
callq 0x41c0
leaq -0xa0(%rbp), %rdi
callq 0x41c0
leaq -0x50(%rbp), %rdi
callq 0x41c0
leaq -0x30(%rbp), %rdi
callq 0x41c0
movq -0x260(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
movq -0x260(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x4290
leaq -0xe0(%rbp), %rdi
callq 0x41c0
leaq -0xa0(%rbp), %rdi
callq 0x41c0
leaq -0x50(%rbp), %rdi
callq 0x41c0
leaq -0x30(%rbp), %rdi
callq 0x41c0
movq -0x78(%rbp), %rdi
callq 0x44f0
nopw (%rax,%rax)