// File: /workspace/github_cpp_makefile_star2_O2/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 0x2561
movq (%r14), %rbx
leaq 0x4c47(%rip), %rdi      # 0x7146
callq 0x2270
leaq 0x4b2f(%rip), %r14      # 0x703a
leaq 0x4b75(%rip), %rcx      # 0x7087
pushq $0x2d
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x4b63(%rip), %rcx      # 0x708c
pushq $0x74
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x4c0d(%rip), %rdi      # 0x714d
callq 0x2270
leaq 0x4c2d(%rip), %rdi      # 0x7179
callq 0x2270
leaq 0x4c35(%rip), %rdi      # 0x718d
callq 0x2270
pushq $0x1
jmp 0x259d
movl %edi, %ebp
movq 0x8(%r14), %rax
movq 0x10(%r14), %rbx
movb (%rax), %r12b
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2922
movq %r15, %rdi
callq 0x290e
testb %al, %al
je 0x25b2
leaq 0x4a73(%rip), %rdi      # 0x7004
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
pushq $0x2
popq %rbx
movl %ebx, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x5, %ebp
je 0x26a3
addq $0x18, %r14
cmpl $0x4, %ebp
jne 0x287d
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)
andq $0x0, 0x48(%rsp)
movups %xmm0, 0x38(%rsp)
andl $0x0, 0x64(%rsp)
movups %xmm0, 0x54(%rsp)
movl $0x1, 0x6c(%rsp)
movups %xmm0, 0x70(%rsp)
andl $0x0, 0x9c(%rsp)
movups %xmm0, 0x84(%rsp)
andl $0x0, 0x94(%rsp)
movb $0x1, 0xa0(%rsp)
movups %xmm0, 0xa8(%rsp)
movups %xmm0, 0xb8(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
callq 0x2922
leaq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x53b4
xorl %ebp, %ebp
cmpb $0x74, %r12b
setne %bpl
leaq 0x4aad(%rip), %rdi      # 0x7124
callq 0x2270
leaq 0x49b2(%rip), %rdi      # 0x7035
movq %r14, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2951
movl %eax, %ebx
jmp 0x286e
movq 0x18(%r14), %r15
movq 0x20(%r14), %r14
xorl %eax, %eax
movb %al, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movb %al, 0x20(%rsp)
movups %xmm0, 0x28(%rsp)
andq $0x0, 0x48(%rsp)
movups %xmm0, 0x38(%rsp)
andl $0x0, 0x64(%rsp)
movups %xmm0, 0x54(%rsp)
movl $0x1, 0x6c(%rsp)
movups %xmm0, 0x70(%rsp)
andl $0x0, 0x9c(%rsp)
movups %xmm0, 0x84(%rsp)
andl $0x0, 0x94(%rsp)
movb $0x1, 0xa0(%rsp)
movups %xmm0, 0xa8(%rsp)
movups %xmm0, 0xb8(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x2922
leaq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x53b4
xorl %eax, %eax
movb %al, 0xf8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x100(%rsp)
movb %al, 0x110(%rsp)
movups %xmm0, 0x118(%rsp)
andq $0x0, 0x138(%rsp)
movups %xmm0, 0x128(%rsp)
andl $0x0, 0x154(%rsp)
movups %xmm0, 0x144(%rsp)
movl $0x1, 0x15c(%rsp)
movups %xmm0, 0x160(%rsp)
andl $0x0, 0x18c(%rsp)
movups %xmm0, 0x174(%rsp)
andl $0x0, 0x184(%rsp)
movb $0x1, 0x190(%rsp)
movups %xmm0, 0x198(%rsp)
movups %xmm0, 0x1a8(%rsp)
movups %xmm0, 0x1b8(%rsp)
movups %xmm0, 0x1c8(%rsp)
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq 0x2922
leaq 0xf8(%rsp), %r13
leaq 0xe8(%rsp), %rsi
movq %r13, %rdi
callq 0x53b4
xorl %ebp, %ebp
cmpb $0x74, %r12b
setne %bpl
leaq 0xe8(%rsp), %r12
movq %r13, (%r12)
leaq 0x8(%rsp), %rax
movq %rax, 0x8(%r12)
leaq 0x48e2(%rip), %rdi      # 0x710e
callq 0x2270
leaq 0x47fd(%rip), %r13      # 0x7035
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2030
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x29b9
movl %eax, %ebx
leaq 0xf8(%rsp), %rdi
callq 0x298a
leaq 0x8(%rsp), %rdi
callq 0x298a
jmp 0x259e
addl $-0x3, %ebp
xorl %r15d, %r15d
cmpb $0x74, %r12b
setne %r15b
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x29f2
leaq 0x18(%rsp), %r14
leaq 0xf8(%rsp), %r12
movq %r14, (%r12)
leaq 0x4841(%rip), %rdi      # 0x70f3
callq 0x2270
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x2a2c
movl %eax, %ebx
movq %r14, %rdi
callq 0x2a8e
jmp 0x259e
jmp 0x28e5
jmp 0x28f9
movq %rax, %rbx
movq %r14, %rdi
callq 0x2a8e
jmp 0x2906
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x298a
jmp 0x28fc
jmp 0x28f9
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x298a
movq %rbx, %rdi
callq 0x22f0