// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]xpack/programs/benchmark.c
// Function: main
int
tmain(int argc, tchar *argv[])
{
	u32 chunk_size = 524288;
	int compression_level = 6;
	void *original_buf = NULL;
	void *compressed_buf = NULL;
	void *decompressed_buf = NULL;
	struct xpack_compressor *compressor = NULL;
	struct xpack_decompressor *decompressor = NULL;
	tchar *default_file_list[] = { NULL };
	int opt_char;
	int i;
	int ret;

	program_invocation_name = get_filename(argv[0]);

	while ((opt_char = tgetopt(argc, argv, optstring)) != -1) {
		switch (opt_char) {
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			compression_level = opt_char - '0';
			break;
		case 'h':
			show_usage(stdout);
			return 0;
		case 'L':
			compression_level = parse_compression_level(toptarg);
			if (compression_level <= 0)
				return 1;
			break;
		case 's':
			chunk_size = parse_chunk_size(toptarg);
			if (chunk_size == 0)
				return 1;
			break;
		case 'V':
			show_version();
			return 0;
		default:
			show_usage(stderr);
			return 1;
		}
	}

	argc -= toptind;
	argv += toptind;

	original_buf = xmalloc(chunk_size);
	compressed_buf = xmalloc(chunk_size - 1);
	decompressed_buf = xmalloc(chunk_size);
	compressor = alloc_compressor(chunk_size, compression_level);
	decompressor = alloc_decompressor();

	ret = -1;
	if (original_buf == NULL || compressed_buf == NULL ||
	    decompressed_buf == NULL ||
	    compressor == NULL || decompressor == NULL)
		goto out;

	if (argc == 0) {
		argv = default_file_list;
		argc = ARRAY_LEN(default_file_list);
	} else {
		for (i = 0; i < argc; i++)
			if (argv[i][0] == '-' && argv[i][1] == '\0')
				argv[i] = NULL;
	}

	printf("Benchmarking XPACK compression:\n");
	printf("\tChunk size: %"PRIu32"\n", chunk_size);
	printf("\tCompression level: %d\n", compression_level);

	for (i = 0; i < argc; i++) {
		struct file_stream in;

		ret = xopen_for_read(argv[i], &in);
		if (ret != 0)
			goto out;

		printf("Processing %"TS"...\n", in.name);

		ret = do_benchmark(&in, original_buf, compressed_buf,
				   decompressed_buf, chunk_size, compressor,
				   decompressor);
		xclose(&in);
		if (ret != 0)
			goto out;
	}
	ret = 0;
out:
	xpack_free_decompressor(decompressor);
	xpack_free_compressor(compressor);
	free(decompressed_buf);
	free(compressed_buf);
	free(original_buf);
	return -ret;
}

