// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]xpack/programs/benchmark.c
// Function: do_benchmark
static int
do_benchmark(struct file_stream *in, void *original_buf, void *compressed_buf,
	     void *decompressed_buf, u32 chunk_size,
	     struct xpack_compressor *compressor,
	     struct xpack_decompressor *decompressor)
{
	u64 total_uncompressed_size = 0;
	u64 total_compressed_size = 0;
	u64 total_compress_time = 0;
	u64 total_decompress_time = 0;
	ssize_t ret;

	while ((ret = xread(in, original_buf, chunk_size)) > 0) {
		u32 original_size = ret;
		u32 compressed_size;
		u64 start_time;
		enum decompress_result result;

		total_uncompressed_size += original_size;

		/* Compress the chunk of data. */
		start_time = current_time();
		compressed_size = xpack_compress(compressor,
						 original_buf,
						 original_size,
						 compressed_buf,
						 original_size - 1);
		total_compress_time += current_time() - start_time;

		if (compressed_size) {
			/* Successfully compressed the chunk of data. */

			/* Decompress the data we just compressed and compare
			 * the result with the original. */
			start_time = current_time();
			result = xpack_decompress(decompressor,
						  compressed_buf,
						  compressed_size,
						  decompressed_buf,
						  original_size,
						  NULL);
			total_decompress_time += current_time() - start_time;

			if (result != DECOMPRESS_SUCCESS) {
				msg("%"TS": failed to decompress data",
				    in->name);
				return -1;
			}

			if (memcmp(original_buf, decompressed_buf,
				   original_size) != 0)
			{
				msg("%"TS": data did not decompress to "
				    "original", in->name);
				return -1;
			}

			total_compressed_size += compressed_size;
		} else {
			/* Compression did not make the chunk smaller. */
			total_compressed_size += original_size;
		}
	}

	if (ret < 0)
		return ret;

	if (total_uncompressed_size == 0) {
		printf("\tFile was empty.\n");
		return 0;
	}

	if (total_compress_time == 0)
		total_compress_time = 1;
	if (total_decompress_time == 0)
		total_decompress_time = 1;

	printf("\tCompressed %"PRIu64 " => %"PRIu64" bytes (%u.%03u%%)\n",
	       total_uncompressed_size, total_compressed_size,
	       (unsigned int)(total_compressed_size * 100 /
				total_uncompressed_size),
	       (unsigned int)(total_compressed_size * 100000 /
				total_uncompressed_size % 1000));
	printf("\tCompression time: %"PRIu64" ms (%"PRIu64" MB/s)\n",
	       total_compress_time / 1000000,
	       1000 * total_uncompressed_size / total_compress_time);
	printf("\tDecompression time: %"PRIu64" ms (%"PRIu64" MB/s)\n",
	       total_decompress_time / 1000000,
	       1000 * total_uncompressed_size / total_decompress_time);

	return 0;
}

// Assembly:
subq $0x88, %rsp
movq 0x90(%rsp), %rax
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movl %r8d, 0x5c(%rsp)
movq %r9, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x5c(%rsp), %eax
movl %eax, %edx
callq 0x2050
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
jle 0x18bc
movq 0x28(%rsp), %rax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq 0x48(%rsp), %rax
movq %rax, 0x48(%rsp)
callq 0x1c90
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x24(%rsp), %eax
movl %eax, %edx
movq 0x68(%rsp), %rcx
movl 0x24(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %r8d
callq 0x68c0
movl %eax, 0x20(%rsp)
callq 0x1c90
subq 0x18(%rsp), %rax
addq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x18a9
callq 0x1c90
movq %rax, 0x18(%rsp)
movq 0x90(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x20(%rsp), %eax
movl %eax, %edx
movq 0x60(%rsp), %rcx
movl 0x24(%rsp), %eax
movl %eax, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0xb360
movl %eax, 0x14(%rsp)
callq 0x1c90
subq 0x18(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1858
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xdbd3(%rip), %rdi      # 0xf414
movb $0x0, %al
callq 0x1a00
movl $0xffffffff, 0x84(%rsp) # imm = 0xFFFFFFFF
jmp 0x19e5
movq 0x70(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x24(%rsp), %eax
movl %eax, %edx
callq 0x1100
cmpl $0x0, %eax
je 0x1899
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xdbb0(%rip), %rdi      # 0xf432
movb $0x0, %al
callq 0x1a00
movl $0xffffffff, 0x84(%rsp) # imm = 0xFFFFFFFF
jmp 0x19e5
movl 0x20(%rsp), %eax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x18b7
movl 0x24(%rsp), %eax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x1751
cmpq $0x0, 0x28(%rsp)
jge 0x18d5
movq 0x28(%rsp), %rax
movl %eax, 0x84(%rsp)
jmp 0x19e5
cmpq $0x0, 0x48(%rsp)
jne 0x18fb
leaq 0xdb76(%rip), %rdi      # 0xf45a
movb $0x0, %al
callq 0x10a0
movl $0x0, 0x84(%rsp)
jmp 0x19e5
cmpq $0x0, 0x38(%rsp)
jne 0x190c
movq $0x1, 0x38(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x191d
movq $0x1, 0x30(%rsp)
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
imulq $0x64, 0x40(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x48(%rsp)
movl %eax, %ecx
imulq $0x186a0, 0x40(%rsp), %rax # imm = 0x186A0
xorl %edx, %edx
divq 0x48(%rsp)
movl $0x3e8, %edi            # imm = 0x3E8
xorl %edx, %edx
divq %rdi
movq %rdx, %rax
movq 0x8(%rsp), %rdx
movl %eax, %r8d
leaq 0xdb03(%rip), %rdi      # 0xf46c
movb $0x0, %al
callq 0x10a0
movq 0x38(%rsp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
imulq $0x3e8, 0x48(%rsp), %rax # imm = 0x3E8
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x38(%rsp)
movq %rax, %rdx
leaq 0xdaf8(%rip), %rdi      # 0xf496
movb $0x0, %al
callq 0x10a0
movq 0x30(%rsp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
imulq $0x3e8, 0x48(%rsp), %rax # imm = 0x3E8
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x30(%rsp)
movq %rax, %rdx
leaq 0xdae9(%rip), %rdi      # 0xf4bc
movb $0x0, %al
callq 0x10a0
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)
nop