void benchmarkEncode(void) {
  double millis;
  double per_sec_in_bytes;
  double MB = 1024.0 * 1024.0;
  double millis_to_sec = 1000 * 1000;
  int n;
  int size;
  printf("%s:\n", __FUNCTION__);
  n = 20000;
  size = 10000;
  millis = benchmarkEncodeTest(n, 10, 2, size);
  per_sec_in_bytes = (10 * 2 * size / MB) * millis_to_sec * n / millis;
  printf("10x2x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\n", n,
         millis, per_sec_in_bytes);
  n = 200;
  millis = benchmarkEncodeTest(n, 100, 20, size);
  per_sec_in_bytes = (100 * 20 * size / MB) * millis_to_sec * n / millis;
  printf("100x20x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\n", n,
         millis, per_sec_in_bytes);
  n = 200;
  size = 1024 * 1024;
  millis = benchmarkEncodeTest(n, 17, 3, size);
  per_sec_in_bytes = (17 * 3 * size / MB) * millis_to_sec * n / millis;
  printf(
      "17x3x(1024*1024), test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\n",
      n, millis, per_sec_in_bytes);
}


x86 assembly (clang, -O0):
<benchmarkEncode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xec7(%rip),%rdi
lea    0xec5(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x4e20,-0x24(%rbp)
movl   $0x2710,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%ecx
mov    $0xa,%esi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <benchmarkEncodeTest@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
imul   $0x14,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe67(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0xc8,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%ecx
mov    $0x64,%esi
mov    $0x14,%edx
mov    $0x0,%al
call   1040 <benchmarkEncodeTest@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
imul   $0x7d0,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe3c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0xc8,-0x24(%rbp)
movl   $0x100000,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%ecx
mov    $0x11,%esi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <benchmarkEncodeTest@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
imul   $0x33,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe0f(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmarkEncode>:
push   %rax
lea    0xee8(%rip),%rdi
lea    0xee6(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x4e20,%edi
mov    $0xa,%esi
mov    $0x2,%edx
mov    $0x2710,%ecx
xor    %eax,%eax
call   1040 <benchmarkEncodeTest@plt>
cvtsi2sd %eax,%xmm0
movsd  0xea3(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0xebd(%rip),%rdi
mov    $0x4e20,%esi
mov    $0x2,%al
call   1030 <printf@plt>
mov    $0xc8,%edi
mov    $0x64,%esi
mov    $0x14,%edx
mov    $0x2710,%ecx
xor    %eax,%eax
call   1040 <benchmarkEncodeTest@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe62(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0xebb(%rip),%rdi
mov    $0xc8,%esi
mov    $0x2,%al
call   1030 <printf@plt>
mov    $0xc8,%edi
mov    $0x11,%esi
mov    $0x3,%edx
mov    $0x100000,%ecx
xor    %eax,%eax
call   1040 <benchmarkEncodeTest@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe29(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0xebb(%rip),%rdi
mov    $0xc8,%esi
mov    $0x2,%al
pop    %rcx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s:\0A\00"
@__FUNCTION__.benchmarkEncode = [16 x i8] c"benchmarkEncode\00"
@.str.1 = [63 x i8] c"10x2x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
@.str.2 = [65 x i8] c"100x20x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
@.str.3 = [69 x i8] c"17x3x(1024*1024), test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
define void @benchmarkEncode() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store double 0x4130000000000000, double* %3
store double 1.000000e+06, double* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.benchmarkEncode, i64 0, i64 0))
store i32 20000, i32* %5
store i32 10000, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 %8, i32 10, i32 2, i32 %9)
%11 = sitofp i32 %10 to double
store double %11, double* %1
%12 = load i32, i32* %6
%13 = mul nsw i32 20, %12
%14 = sitofp i32 %13 to double
%15 = load double, double* %3
%16 = fdiv double %14, %15
%17 = load double, double* %4
%18 = fmul double %16, %17
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to double
%21 = fmul double %18, %20
%22 = load double, double* %1
%23 = fdiv double %21, %22
store double %23, double* %2
%24 = load i32, i32* %5
%25 = load double, double* %1
%26 = load double, double* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i32 %24, double %25, double %26)
store i32 200, i32* %5
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 %28, i32 100, i32 20, i32 %29)
%31 = sitofp i32 %30 to double
store double %31, double* %1
%32 = load i32, i32* %6
%33 = mul nsw i32 2000, %32
%34 = sitofp i32 %33 to double
%35 = load double, double* %3
%36 = fdiv double %34, %35
%37 = load double, double* %4
%38 = fmul double %36, %37
%39 = load i32, i32* %5
%40 = sitofp i32 %39 to double
%41 = fmul double %38, %40
%42 = load double, double* %1
%43 = fdiv double %41, %42
store double %43, double* %2
%44 = load i32, i32* %5
%45 = load double, double* %1
%46 = load double, double* %2
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 %44, double %45, double %46)
store i32 200, i32* %5
store i32 1048576, i32* %6
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 %48, i32 17, i32 3, i32 %49)
%51 = sitofp i32 %50 to double
store double %51, double* %1
%52 = load i32, i32* %6
%53 = mul nsw i32 51, %52
%54 = sitofp i32 %53 to double
%55 = load double, double* %3
%56 = fdiv double %54, %55
%57 = load double, double* %4
%58 = fmul double %56, %57
%59 = load i32, i32* %5
%60 = sitofp i32 %59 to double
%61 = fmul double %58, %60
%62 = load double, double* %1
%63 = fdiv double %61, %62
store double %63, double* %2
%64 = load i32, i32* %5
%65 = load double, double* %1
%66 = load double, double* %2
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), i32 %64, double %65, double %66)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s:\0A\00"
@__FUNCTION__.benchmarkEncode = [16 x i8] c"benchmarkEncode\00"
@.str.1 = [63 x i8] c"10x2x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
@.str.2 = [65 x i8] c"100x20x10000, test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
@.str.3 = [69 x i8] c"17x3x(1024*1024), test_count=%d millis=%lf per_sec_in_bytes=%lfMB/s\0A\00"
define void @benchmarkEncode() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__FUNCTION__.benchmarkEncode, i64 0, i64 0))
%2 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 20000, i32 10, i32 2, i32 10000)
%3 = sitofp i32 %2 to double
%4 = fdiv double 0x41EC6BF526340000, %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i32 20000, double %3, double %4)
%6 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 200, i32 100, i32 20, i32 10000)
%7 = sitofp i32 %6 to double
%8 = fdiv double 0x41EC6BF526340000, %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 200, double %7, double %8)
%10 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @benchmarkEncodeTest to i32 (i32, i32, i32, i32, ...)*)(i32 200, i32 17, i32 3, i32 1048576)
%11 = sitofp i32 %10 to double
%12 = fdiv double 1.020000e+10, %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), i32 200, double %11, double %12)
ret void
}