// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r13
movl %edi, %r15d
andq $0x0, 0x90(%rsp)
movq (%rsi), %rdi
callq 0x1a07
leaq 0x7e15(%rip), %rcx      # 0x9100
movq %rax, (%rcx)
pushq $0x6
popq %r12
movl $0x80000, %eax          # imm = 0x80000
movq %rax, 0x8(%rsp)
leaq 0x4d01(%rip), %rbx      # 0x6004
leaq 0x7e16(%rip), %r14      # 0x9120
pushq $0x1
popq %rbp
movl %r15d, %edi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1ec8
leal -0x31(%rax), %ecx
cmpl $0x9, %ecx
jae 0x132b
addl $-0x30, %eax
movl %eax, %r12d
jmp 0x130d
cmpl $0x4c, %eax
jne 0x1344
movq (%r14), %rdi
callq 0x1e2d
movl %eax, %r12d
testl %eax, %eax
jg 0x130d
jmp 0x17d0
cmpl $-0x1, %eax
je 0x137a
cmpl $0x56, %eax
je 0x1440
cmpl $0x68, %eax
je 0x142f
cmpl $0x73, %eax
jne 0x1453
movq (%r14), %rdi
callq 0x1de2
movq %rax, 0x8(%rsp)
testl %eax, %eax
jne 0x130d
jmp 0x17d0
leaq 0x7d6f(%rip), %rax      # 0x90f0
movslq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %r14
movl %r14d, %ebx
movq %rbx, %rdi
callq 0x19a0
movq %rax, %rbp
leal -0x1(%r14), %edi
callq 0x19a0
movq %rax, (%rsp)
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x19a0
movq %rax, 0x20(%rsp)
movl %r14d, %edi
movl %r12d, %esi
callq 0x1e74
movq %rax, %rbx
callq 0x1ea5
movq %rbp, %xmm0
movq (%rsp), %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %rbx, 0x48(%rsp)
movq %rbx, %xmm1
movq 0x20(%rsp), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
pxor %xmm1, %xmm1
movq %rax, 0x40(%rsp)
testq %rax, %rax
sete %al
pcmpeqd %xmm1, %xmm0
pcmpeqd %xmm1, %xmm2
movdqa %xmm0, %xmm1
shufps $0xdd, %xmm2, %xmm1     # xmm1 = xmm1[1,3],xmm2[1,3]
shufps $0x88, %xmm2, %xmm0     # xmm0 = xmm0[0,2],xmm2[0,2]
andps %xmm1, %xmm0
movmskps %xmm0, %ecx
testl %ecx, %ecx
setne %cl
orb %al, %cl
je 0x1467
pushq $-0x1
popq %r14
movq (%rsp), %r13
jmp 0x179c
movq 0x7ba2(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x17e4
jmp 0x144c
leaq 0x4e5f(%rip), %rdi      # 0x62a6
callq 0x1060
xorl %ebp, %ebp
jmp 0x17d0
movq 0x7b9e(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
callq 0x17e4
jmp 0x17d0
movq 0x28(%rsp), %rax
subl %eax, %r15d
je 0x14ac
leaq (,%rax,8), %r14
addq %r13, %r14
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq (%rsp), %r13
cmpq %rax, %rcx
je 0x14bc
movq (%r14,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x14a7
cmpb $0x0, 0x1(%rdx)
jne 0x14a7
andq $0x0, (%r14,%rax,8)
incq %rax
jmp 0x148e
leaq 0x90(%rsp), %r14
pushq $0x1
popq %r15
movq (%rsp), %r13
leaq 0x4dc3(%rip), %rdi      # 0x6286
callq 0x1060
leaq 0x4b45(%rip), %rdi      # 0x6014
xorl %ebx, %ebx
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x10b0
leaq 0x4b41(%rip), %rdi      # 0x6025
movl %r12d, %esi
xorl %eax, %eax
callq 0x10b0
testl %r15d, %r15d
cmovlel %ebx, %r15d
xorl %eax, %eax
movq %rbp, 0x18(%rsp)
movq %r15, 0x38(%rsp)
movq %r14, 0x58(%rsp)
cmpq %r15, %rax
je 0x1794
movq %rax, 0x60(%rsp)
movq (%r14,%rax,8), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1a23
testl %eax, %eax
jne 0x1799
movq 0x80(%rsp), %rsi
leaq 0x4b04(%rip), %rdi      # 0x603d
xorl %eax, %eax
callq 0x10b0
xorl %r12d, %r12d
xorl %ebx, %ebx
movq $0x0, 0x50(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
movq 0x68(%rsp), %rdx
callq 0x1c23
movq %rax, %r14
testq %rax, %rax
jle 0x164d
movq %rbx, 0x8(%rsp)
movl %r14d, %ebx
callq 0x19dd
movq %rax, 0x28(%rsp)
leal -0x1(%r14), %r8d
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x3709
movq %rax, %r14
callq 0x19dd
movq %rax, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %r14
je 0x162e
movq %rcx, 0x70(%rsp)
movq %r12, %rbp
callq 0x19dd
movq %rax, %r12
movq 0x40(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x49dc
movl %eax, 0x34(%rsp)
callq 0x19dd
cmpl $0x0, 0x34(%rsp)
jne 0x171a
movq %rax, %r13
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1160
testl %eax, %eax
movq 0x38(%rsp), %r15
jne 0x173d
subq %r12, %rbp
movq %rbp, %r12
addq %r13, %r12
movq 0x18(%rsp), %rbp
movq (%rsp), %r13
movq 0x70(%rsp), %rcx
jmp 0x1631
movq %rbx, %r14
addq %rbx, 0x10(%rsp)
movq 0x8(%rsp), %rbx
subq 0x28(%rsp), %rbx
addq %rcx, %rbx
addq %r14, 0x50(%rsp)
jmp 0x1557
js 0x1762
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x1783
cmpq $0x1, %rbx
adcq $0x0, %rbx
cmpq $0x1, %r12
adcq $0x0, %r12
movq 0x50(%rsp), %r9
imulq $0x64, %r9, %rax
xorl %r14d, %r14d
xorl %edx, %edx
divq %rsi
movq %rax, %rcx
imulq $0x186a0, %r9, %rax     # imm = 0x186A0
xorl %edx, %edx
divq %rsi
xorl %edx, %edx
movq %rsi, %r10
movq %rsi, 0x10(%rsp)
movl $0x3e8, %esi            # imm = 0x3E8
divq %rsi
movq %rdx, %r8
leaq 0x4b61(%rip), %rdi      # 0x620e
movq %r10, %rsi
movq %r9, %rdx
xorl %eax, %eax
callq 0x10b0
movq %rbx, %rax
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divq %rcx
movq %rax, %rsi
movq %rbx, %rcx
imulq $0x3e8, 0x10(%rsp), %rbx # imm = 0x3E8
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
leaq 0x4b53(%rip), %rdi      # 0x6238
movq %rax, %rdx
xorl %eax, %eax
callq 0x10b0
movq %r12, %rax
xorl %edx, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
divq %rcx
movq %rax, %rsi
movq %rbx, %rax
xorl %edx, %edx
divq %r12
leaq 0x4b50(%rip), %rdi      # 0x625e
movq %rax, %rdx
xorl %eax, %eax
callq 0x10b0
jmp 0x1762
movq 0x80(%rsp), %rsi
leaq 0x4a9f(%rip), %rdi      # 0x61c8
xorl %eax, %eax
callq 0x17fc
pushq $-0x1
popq %rax
movl %eax, %r14d
movq 0x38(%rsp), %r15
jmp 0x1759
movq 0x80(%rsp), %rsi
leaq 0x4a9a(%rip), %rdi      # 0x61e6
xorl %eax, %eax
callq 0x17fc
pushq $-0x1
popq %rax
movl %eax, %r14d
movq 0x18(%rsp), %rbp
movq (%rsp), %r13
leaq 0x78(%rsp), %rdi
callq 0x1d92
testl %r14d, %r14d
jne 0x179c
movq 0x60(%rsp), %rax
incq %rax
movq 0x58(%rsp), %r14
jmp 0x1506
leaq 0x4c3a(%rip), %rdi      # 0x63c4
callq 0x1060
xorl %r14d, %r14d
jmp 0x1762
xorl %r14d, %r14d
jmp 0x179c
movl %eax, %r14d
movq 0x40(%rsp), %rdi
callq 0x5bb3
movq 0x48(%rsp), %rdi
callq 0x372c
movq 0x20(%rsp), %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
negl %r14d
movq %r14, %rbp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq