// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movl %edx, %ebp
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, %rbx
movq %rdi, %r13
movl 0x1014(%rdi), %esi
movl 0x1018(%rdi), %edx
movq %rax, %rdi
callq 0x3770
testl %eax, %eax
jne 0x2f61
movl %ebp, %eax
movq %rax, 0x18(%rsp)
leaq 0x1(%rax), %r15
movq %rbx, 0x28(%rsp)
leaq 0x20(%rbx), %rbp
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r13, (%rsp)
cmpl 0x103c(%r13), %eax
jae 0x2d95
movq %rax, 0x8(%rsp)
callq 0x30bb
callq 0x30d0
movq %rax, %r12
xorl %ebx, %ebx
movq %rbp, %r8
movq %r15, %r13
decq %r13
je 0x2c9c
leaq 0x28(%r8), %r14
movl -0x4(%r8), %eax
movl %eax, (%r8)
movq 0x10(%rsp), %rdi
movl -0x8(%r8), %edx
movq -0x20(%r8), %rsi
movq -0x18(%r8), %rcx
callq 0x388e
movq %r14, %r8
testl %eax, %eax
je 0x2c6a
jmp 0x2d56
callq 0x30d0
subq %r12, %rax
incq %rbx
movl $0xb2d05e00, %ecx       # imm = 0xB2D05E00
cmpq %rcx, %rax
jb 0x2c64
movq (%rsp), %r13
movq (%r13), %rcx
imulq 0x30(%rcx), %rbx
imulq $0x3e8, %rbx, %rcx      # imm = 0x3E8
movq %rcx, %xmm3
movq 0x239e(%rip), %xmm1     # 0x5070
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x23a2(%rip), %xmm2     # 0x5080
subpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
addsd %xmm3, %xmm0
movq %rax, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
divsd %xmm1, %xmm0
cmpl $0x1, 0x1034(%r13)
jne 0x2d3e
leaq 0x2741(%rip), %rdi      # 0x545d
movb $0x1, %al
movapd %xmm0, 0x30(%rsp)
callq 0x10f0
movq 0x5298(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
callq 0x11c0
movapd 0x30(%rsp), %xmm0
maxsd 0x20(%rsp), %xmm0
movq 0x8(%rsp), %rax
incl %eax
movsd %xmm0, 0x20(%rsp)
jmp 0x2c43
movq 0x529b(%rip), %rcx      # 0x7ff8
movq (%rcx), %r14
movq (%rsp), %rcx
movq 0x8(%rcx), %rbx
movl %eax, %edi
callq 0x1250
leaq 0x2459(%rip), %rsi      # 0x51cf
movq %r14, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1190
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, 0x1034(%r13)
jne 0x2da7
pushq $0xa
popq %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x3868
imulq $0x28, 0x18(%rsp), %rax
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x28(%rsp), %rbx
cmpq %rcx, %rax
je 0x2dd3
movl 0x20(%rbx,%rcx), %edx
addq %rdx, %r14
addq $0x28, %rcx
jmp 0x2dc1
movq (%r13), %rax
cvtsi2sdq 0x30(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x1014(%r13), %esi
leaq 0x10(%rsp), %rdi
callq 0x3d34
testl %eax, %eax
jne 0x2f61
movq %r14, 0x48(%rsp)
imulq $0x64, %r14, %rax
cvtsi2sd %rax, %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rax
leaq 0x1(%rax), %r15
leaq 0x24(%rbx), %r12
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl 0x103c(%r13), %eax
jae 0x2f82
movq %rax, 0x30(%rsp)
callq 0x30bb
callq 0x30d0
movq %rax, %r13
xorl %ebx, %ebx
movq %r12, %r8
movq %r15, %rbp
decq %rbp
je 0x2e88
leaq 0x28(%r8), %r14
movl -0xc(%r8), %eax
movl %eax, (%r8)
movq 0x10(%rsp), %rdi
movl -0x4(%r8), %edx
movq -0x1c(%r8), %rsi
movq -0x14(%r8), %rcx
callq 0x3d3e
movq %r14, %r8
testl %eax, %eax
je 0x2e56
jmp 0x2f3c
callq 0x30d0
subq %r13, %rax
incq %rbx
movl $0xb2d05e00, %ecx       # imm = 0xB2D05E00
cmpq %rcx, %rax
jb 0x2e50
movq (%rsp), %r13
movq (%r13), %rcx
imulq 0x30(%rcx), %rbx
imulq $0x3e8, %rbx, %rcx      # imm = 0x3E8
movq %rcx, %xmm3
movq 0x21b2(%rip), %xmm1     # 0x5070
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x21b6(%rip), %xmm2     # 0x5080
subpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
addsd %xmm3, %xmm0
movq %rax, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
divsd %xmm1, %xmm0
cmpl $0x1, 0x1034(%r13)
jne 0x2f2a
leaq 0x2555(%rip), %rdi      # 0x545d
movb $0x1, %al
movapd %xmm0, 0x50(%rsp)
callq 0x10f0
movq 0x50ac(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
callq 0x11c0
movapd 0x50(%rsp), %xmm0
maxsd 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rax
incl %eax
jmp 0x2e29
movq 0x50b5(%rip), %rcx      # 0x7ff8
movq (%rcx), %r14
movq (%rsp), %rcx
movq 0x8(%rcx), %rbx
movl %eax, %edi
callq 0x1250
leaq 0x235c(%rip), %rsi      # 0x52b8
jmp 0x2d76
movq 0x5090(%rip), %rcx      # 0x7ff8
movq (%rcx), %r14
movq 0x8(%r13), %rbx
movl %eax, %edi
callq 0x1250
leaq 0x21ec(%rip), %rsi      # 0x5169
jmp 0x2d76
cmpl $0x1, 0x1034(%r13)
jne 0x2f94
pushq $0xa
popq %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x3d3b
movq 0x5053(%rip), %r10      # 0x7ff8
leaq 0x24b9(%rip), %rsi      # 0x5465
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x28(%rsp), %r15
cmpq 0x18(%rsp), %r14
je 0x3061
imulq $0x28, %r14, %rax
leaq (%r15,%rax), %rbx
movl 0x18(%r15,%rax), %ecx
movl 0x24(%r15,%rax), %ebp
cmpl %ecx, %ebp
jne 0x3013
movq %rbp, %rax
movl %ebp, %edi
addq %rbp, %r12
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
addq %r13, %rax
movl %edi, %edi
xorl %r11d, %r11d
cmpl %r11d, %edi
je 0x300b
movzbl (%rcx,%r11), %r8d
movzbl (%rdx,%r11), %r9d
cmpb %r9b, %r8b
jne 0x303d
incq %r11
jmp 0x2ff2
incq %r14
movq %rax, %r13
jmp 0x2fba
movq (%r10), %rdi
movq (%rsp), %rax
movq 0x8(%rax), %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1190
leaq 0x2436(%rip), %rsi      # 0x5465
movq 0x4fc2(%rip), %r10      # 0x7ff8
movl 0x18(%rbx), %eax
movl %eax, %edi
jmp 0x2fe0
movq (%r10), %rdi
movq (%rsp), %rax
movq 0x8(%rax), %rdx
addq %r11, %r13
leaq 0x2445(%rip), %rsi      # 0x5497
movq %r13, %rcx
xorl %eax, %eax
callq 0x1190
jmp 0x2d86
movq (%rsp), %rbx
movq (%rbx), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, %r12
jne 0x30a1
movl 0x1018(%rbx), %esi
leaq 0x248e(%rip), %rdi      # 0x550c
movq 0x48(%rsp), %rdx
movsd 0x40(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
callq 0x10f0
jmp 0x2d86
movq (%r10), %rdi
movq 0x8(%rbx), %rdx
leaq 0x2422(%rip), %rsi      # 0x54d1
movq %r12, %r8
xorl %eax, %eax
callq 0x1190
jmp 0x3071