// File: /workspace/github_cpp_makefile_star2_O1/nmmmnu[P]HM3/hm3/main/db_merge.cc
// Function: main
int main(int argc, char **argv){
	if (argc <= 1 + 1 + 1){
		printUsage(argv[0]);
		return 1;
	}

	bool keepTombstones	= argv[1][0] == 't' ? false : true;
	const char *output	= argv[2];

	const char **path	= (const char **) &argv[3];
	int const pathc		= argc - 3;

	if (fileExists(output)){
		printf("File %s exists. Please remove it and try again.\n", output);
		return 2;
	}

	using DiskTable = hm3::DiskTable;

	if (pathc == 1){
		const char *filename = path[0];

		using MyMergeTable = DiskTable;

		MyMergeTable table;
		table.open(filename);

		printf("Merging (cleanup) single table...\n");
		printf("\t%s\n", filename);

		return merge(table, output, keepTombstones);

	}else if (pathc == 2){
		const char *filename1 = path[0];
		const char *filename2 = path[1];

		DiskTable table1;
		table1.open(filename1);

		DiskTable table2;
		table2.open(filename2);

		using MyMergeTable = hm3::DualTable<DiskTable, DiskTable>;

		// table 2 have precedence
		MyMergeTable table(table2, table1);

		printf("Merging two tables...\n");
		printf("\t%s\n", filename1);
		printf("\t%s\n", filename2);

		return merge(table, output, keepTombstones);

	}else{
		using ArgTableLoader = hm3::tableloader::ArgTableLoader;

		ArgTableLoader al { pathc, path };

		using MyMergeTable = hm3::LSMTable<ArgTableLoader::container_type>;

		MyMergeTable table( *al );

		printf("Merging multiple tables...\n");

		return merge(table, output, keepTombstones);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r14
cmpl $0x3, %edi
jg 0x25ab
movq (%r14), %rbx
leaq 0x5c07(%rip), %rdi      # 0x8146
callq 0x2270
leaq 0x5aef(%rip), %r14      # 0x803a
leaq 0x5b35(%rip), %rcx      # 0x8087
movq %r14, %rdi
movq %rbx, %rsi
movl $0x2d, %edx
xorl %eax, %eax
callq 0x2030
leaq 0x5b21(%rip), %rcx      # 0x808c
movq %r14, %rdi
movq %rbx, %rsi
movl $0x74, %edx
xorl %eax, %eax
callq 0x2030
leaq 0x5bc9(%rip), %rdi      # 0x814d
callq 0x2270
leaq 0x5be9(%rip), %rdi      # 0x8179
callq 0x2270
leaq 0x5bf1(%rip), %rdi      # 0x818d
callq 0x2270
movl $0x1, %ebx
jmp 0x293a
movl %edi, %ebp
movq 0x8(%r14), %rax
movq 0x10(%r14), %rbx
movb (%rax), %r12b
testq %rbx, %rbx
leaq 0x5a72(%rip), %r15      # 0x8034
movq %rbx, %rdi
cmoveq %r15, %rdi
xorl %esi, %esi
callq 0x22c0
cmpl $-0x1, %eax
je 0x25f0
leaq 0x5a28(%rip), %rdi      # 0x8004
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
movl $0x2, %ebx
jmp 0x293a
cmpl $0x5, %ebp
je 0x26e8
addq $0x18, %r14
cmpl $0x4, %ebp
jne 0x277b
movq (%r14), %r14
xorl %eax, %eax
movb %al, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movb %al, 0x20(%rsp)
movups %xmm0, 0x28(%rsp)
movups %xmm0, 0x38(%rsp)
movq $0x0, 0x48(%rsp)
movups %xmm0, 0x54(%rsp)
movl %eax, 0x64(%rsp)
movl $0x1, 0x6c(%rsp)
movups %xmm0, 0x70(%rsp)
movl %eax, 0x9c(%rsp)
movups %xmm0, 0x84(%rsp)
movl %eax, 0x94(%rsp)
movb $0x1, 0xa0(%rsp)
movups %xmm0, 0xa8(%rsp)
movups %xmm0, 0xb8(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
testq %r14, %r14
je 0x2692
movq %r14, %rdi
callq 0x20b0
movq %r14, %r15
leaq 0xf8(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, 0x8(%rsi)
leaq 0x8(%rsp), %rdi
callq 0x5c24
xorl %ebp, %ebp
cmpb $0x74, %r12b
setne %bpl
leaq 0x5a68(%rip), %rdi      # 0x8124
callq 0x2270
leaq 0x596d(%rip), %rdi      # 0x8035
movq %r14, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2988
movl %eax, %ebx
jmp 0x2930
movq 0x18(%r14), %r15
movq 0x20(%r14), %rbp
xorl %eax, %eax
movb %al, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movb %al, 0x20(%rsp)
movups %xmm0, 0x28(%rsp)
movups %xmm0, 0x38(%rsp)
movq $0x0, 0x48(%rsp)
movups %xmm0, 0x54(%rsp)
movl %eax, 0x64(%rsp)
movl $0x1, 0x6c(%rsp)
movups %xmm0, 0x70(%rsp)
movl %eax, 0x9c(%rsp)
movups %xmm0, 0x84(%rsp)
movl %eax, 0x94(%rsp)
movb $0x1, 0xa0(%rsp)
movups %xmm0, 0xa8(%rsp)
movups %xmm0, 0xb8(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
testq %r15, %r15
je 0x27d2
movq %r15, %rdi
callq 0x20b0
movq %r15, %rcx
jmp 0x27d9
addl $-0x3, %ebp
xorl %r15d, %r15d
cmpb $0x74, %r12b
setne %r15b
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x2a66
leaq 0x18(%rsp), %r14
leaq 0xf8(%rsp), %r12
movq %r14, (%r12)
leaq 0x5943(%rip), %rdi      # 0x80f3
callq 0x2270
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x2aa3
movl %eax, %ebx
movq %r14, %rdi
callq 0x2afe
jmp 0x293a
leaq 0x585b(%rip), %rcx      # 0x8034
leaq 0xf8(%rsp), %rsi
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x5c24
xorl %eax, %eax
movb %al, 0xf8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x100(%rsp)
movb %al, 0x110(%rsp)
movups %xmm0, 0x118(%rsp)
movups %xmm0, 0x128(%rsp)
movq $0x0, 0x138(%rsp)
movups %xmm0, 0x144(%rsp)
movl %eax, 0x154(%rsp)
movl $0x1, 0x15c(%rsp)
movups %xmm0, 0x160(%rsp)
movl %eax, 0x18c(%rsp)
movups %xmm0, 0x174(%rsp)
movl %eax, 0x184(%rsp)
movb $0x1, 0x190(%rsp)
movups %xmm0, 0x198(%rsp)
movups %xmm0, 0x1a8(%rsp)
movups %xmm0, 0x1b8(%rsp)
movups %xmm0, 0x1c8(%rsp)
testq %rbp, %rbp
movq %r15, (%rsp)
je 0x28a2
movq %rbp, %rdi
callq 0x20b0
movq %rbp, %rcx
jmp 0x28a9
leaq 0x578b(%rip), %rcx      # 0x8034
movq %rbp, %r15
leaq 0xe8(%rsp), %rsi
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
leaq 0xf8(%rsp), %r13
movq %r13, %rdi
callq 0x5c24
xorl %ebp, %ebp
cmpb $0x74, %r12b
setne %bpl
leaq 0xe8(%rsp), %r12
movq %r13, (%r12)
movq %r14, 0x8(%r12)
leaq 0x5821(%rip), %rdi      # 0x810e
callq 0x2270
leaq 0x573c(%rip), %r13      # 0x8035
movq %r13, %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2030
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2a16
movl %eax, %ebx
leaq 0xf8(%rsp), %rdi
callq 0x29d8
leaq 0x8(%rsp), %rdi
callq 0x29d8
movl %ebx, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2950
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x29d8
jmp 0x2976
jmp 0x2973
movq %rax, %rbx
movq %r14, %rdi
callq 0x2afe
jmp 0x2980
jmp 0x2973
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x29d8
movq %rbx, %rdi
callq 0x22f0