// File: /workspace/github_c_makefile_star2_O1/lmcilroy[P]lzm/lzm.c
// Function: benchmark_level
static unsigned int
benchmark_level(struct compress_args * const args, struct chunk *chunks,
    unsigned int nchunks)
{
	struct lzm_state *state = NULL;
	double rate;
	double comp_rate;
	double decomp_rate;
	double comp_perc;
	unsigned long ts_start;
	unsigned long iterations;
	unsigned long time;
	unsigned int t;
	unsigned int c;
	unsigned int ret;
	off_t comp_size;
	off_t decomp_size;
	off_t offset = 0;
	const unsigned char *d1;
	const unsigned char *d2;

	comp_rate = 0;
	ret = lzm_encode_init(&state, args->format, args->level);
	if (ret != 0) {
		fprintf(stderr, "File %s: failed to init lzm: %s\n",
		    args->filename, strerror(ret));
		goto out;
	}

	for (t = 0; t < args->bench_tests; t++) {

		iterations = 0;
		synctime();
		ts_start = gettime();

		do {
			for (c = 0; c < nchunks; c++) {
				chunks[c].size_comp_out = chunks[c].size_comp;
				ret = lzm_encode(state, chunks[c].data_orig,
				    chunks[c].size_orig, chunks[c].data_comp,
				    &chunks[c].size_comp_out);
				if (unlikely(ret != 0)) {
					fprintf(stderr,
					"File %s: failed to encode data: %s\n",
					    args->filename, strerror(ret));
					goto out;
				}
			}

			time = gettime() - ts_start;
			iterations++;

		} while (time < BENCH_TIME);

		rate = (double)(args->st->st_size * iterations * 1000) /
		    (double)time;
		if (rate > comp_rate)
			comp_rate = rate;

		if (args->verbose == true) {
			printf("%10.4f ", rate);
			fflush(stdout);
		}
	}

	if (args->verbose == true)
		printf("\n");

	lzm_encode_finish(state);

	comp_size = 0;
	for (c = 0; c < nchunks; c++)
		comp_size += chunks[c].size_comp_out;

	comp_perc = (double)(comp_size * 100) / (double)args->st->st_size;

	decomp_rate = 0;
	ret = lzm_decode_init(&state, args->format);
	if (ret != 0) {
		fprintf(stderr, "File %s: failed to init lzm: %s\n",
		    args->filename, strerror(ret));
		goto out;
	}

	for (t = 0; t < args->bench_tests; t++) {

		iterations = 0;
		synctime();
		ts_start = gettime();

		do {
			for (c = 0; c < nchunks; c++) {
				chunks[c].size_decomp_out = chunks[c].size_orig;
				ret = lzm_decode(state, chunks[c].data_comp,
				    chunks[c].size_comp_out,
				    chunks[c].data_decomp,
				    &chunks[c].size_decomp_out);
				if (unlikely(ret != 0)) {
					fprintf(stderr,
					"File %s: failed to decode data: %s\n",
					    args->filename, strerror(ret));
					goto out;
				}
			}

			time = gettime() - ts_start;
			iterations++;

		} while (time < BENCH_TIME);

		rate = (double)(args->st->st_size * iterations * 1000) /
		    (double)time;
		if (rate > decomp_rate)
			decomp_rate = rate;

		if (args->verbose == true) {
			printf("%10.4f ", rate);
			fflush(stdout);
		}
	}

	if (args->verbose == true)
		printf("\n");

	lzm_decode_finish(state);

	decomp_size = 0;
	for (c = 0; c < nchunks; c++) {
		decomp_size += chunks[c].size_decomp_out;
		if (chunks[c].size_decomp_out != chunks[c].size_orig) {
			fprintf(stderr,
			"File %s: incorrect chunk size, expect %u, got %u\n",
			    args->filename, chunks[c].size_orig,
			    chunks[c].size_decomp_out);
		}
		d1 = chunks[c].data_orig;
		d2 = chunks[c].data_decomp;
		for (t = 0; t < chunks[c].size_orig; t++) {
			if (*d1 != *d2) {
				fprintf(stderr,
				    "File %s: corruption, offset %lu,"
				    " expect 0x%x, found 0x%x\n",
				    args->filename, offset, *d1, *d2);
				goto out;
			}
			d1++;
			d2++;
			offset++;
		}
	}

	if (decomp_size != args->st->st_size) {
		fprintf(stderr,
		"File %s: incorrect decompressed size, expect %lu, got %lu\n",
		    args->filename, args->st->st_size, decomp_size);
	}

	printf("Level %d: --> %lu, %9.4f%%, %10.4f MB/s, %10.4f MB/s\n",
	    args->level, comp_size, comp_perc, comp_rate, decomp_rate);

 out:
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %ebp
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movq $0x0, (%rdi)
movl 0x1014(%rbx), %esi
movl 0x1018(%rbx), %edx
callq 0x4bb6
testl %eax, %eax
jne 0x4a21
cmpl $0x0, 0x103c(%rbx)
movq %rbx, 0x10(%rsp)
movl %ebp, 0x8(%rsp)
je 0x46a7
movl %ebp, %eax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rax
leaq 0x20(%rax), %r14
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movsd %xmm1, 0x38(%rsp)
movq %r15, 0x40(%rsp)
callq 0x10c0
movq %rax, %r13
callq 0x10c0
cmpq %r13, %rax
je 0x452d
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x468c
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rbp
xorl %r12d, %r12d
movq 0x48(%rsp), %rbx
movq %r14, %r13
cmpl $0x0, 0x8(%rsp)
je 0x459c
movl -0x4(%r13), %eax
movl %eax, (%r13)
movq 0x20(%rsp), %rdi
movl -0x8(%r13), %edx
movq -0x20(%r13), %rsi
movq -0x18(%r13), %rcx
movq %r13, %r8
callq 0x4d0a
testl %eax, %eax
jne 0x4696
addq $0x28, %r13
decq %rbx
jne 0x456a
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x45d8
movq 0x28(%rsp), %rax
subq %r15, %rax
movq 0x30(%rsp), %rcx
subq %rbp, %rcx
imulq $0x3b9aca00, %rax, %rax # imm = 0x3B9ACA00
addq %rcx, %rax
incq %r12
movl $0xb2d05e00, %ecx       # imm = 0xB2D05E00
cmpq %rcx, %rax
jb 0x455b
jmp 0x45df
callq 0x19a1
jmp 0x45af
movq 0x10(%rsp), %rbx
movq (%rbx), %rcx
imulq 0x30(%rcx), %r12
imulq $0x3e8, %r12, %rcx      # imm = 0x3E8
movq %rcx, %xmm1
movq 0x1a30(%rip), %xmm3     # 0x6030
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x1a34(%rip), %xmm4     # 0x6040
subpd %xmm4, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %rax, %xmm2
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
subpd %xmm4, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cmpl $0x1, 0x1034(%rbx)
movq 0x40(%rsp), %r15
jne 0x4670
leaq 0x1e3b(%rip), %rdi      # 0x6489
movb $0x1, %al
movapd %xmm0, 0x60(%rsp)
callq 0x10f0
movq 0x4966(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x11d0
movapd 0x60(%rsp), %xmm0
maxsd 0x38(%rsp), %xmm0
incl %r15d
movapd %xmm0, %xmm1
cmpl 0x103c(%rbx), %r15d
jb 0x451a
jmp 0x46ab
callq 0x1947
jmp 0x454e
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x1969
jmp 0x4a60
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
cmpl $0x1, 0x1034(%rbx)
jne 0x46c4
movl $0xa, %edi
callq 0x1040
movq 0x20(%rsp), %rdi
callq 0x4cda
movl 0x8(%rsp), %ebp
testl %ebp, %ebp
je 0x46fc
movl %ebp, %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
movq 0x18(%rsp), %rsi
movl 0x20(%rsi,%rcx), %edx
addq %rdx, %r15
addq $0x28, %rcx
cmpq %rcx, %rax
jne 0x46ea
jmp 0x46ff
xorl %r15d, %r15d
movq (%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sdq 0x30(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0x1014(%rbx), %esi
leaq 0x20(%rsp), %rdi
callq 0x50a4
testl %eax, %eax
jne 0x4a56
cmpl $0x0, 0x103c(%rbx)
je 0x48e7
movl %ebp, %eax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rax
addq $0x24, %rax
movq %rax, 0x40(%rsp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, 0x80(%rsp)
movq %r14, 0x38(%rsp)
callq 0x10c0
movq %rax, %r13
callq 0x10c0
cmpq %r13, %rax
je 0x4768
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x48cc
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rbp
xorl %r12d, %r12d
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %r13
cmpl $0x0, 0x8(%rsp)
je 0x47d9
movl -0xc(%r13), %eax
movl %eax, (%r13)
movq 0x20(%rsp), %rdi
movl -0x4(%r13), %edx
movq -0x1c(%r13), %rsi
movq -0x14(%r13), %rcx
movq %r13, %r8
callq 0x2768
testl %eax, %eax
jne 0x48d6
addq $0x28, %r13
decq %rbx
jne 0x47a7
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x4815
movq 0x28(%rsp), %rax
subq %r14, %rax
movq 0x30(%rsp), %rcx
subq %rbp, %rcx
imulq $0x3b9aca00, %rax, %rax # imm = 0x3B9ACA00
addq %rcx, %rax
incq %r12
movl $0xb2d05e00, %ecx       # imm = 0xB2D05E00
cmpq %rcx, %rax
jb 0x4796
jmp 0x481c
callq 0x1a55
jmp 0x47ec
movq 0x10(%rsp), %rbx
movq (%rbx), %rcx
imulq 0x30(%rcx), %r12
imulq $0x3e8, %r12, %rcx      # imm = 0x3E8
movq %rcx, %xmm1
movq 0x17f3(%rip), %xmm3     # 0x6030
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x17f7(%rip), %xmm4     # 0x6040
subpd %xmm4, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %rax, %xmm2
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
subpd %xmm4, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cmpl $0x1, 0x1034(%rbx)
movq 0x38(%rsp), %r14
jne 0x48ad
leaq 0x1bfe(%rip), %rdi      # 0x6489
movb $0x1, %al
movapd %xmm0, 0x50(%rsp)
callq 0x10f0
movq 0x4729(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x11d0
movapd 0x50(%rsp), %xmm0
maxsd 0x80(%rsp), %xmm0
incl %r14d
movapd %xmm0, %xmm1
cmpl 0x103c(%rbx), %r14d
jb 0x4752
jmp 0x48eb
callq 0x19fb
jmp 0x4789
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x1a1d
jmp 0x4a60
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
cmpl $0x1, 0x1034(%rbx)
jne 0x4904
movl $0xa, %edi
callq 0x1040
movq 0x20(%rsp), %rdi
callq 0x50ae
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x49d6
movl %eax, %r11d
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x18(%rsp), %r10
movapd 0x60(%rsp), %xmm1
movapd 0x50(%rsp), %xmm2
leaq (%r14,%r14,4), %rbx
movl 0x18(%r10,%rbx,8), %ecx
movl 0x24(%r10,%rbx,8), %ebp
cmpl %ecx, %ebp
jne 0x4992
leaq (%r10,%rbx,8), %rdx
movl 0x18(%rdx), %eax
testq %rax, %rax
je 0x4985
movq (%rdx), %rcx
movq 0x10(%rdx), %rdx
leal -0x1(%rax), %esi
leaq (%rsi,%r13), %rdi
incq %rdi
xorl %esi, %esi
movzbl (%rcx,%rsi), %r8d
movzbl (%rdx,%rsi), %r9d
cmpb %r9b, %r8b
jne 0x4a2d
incq %rsi
cmpl %esi, %eax
jne 0x4968
movq %rdi, %r13
addq %rbp, %r12
incq %r14
cmpq %r11, %r14
jne 0x4937
jmp 0x49e5
movq 0x465f(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x1ae5(%rip), %rsi      # 0x6491
movl %ebp, %r8d
xorl %eax, %eax
movq %r11, 0x8(%rsp)
callq 0x11a0
movq 0x8(%rsp), %r11
movapd 0x50(%rsp), %xmm2
movapd 0x60(%rsp), %xmm1
movq 0x18(%rsp), %r10
jmp 0x4949
xorl %r12d, %r12d
movapd 0x60(%rsp), %xmm1
movapd 0x50(%rsp), %xmm2
imulq $0x64, %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x78(%rsp), %xmm0
movq 0x10(%rsp), %rbx
movq (%rbx), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, %r12
jne 0x4a72
movl 0x1018(%rbx), %esi
leaq 0x1b23(%rip), %rdi      # 0x6538
movq %r15, %rdx
movb $0x3, %al
callq 0x10f0
jmp 0x4a60
movq %rbx, %rdi
movl %eax, %esi
callq 0x190f
jmp 0x4a60
movq 0x45c4(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdx
addq %rsi, %r13
leaq 0x1a79(%rip), %rsi      # 0x64c3
movq %r13, %rcx
xorl %eax, %eax
callq 0x11a0
jmp 0x4a60
movq %rbx, %rdi
movl %eax, %esi
callq 0x19c3
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x457f(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x8(%rbx), %rdx
leaq 0x1a76(%rip), %rsi      # 0x64fd
movq %r12, %r8
xorl %eax, %eax
movsd %xmm0, 0x8(%rsp)
callq 0x11a0
movsd 0x8(%rsp), %xmm0
movapd 0x50(%rsp), %xmm2
movapd 0x60(%rsp), %xmm1
jmp 0x4a08
nop