// File: twekkel[P]mzpq/mzpq.cpp
// Function: main
int main(int argc, char **argv) {

	// Initialization
	int c = 0;
	bool conout   = false;
	bool compress = true;
	bool force    = false;
	bool keep     = false;
	bool name     = false;
	std::size_t found;
	std::string method = "4";
	std::string fname;
	std::string fnorg;

	// See how we are called and change defaults accordingly
	std::string filename = argv[0];
	found = filename.find_last_of("\\/");
	if ( std::string::npos != found ) filename.erase(0, found + 1);

	if ( filename.compare("unmzpq") == 0 ) {
		compress = false;
	} else if ( filename.compare("mzpqcat") == 0 ) {
		conout   = true;
		compress = false;
		keep     = true;
	}

	// Parse command line arguments
	while ((c = getopt (argc, argv, "123456789cdfhkm:NV")) != -1)
	switch(c)
	{
	case '1':
		method = "1";
		break;
	case '2':
		method = "2";
		break;
	case '3':
		method = "3";
		break;
	case '4':
		method = "4";
		break;
	case '5':
		method = "47";
		break;
	case '6':
		method = "51";
		break;
	case '7':
		method = "54";
		break;
	case '8':
		method = "57";
		break;
	case '9':
		method = "59";
		break;
	case 'c':
		conout = true;
		break;
	case 'd':
		compress = false;
		break;
	case 'f':
		force = true;
		break;
	case 'h':
		usage();
		break;
	case 'k':
		keep = true;
		break;
	case 'm':
		method = optarg;
		break;
	case 'N':
		name = true;
		break;
	case 'V':
		version();
		break;
	default:
		usage();
	}

	// Loop over the arguments/file names, at least once to cover stdin
	int i = optind;
	do {

		if ( argv[i] != NULL ) fname = argv[i];
		if ( fname.compare("-") == 0) fname.clear();
		fnorg = fname;

		// Try to read from file
		if ( ! fname.empty() && ! fexists(fname) ) {
			fprintf(stderr, "%s does not exists\n", fname.c_str());
			exit(1);
		}

		if ( ! fname.empty() ) {
			stdin = freopen( fname.c_str() , "r", stdin );
		}

		// Compress
		if ( compress && ! conout && ! fname.empty() ) {
			fname += suffix;
			if ( ! force && fexists(fname) ) {
				fprintf(stderr, "%s already exists\n", fname.c_str());
				return 1;
			}
			stdout = freopen(fname.c_str() , "w", stdout);
		}

		// Decompress
		if ( ! compress && ! conout && ! fname.empty() ) {
			found = fname.find(suffix);
			if ( found == std::string::npos ) {
				fprintf(stderr, "unknown suffix: %s\n", fname.c_str());
				exit(1);
			}
			fname = fname.substr( 0, found );
			if ( ! force && fexists(fname) ) {
				fprintf(stderr, "%s already exists\n", fname.c_str());
				return 1;
			}
			stdout = freopen(fname.c_str() , "w", stdout);
		}

		// Do the actual work
		if ( compress ) {
			libzpaq::compress(&in, &out, method.c_str(), name ? fnorg.c_str() : "");
		} else {
			libzpaq::decompress(&in, &out);
		}

		// Remove input file
		if ( ! keep ) remove(fnorg.c_str());

		// Next file
		i++;
	} while ( i < argc );

	// Flush output streams before exiting
	fflush(stdout);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
movb $0x1, -0x16(%rbp)
movb $0x0, -0x17(%rbp)
movb $0x0, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x54a0
movq -0x168(%rbp), %rdx
leaq 0x32873(%rip), %rsi     # 0x380a5
leaq -0x48(%rbp), %rdi
callq 0x6070
jmp 0x583d
leaq -0x49(%rbp), %rdi
callq 0x52c0
leaq -0x80(%rbp), %rdi
callq 0x53a0
leaq -0xa0(%rbp), %rdi
callq 0x53a0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x178(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x54a0
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x6070
jmp 0x5898
leaq -0xc1(%rbp), %rdi
callq 0x52c0
leaq -0xc0(%rbp), %rdi
leaq 0x2e9cc(%rip), %rsi     # 0x3427e
movq $-0x1, %rdx
callq 0x5240
movq %rax, -0x28(%rbp)
movq $-0x1, %rax
cmpq -0x28(%rbp), %rax
je 0x593e
movq -0x28(%rbp), %rdx
incq %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x5090
jmp 0x58e8
jmp 0x593e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x52c0
jmp 0x6060
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x52c0
jmp 0x6042
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5548
jmp 0x6042
leaq -0xc0(%rbp), %rdi
leaq 0x2e935(%rip), %rsi     # 0x34281
callq 0x50c0
cmpl $0x0, %eax
jne 0x595c
movb $0x0, -0x16(%rbp)
jmp 0x5982
leaq -0xc0(%rbp), %rdi
leaq 0x2e91e(%rip), %rsi     # 0x34288
callq 0x50c0
cmpl $0x0, %eax
jne 0x5980
movb $0x1, -0x15(%rbp)
movb $0x0, -0x16(%rbp)
movb $0x1, -0x18(%rbp)
jmp 0x5982
jmp 0x5984
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2e8fe(%rip), %rdx     # 0x34290
callq 0x5080
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x5aed
movl -0x14(%rbp), %eax
addl $-0x31, %eax
movl %eax, %ecx
movq %rcx, -0x180(%rbp)
subl $0x3c, %eax
ja 0x5adf
movq -0x180(%rbp), %rax
leaq 0x2e63b(%rip), %rcx     # 0x34004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x32d76(%rip), %rsi     # 0x3874f
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x59e4
jmp 0x5ae8
leaq 0x35445(%rip), %rsi     # 0x3ae35
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x59fb
jmp 0x5ae8
leaq 0x3544a(%rip), %rsi     # 0x3ae51
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a12
jmp 0x5ae8
leaq 0x32687(%rip), %rsi     # 0x380a5
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a29
jmp 0x5ae8
leaq 0x2e86e(%rip), %rsi     # 0x342a3
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a40
jmp 0x5ae8
leaq 0x2e85a(%rip), %rsi     # 0x342a6
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a57
jmp 0x5ae8
leaq 0x2e846(%rip), %rsi     # 0x342a9
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a6e
jmp 0x5ae8
leaq 0x2e835(%rip), %rsi     # 0x342ac
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a82
jmp 0x5ae8
leaq 0x2e824(%rip), %rsi     # 0x342af
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5a96
jmp 0x5ae8
movb $0x1, -0x15(%rbp)
jmp 0x5ae8
movb $0x0, -0x16(%rbp)
jmp 0x5ae8
movb $0x1, -0x17(%rbp)
jmp 0x5ae8
callq 0x5790
jmp 0x5ab1
jmp 0x5ae8
movb $0x1, -0x18(%rbp)
jmp 0x5ae8
movq 0x3b4f8(%rip), %rax     # 0x40fb8
movq (%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x5390
jmp 0x5ace
jmp 0x5ae8
movb $0x1, -0x19(%rbp)
jmp 0x5ae8
callq 0x57b0
jmp 0x5add
jmp 0x5ae8
callq 0x5790
jmp 0x5ae6
jmp 0x5ae8
jmp 0x5984
movq 0x3b4ec(%rip), %rax     # 0x40fe0
movl (%rax), %eax
movl %eax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movslq -0xc8(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5b2a
movq -0x10(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x80(%rbp), %rdi
callq 0x5390
jmp 0x5b28
jmp 0x5b2a
leaq -0x80(%rbp), %rdi
leaq 0x32723(%rip), %rsi     # 0x38258
callq 0x50c0
cmpl $0x0, %eax
jne 0x5b48
leaq -0x80(%rbp), %rdi
callq 0x5370
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5040
jmp 0x5b5a
leaq -0x80(%rbp), %rdi
callq 0x5460
movb %al, %cl
movb $0x0, -0xe9(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x181(%rbp)
jne 0x5ba6
leaq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5120
jmp 0x5b8b
movb $0x1, -0xe9(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x5760
xorb $-0x1, %al
movb %al, -0x181(%rbp)
movb -0x181(%rbp), %al
movb %al, -0x182(%rbp)
testb $0x1, -0xe9(%rbp)
jne 0x5bbd
jmp 0x5bc9
leaq -0xe8(%rbp), %rdi
callq 0x5548
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x5bd5
jmp 0x5c11
movq 0x3b3fc(%rip), %rax     # 0x40fd8
movq (%rax), %rax
movq %rax, -0x190(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5110
movq -0x190(%rbp), %rdi
movq %rax, %rdx
leaq 0x2e6b2(%rip), %rsi     # 0x342b2
movb $0x0, %al
callq 0x53d0
movl $0x1, %edi
callq 0x5330
leaq -0x80(%rbp), %rdi
callq 0x5460
testb $0x1, %al
jne 0x5c5a
leaq -0x80(%rbp), %rdi
callq 0x5110
movq %rax, %rdi
movq 0x3b39f(%rip), %rax     # 0x40fd0
movq (%rax), %rdx
leaq 0x32628(%rip), %rsi     # 0x38263
callq 0x52b0
movq %rax, -0x198(%rbp)
jmp 0x5c49
movq -0x198(%rbp), %rcx
movq 0x3b379(%rip), %rax     # 0x40fd0
movq %rcx, (%rax)
testb $0x1, -0x16(%rbp)
je 0x5d86
testb $0x1, -0x15(%rbp)
jne 0x5d86
leaq -0x80(%rbp), %rdi
callq 0x5460
testb $0x1, %al
jne 0x5d86
leaq 0x3c6da(%rip), %rsi     # 0x42360
leaq -0x80(%rbp), %rdi
callq 0x5360
jmp 0x5c91
movb -0x17(%rbp), %cl
movb $0x0, -0x111(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x199(%rbp)
jne 0x5cd3
leaq -0x110(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5120
jmp 0x5cba
movb $0x1, -0x111(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x5760
movb %al, -0x199(%rbp)
movb -0x199(%rbp), %al
movb %al, -0x19a(%rbp)
testb $0x1, -0x111(%rbp)
jne 0x5cea
jmp 0x5cf6
leaq -0x110(%rbp), %rdi
callq 0x5548
movb -0x19a(%rbp), %al
testb $0x1, %al
jne 0x5d02
jmp 0x5d4a
movq 0x3b2cf(%rip), %rax     # 0x40fd8
movq (%rax), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5110
movq -0x1a8(%rbp), %rdi
movq %rax, %rdx
leaq 0x2e599(%rip), %rsi     # 0x342c6
movb $0x0, %al
callq 0x53d0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x118(%rbp)
jmp 0x600c
leaq -0x80(%rbp), %rdi
callq 0x5110
movq %rax, %rdi
movq 0x3b24b(%rip), %rax     # 0x40fa8
movq (%rax), %rdx
leaq 0x3290c(%rip), %rsi     # 0x38673
callq 0x52b0
movq %rax, -0x1b0(%rbp)
jmp 0x5d75
movq -0x1b0(%rbp), %rcx
movq 0x3b225(%rip), %rax     # 0x40fa8
movq %rcx, (%rax)
testb $0x1, -0x16(%rbp)
jne 0x5f31
testb $0x1, -0x15(%rbp)
jne 0x5f31
leaq -0x80(%rbp), %rdi
callq 0x5460
testb $0x1, %al
jne 0x5f31
leaq -0x80(%rbp), %rdi
leaq 0x3c5aa(%rip), %rsi     # 0x42360
xorl %eax, %eax
movl %eax, %edx
callq 0x5530
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x28(%rbp)
jne 0x5e06
movq 0x3b207(%rip), %rax     # 0x40fd8
movq (%rax), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5110
movq -0x1b8(%rbp), %rdi
movq %rax, %rdx
leaq 0x2e4e4(%rip), %rsi     # 0x342d9
movb $0x0, %al
callq 0x53d0
movl $0x1, %edi
callq 0x5330
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x138(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5290
jmp 0x5e20
leaq -0x80(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5340
leaq -0x138(%rbp), %rdi
callq 0x5548
movb -0x17(%rbp), %cl
movb $0x0, -0x159(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1b9(%rbp)
jne 0x5e7e
leaq -0x158(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5120
jmp 0x5e65
movb $0x1, -0x159(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x5760
movb %al, -0x1b9(%rbp)
movb -0x1b9(%rbp), %al
movb %al, -0x1ba(%rbp)
testb $0x1, -0x159(%rbp)
jne 0x5e95
jmp 0x5ea1
leaq -0x158(%rbp), %rdi
callq 0x5548
movb -0x1ba(%rbp), %al
testb $0x1, %al
jne 0x5ead
jmp 0x5ef5
movq 0x3b124(%rip), %rax     # 0x40fd8
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x5110
movq -0x1c8(%rbp), %rdi
movq %rax, %rdx
leaq 0x2e3ee(%rip), %rsi     # 0x342c6
movb $0x0, %al
callq 0x53d0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x118(%rbp)
jmp 0x600c
leaq -0x80(%rbp), %rdi
callq 0x5110
movq %rax, %rdi
movq 0x3b0a0(%rip), %rax     # 0x40fa8
movq (%rax), %rdx
leaq 0x32761(%rip), %rsi     # 0x38673
callq 0x52b0
movq %rax, -0x1d0(%rbp)
jmp 0x5f20
movq -0x1d0(%rbp), %rcx
movq 0x3b07a(%rip), %rax     # 0x40fa8
movq %rcx, (%rax)
testb $0x1, -0x16(%rbp)
je 0x5fa2
leaq -0x48(%rbp), %rdi
callq 0x5110
movq %rax, -0x1d8(%rbp)
testb $0x1, -0x19(%rbp)
je 0x5f62
leaq -0xa0(%rbp), %rdi
callq 0x5110
movq %rax, -0x1e0(%rbp)
jmp 0x5f72
leaq 0x32bdb(%rip), %rax     # 0x38b44
movq %rax, -0x1e0(%rbp)
jmp 0x5f72
movq -0x1d8(%rbp), %rdx
movq -0x1e0(%rbp), %rcx
leaq 0x3b329(%rip), %rdi     # 0x412b0
leaq 0x3b32a(%rip), %rsi     # 0x412b8
xorl %eax, %eax
movl %eax, %r8d
movl $0x1, %r9d
callq 0x168d0
jmp 0x5fa0
jmp 0x5fb9
leaq 0x3b307(%rip), %rdi     # 0x412b0
leaq 0x3b308(%rip), %rsi     # 0x412b8
callq 0x14370
jmp 0x5fb7
jmp 0x5fb9
testb $0x1, -0x18(%rbp)
jne 0x5fd3
leaq -0xa0(%rbp), %rdi
callq 0x5110
movq %rax, %rdi
callq 0x54e0
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0x8(%rbp), %eax
jl 0x5afc
movq 0x3afb0(%rip), %rax     # 0x40fa8
movq (%rax), %rdi
callq 0x5300
jmp 0x6002
movl $0x0, -0x118(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5548
leaq -0xa0(%rbp), %rdi
callq 0x5548
leaq -0x80(%rbp), %rdi
callq 0x5548
leaq -0x48(%rbp), %rdi
callq 0x5548
movl -0x4(%rbp), %eax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x5548
leaq -0x80(%rbp), %rdi
callq 0x5548
leaq -0x48(%rbp), %rdi
callq 0x5548
movq -0x58(%rbp), %rdi
callq 0x5490
nopl (%rax)