// Assembly:
subq $0x88, %rsp
movl $0x0, 0x84(%rsp)
movl %edi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl $0x80000, 0x74(%rsp)    # imm = 0x80000
movl $0x6, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x10d0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
callq 0x1cc0
movq %rax, %rcx
leaq 0x10dcd(%rip), %rax     # 0x120f0
movq %rcx, (%rax)
movl 0x80(%rsp), %edi
movq 0x78(%rsp), %rsi
leaq 0xddd7(%rip), %rdx      # 0xf110
callq 0x2570
movl %eax, 0x3c(%rsp)
cmpl $-0x1, %eax
je 0x1437
movl 0x3c(%rsp), %eax
addl $-0x31, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x42, %eax
ja 0x1413
movq 0x10(%rsp), %rax
leaq 0xdc96(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x3c(%rsp), %eax
subl $0x30, %eax
movl %eax, 0x70(%rsp)
jmp 0x1432
movq 0x10c4a(%rip), %rax     # 0x11fd8
movq (%rax), %rdi
callq 0x16b0
movl $0x0, 0x84(%rsp)
jmp 0x1698
leaq 0x10d63(%rip), %rax     # 0x12110
movq (%rax), %rdi
callq 0x2480
movl %eax, 0x70(%rsp)
cmpl $0x0, 0x70(%rsp)
jg 0x13d0
movl $0x1, 0x84(%rsp)
jmp 0x1698
jmp 0x1432
leaq 0x10d37(%rip), %rax     # 0x12110
movq (%rax), %rdi
callq 0x2400
movl %eax, 0x74(%rsp)
cmpl $0x0, 0x74(%rsp)
jne 0x13fc
movl $0x1, 0x84(%rsp)
jmp 0x1698
jmp 0x1432
callq 0x16e0
movl $0x0, 0x84(%rsp)
jmp 0x1698
movq 0x10bde(%rip), %rax     # 0x11ff8
movq (%rax), %rdi
callq 0x16b0
movl $0x1, 0x84(%rsp)
jmp 0x1698
jmp 0x1326
leaq 0x10ca2(%rip), %rax     # 0x120e0
movl (%rax), %ecx
movl 0x80(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x80(%rsp)
leaq 0x10c89(%rip), %rax     # 0x120e0
movl (%rax), %ecx
movq 0x78(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movl 0x74(%rsp), %eax
movl %eax, %edi
callq 0x1c30
movq %rax, 0x68(%rsp)
movl 0x74(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x1c30
movq %rax, 0x60(%rsp)
movl 0x74(%rsp), %eax
movl %eax, %edi
callq 0x1c30
movq %rax, 0x58(%rsp)
movl 0x74(%rsp), %edi
movl 0x70(%rsp), %esi
callq 0x24f0
movq %rax, 0x50(%rsp)
callq 0x2540
movq %rax, 0x48(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
cmpq $0x0, 0x68(%rsp)
je 0x14ee
cmpq $0x0, 0x60(%rsp)
je 0x14ee
cmpq $0x0, 0x58(%rsp)
je 0x14ee
cmpq $0x0, 0x50(%rsp)
je 0x14ee
cmpq $0x0, 0x48(%rsp)
jne 0x14f3
jmp 0x1659
cmpl $0x0, 0x80(%rsp)
jne 0x1514
leaq 0x40(%rsp), %rax
movq %rax, 0x78(%rsp)
movl $0x1, 0x80(%rsp)
jmp 0x1579
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x1577
movq 0x78(%rsp), %rax
movslq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x1568
movq 0x78(%rsp), %rax
movslq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x1568
movq 0x78(%rsp), %rax
movslq 0x38(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x156a
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x151c
jmp 0x1579
leaq 0xdba0(%rip), %rdi      # 0xf120
movb $0x0, %al
callq 0x10a0
movl 0x74(%rsp), %esi
leaq 0xdbaf(%rip), %rdi      # 0xf141
movb $0x0, %al
callq 0x10a0
movl 0x70(%rsp), %esi
leaq 0xdbae(%rip), %rdi      # 0xf152
movb $0x0, %al
callq 0x10a0
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x1651
movq 0x78(%rsp), %rax
movslq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1d10
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x15e9
jmp 0x1659
movq 0x20(%rsp), %rsi
leaq 0xdb75(%rip), %rdi      # 0xf16a
movb $0x0, %al
callq 0x10a0
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rcx
movl 0x74(%rsp), %r8d
movq 0x50(%rsp), %r9
movq 0x48(%rsp), %rax
leaq 0x18(%rsp), %rdi
movq %rax, (%rsp)
callq 0x1700
movl %eax, 0x34(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x2370
cmpl $0x0, 0x34(%rsp)
je 0x163f
jmp 0x1659
jmp 0x1641
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x15b3
movl $0x0, 0x34(%rsp)
movq 0x48(%rsp), %rdi
callq 0xec30
movq 0x50(%rsp), %rdi
callq 0x6970
movq 0x58(%rsp), %rdi
callq 0x1030
movq 0x60(%rsp), %rdi
callq 0x1030
movq 0x68(%rsp), %rdi
callq 0x1030
xorl %eax, %eax
subl 0x34(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw (%rax,%rax)