// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x20(%rsp), %rdi
movq $0x0, (%rdi)
movl 0x1014(%r14), %esi
movl 0x1018(%r14), %edx
callq 0x4bbe
testl %eax, %eax
jne 0x4a33
cmpl $0x0, 0x103c(%r14)
movq %r14, 0x10(%rsp)
movl %ebx, 0x8(%rsp)
je 0x46b8
movl %ebx, %eax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rax
leaq 0x20(%rax), %rbx
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 0x453d
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x469d
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rbp
xorl %r12d, %r12d
movq 0x48(%rsp), %r14
movq %rbx, %r13
cmpl $0x0, 0x8(%rsp)
je 0x45ac
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 0x4ce2
testl %eax, %eax
jne 0x46a7
addq $0x28, %r13
decq %r14
jne 0x457a
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x45e8
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 0x456b
jmp 0x45ef
callq 0x19a2
jmp 0x45bf
movq 0x10(%rsp), %r14
movq (%r14), %rcx
imulq 0x30(%rcx), %r12
imulq $0x3e8, %r12, %rcx      # imm = 0x3E8
movq %rcx, %xmm1
movq 0x1a30(%rip), %xmm3     # 0x6040
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x1a34(%rip), %xmm4     # 0x6050
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(%r14)
movq 0x40(%rsp), %r15
jne 0x4681
leaq 0x1e32(%rip), %rdi      # 0x6491
movb $0x1, %al
movapd %xmm0, 0x60(%rsp)
callq 0x10f0
movq 0x4955(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x11d0
movapd 0x60(%rsp), %xmm0
maxsd 0x38(%rsp), %xmm0
incl %r15d
movapd %xmm0, %xmm1
cmpl 0x103c(%r14), %r15d
jb 0x452a
jmp 0x46bc
callq 0x1948
jmp 0x455e
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x196a
jmp 0x4a72
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
cmpl $0x1, 0x1034(%r14)
jne 0x46d6
movl $0xa, %edi
callq 0x1040
movq 0x20(%rsp), %rdi
callq 0x4cb2
movl 0x8(%rsp), %ebx
testl %ebx, %ebx
je 0x470e
movl %ebx, %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 0x46fc
jmp 0x4711
xorl %r15d, %r15d
movq (%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sdq 0x30(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0x1014(%r14), %esi
leaq 0x20(%rsp), %rdi
callq 0x5078
testl %eax, %eax
jne 0x4a68
cmpl $0x0, 0x103c(%r14)
je 0x48fa
movl %ebx, %eax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rax
addq $0x24, %rax
movq %rax, 0x40(%rsp)
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
movsd %xmm1, 0x80(%rsp)
movq %rbx, 0x38(%rsp)
callq 0x10c0
movq %rax, %r13
callq 0x10c0
cmpq %r13, %rax
je 0x477b
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x48df
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %rbp
xorl %r12d, %r12d
movq 0x48(%rsp), %r14
movq 0x40(%rsp), %r13
cmpl $0x0, 0x8(%rsp)
je 0x47ec
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 0x27af
testl %eax, %eax
jne 0x48e9
addq $0x28, %r13
decq %r14
jne 0x47ba
movl $0x4, %edi
leaq 0x28(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x4828
movq 0x28(%rsp), %rax
subq %rbx, %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 0x47a9
jmp 0x482f
callq 0x1a56
jmp 0x47ff
movq 0x10(%rsp), %r14
movq (%r14), %rcx
imulq 0x30(%rcx), %r12
imulq $0x3e8, %r12, %rcx      # imm = 0x3E8
movq %rcx, %xmm1
movq 0x17f0(%rip), %xmm3     # 0x6040
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x17f4(%rip), %xmm4     # 0x6050
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(%r14)
movq 0x38(%rsp), %rbx
jne 0x48c1
leaq 0x1bf2(%rip), %rdi      # 0x6491
movb $0x1, %al
movapd %xmm0, 0x50(%rsp)
callq 0x10f0
movq 0x4715(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x11d0
movapd 0x50(%rsp), %xmm0
maxsd 0x80(%rsp), %xmm0
incl %ebx
movapd %xmm0, %xmm1
cmpl 0x103c(%r14), %ebx
jb 0x4765
jmp 0x48fe
callq 0x19fc
jmp 0x479c
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x1a1e
jmp 0x4a72
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
cmpl $0x1, 0x1034(%r14)
jne 0x4918
movl $0xa, %edi
callq 0x1040
movq 0x20(%rsp), %rdi
callq 0x5082
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x49e8
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), %rax
leaq (%r10,%rax,8), %rbx
movl 0x18(%rbx), %ecx
movl 0x24(%rbx), %ebp
cmpl %ecx, %ebp
jne 0x49a1
movl %ebp, %esi
testl %esi, %esi
je 0x4994
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leal -0x1(%rsi), %edx
addq %r13, %rdx
incq %rdx
movl %esi, %edi
xorl %esi, %esi
movzbl (%rax,%rsi), %r8d
movzbl (%rcx,%rsi), %r9d
cmpb %r9b, %r8b
jne 0x4a3f
incq %rsi
cmpl %esi, %edi
jne 0x4977
movq %rdx, %r13
addq %rbp, %r12
incq %r14
cmpq %r11, %r14
jne 0x494b
jmp 0x49f7
movq 0x4650(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x1ade(%rip), %rsi      # 0x6499
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
movl 0x18(%rbx), %esi
jmp 0x495f
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 0x4a84
movl 0x1018(%rbx), %esi
leaq 0x1b19(%rip), %rdi      # 0x6540
movq %r15, %rdx
movb $0x3, %al
callq 0x10f0
jmp 0x4a72
movq %r14, %rdi
movl %eax, %esi
callq 0x1910
jmp 0x4a72
movq 0x45b2(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdx
addq %rsi, %r13
leaq 0x1a6f(%rip), %rsi      # 0x64cb
movq %r13, %rcx
xorl %eax, %eax
callq 0x11a0
jmp 0x4a72
movq %r14, %rdi
movl %eax, %esi
callq 0x19c4
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x456d(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq 0x8(%rbx), %rdx
leaq 0x1a6c(%rip), %rsi      # 0x6505
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 0x4a1a