void DynamicProgrammingQ2(double *Q1, double *T1, double *Q2, double *T2,
                          int m1, int n1, int n2, double *tv1, double *tv2,
                          int n1v, int n2v, double *G, double *T, double *size,
                          double lam1) {
  int *idxv1 = 0;
  int *idxv2 = 0;
  double *E = 0;
  int *P = 0;
  idxv1 = (int *)malloc((n1v) * sizeof(int));
  idxv2 = (int *)malloc((n2v) * sizeof(int));
  E = (double *)malloc((n1v) * (n2v) * sizeof(double));
  P = (int *)calloc((n1v) * (n2v), sizeof(int));
  dp_all_indexes(T1, n1, tv1, n1v, idxv1);
  dp_all_indexes(T2, n2, tv2, n2v, idxv2);
  dp_costs(Q1, T1, n1, Q2, T2, n2, m1, tv1, idxv1, n1v, tv2, idxv2, n2v, E, P,
           lam1);
  *size = dp_build_gamma(P, tv1, n1v, tv2, n2v, G, T);
  free(idxv1);
  free(idxv2);
  free(E);
  free(P);
}


x86 assembly (clang, -O0):
<DynamicProgrammingQ2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8d,-0x4c(%rbp)
mov    %r9d,-0x50(%rbp)
movsd  %xmm0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movslq 0x28(%rbp),%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x60(%rbp)
movslq 0x30(%rbp),%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    0x28(%rbp),%eax
imul   0x30(%rbp),%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x70(%rbp)
mov    0x28(%rbp),%eax
imul   0x30(%rbp),%eax
movslq %eax,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    0x28(%rbp),%ecx
mov    -0x60(%rbp),%r8
mov    $0x0,%al
call   1040 <dp_all_indexes@plt>
mov    -0x48(%rbp),%rdi
mov    0x10(%rbp),%esi
mov    0x20(%rbp),%rdx
mov    0x30(%rbp),%ecx
mov    -0x68(%rbp),%r8
mov    $0x0,%al
call   1040 <dp_all_indexes@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    0x10(%rbp),%r9d
mov    -0x4c(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    0x18(%rbp),%r13
mov    -0x60(%rbp),%r12
mov    0x28(%rbp),%r15d
mov    0x20(%rbp),%r14
mov    -0x68(%rbp),%rbx
mov    0x30(%rbp),%r11d
mov    -0x70(%rbp),%r10
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x84(%rbp),%eax
movsd  -0x58(%rbp),%xmm0
mov    %eax,(%rsp)
mov    -0x80(%rbp),%rax
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15d,0x18(%rsp)
mov    %r14,0x20(%rsp)
mov    %rbx,0x28(%rsp)
mov    %r11d,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
mov    $0x1,%al
call   1070 <dp_costs@plt>
mov    -0x78(%rbp),%rdi
mov    0x18(%rbp),%rsi
mov    0x28(%rbp),%edx
mov    0x20(%rbp),%rcx
mov    0x30(%rbp),%r8d
mov    0x38(%rbp),%r9
mov    0x40(%rbp),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1080 <dp_build_gamma@plt>
cvtsi2sd %eax,%xmm0
mov    0x48(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<DynamicProgrammingQ2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movsd  %xmm0,0x60(%rsp)
mov    %r9d,%r14d
mov    %r9d,0x4(%rsp)
mov    %r8,0x68(%rsp)
mov    %rcx,0x48(%rsp)
mov    %rdx,0x58(%rsp)
mov    %rsi,%r13
mov    %rdi,0x50(%rsp)
movslq 0xd8(%rsp),%rcx
movslq 0xe0(%rsp),%rbx
mov    %rbx,0x28(%rsp)
mov    0xf8(%rsp),%rax
mov    %rax,0x80(%rsp)
mov    0xe8(%rsp),%rax
mov    %rax,0x70(%rsp)
mov    0xf0(%rsp),%rax
mov    %rax,0x78(%rsp)
mov    0xc0(%rsp),%r12d
mov    0xd0(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0xc8(%rsp),%r15
mov    %r15,0x40(%rsp)
mov    %rcx,%rdi
mov    %rcx,%rbp
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %ebx,%eax
imul   %ebp,%eax
mov    %rbp,%rbx
mov    %rbp,0x38(%rsp)
movslq %eax,%rbp
lea    0x0(,%rbp,8),%rdi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    $0x4,%esi
mov    %rbp,%rdi
call   1050 <calloc@plt>
mov    %rax,0x30(%rsp)
mov    %r13,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    0x8(%rsp),%r14
mov    %r14,%r8
xor    %eax,%eax
call   1040 <dp_all_indexes@plt>
mov    0x48(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r12d,%r15d
mov    0x18(%rsp),%rdx
mov    0x28(%rsp),%r12
mov    %r12d,%ecx
mov    0x10(%rsp),%rbp
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <dp_all_indexes@plt>
sub    $0x8,%rsp
mov    0x58(%rsp),%rdi
mov    %r13,%rsi
mov    0xc(%rsp),%edx
mov    0x60(%rsp),%rcx
mov    %rbx,%r8
mov    %r15d,%r9d
movsd  0x68(%rsp),%xmm0
mov    $0x1,%al
mov    0x38(%rsp),%r13
push   %r13
push   0x30(%rsp)
push   %r12
push   %rbp
mov    0x40(%rsp),%r15
push   %r15
mov    0x68(%rsp),%rbx
push   %rbx
push   %r14
mov    0x80(%rsp),%rbp
push   %rbp
push   0xb0(%rsp)
call   1070 <dp_costs@plt>
add    $0x48,%rsp
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %r15,%rcx
mov    %r12d,%r8d
mov    0x78(%rsp),%r9
xor    %eax,%eax
push   0x80(%rsp)
call   1080 <dp_build_gamma@plt>
add    $0x10,%rsp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x80(%rsp),%rax
movsd  %xmm0,(%rax)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @DynamicProgrammingQ2(double* %0, double* %1, double* %2, double* %3, i32 %4, i32 %5, i32 %6, double* %7, double* %8, i32 %9, i32 %10, double* %11, double* %12, double* %13, double %14) {
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca double*
%24 = alloca double*
%25 = alloca i32
%26 = alloca i32
%27 = alloca double*
%28 = alloca double*
%29 = alloca double*
%30 = alloca double
%31 = alloca i32*
%32 = alloca i32*
%33 = alloca double*
%34 = alloca i32*
store double* %0, double** %16
store double* %1, double** %17
store double* %2, double** %18
store double* %3, double** %19
store i32 %4, i32* %20
store i32 %5, i32* %21
store i32 %6, i32* %22
store double* %7, double** %23
store double* %8, double** %24
store i32 %9, i32* %25
store i32 %10, i32* %26
store double* %11, double** %27
store double* %12, double** %28
store double* %13, double** %29
store double %14, double* %30
store i32* null, i32** %31
store i32* null, i32** %32
store double* null, double** %33
store i32* null, i32** %34
%35 = load i32, i32* %25
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = call i8* @malloc(i64 %37)
%39 = bitcast i8* %38 to i32*
store i32* %39, i32** %31
%40 = load i32, i32* %26
%41 = sext i32 %40 to i64
%42 = mul i64 %41, 4
%43 = call i8* @malloc(i64 %42)
%44 = bitcast i8* %43 to i32*
store i32* %44, i32** %32
%45 = load i32, i32* %25
%46 = load i32, i32* %26
%47 = mul nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 8
%50 = call i8* @malloc(i64 %49)
%51 = bitcast i8* %50 to double*
store double* %51, double** %33
%52 = load i32, i32* %25
%53 = load i32, i32* %26
%54 = mul nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = call i8* @calloc(i64 %55, i64 4)
%57 = bitcast i8* %56 to i32*
store i32* %57, i32** %34
%58 = load double*, double** %17
%59 = load i32, i32* %21
%60 = load double*, double** %23
%61 = load i32, i32* %25
%62 = load i32*, i32** %31
%63 = call i32 (double*, i32, double*, i32, i32*, ...) bitcast (i32 (...)* @dp_all_indexes to i32 (double*, i32, double*, i32, i32*, ...)*)(double* %58, i32 %59, double* %60, i32 %61, i32* %62)
%64 = load double*, double** %19
%65 = load i32, i32* %22
%66 = load double*, double** %24
%67 = load i32, i32* %26
%68 = load i32*, i32** %32
%69 = call i32 (double*, i32, double*, i32, i32*, ...) bitcast (i32 (...)* @dp_all_indexes to i32 (double*, i32, double*, i32, i32*, ...)*)(double* %64, i32 %65, double* %66, i32 %67, i32* %68)
%70 = load double*, double** %16
%71 = load double*, double** %17
%72 = load i32, i32* %21
%73 = load double*, double** %18
%74 = load double*, double** %19
%75 = load i32, i32* %22
%76 = load i32, i32* %20
%77 = load double*, double** %23
%78 = load i32*, i32** %31
%79 = load i32, i32* %25
%80 = load double*, double** %24
%81 = load i32*, i32** %32
%82 = load i32, i32* %26
%83 = load double*, double** %33
%84 = load i32*, i32** %34
%85 = load double, double* %30
%86 = call i32 (double*, double*, i32, double*, double*, i32, i32, double*, i32*, i32, double*, i32*, i32, double*, i32*, double, ...) bitcast (i32 (...)* @dp_costs to i32 (double*, double*, i32, double*, double*, i32, i32, double*, i32*, i32, double*, i32*, i32, double*, i32*, double, ...)*)(double* %70, double* %71, i32 %72, double* %73, double* %74, i32 %75, i32 %76, double* %77, i32* %78, i32 %79, double* %80, i32* %81, i32 %82, double* %83, i32* %84, double %85)
%87 = load i32*, i32** %34
%88 = load double*, double** %23
%89 = load i32, i32* %25
%90 = load double*, double** %24
%91 = load i32, i32* %26
%92 = load double*, double** %27
%93 = load double*, double** %28
%94 = call i32 (i32*, double*, i32, double*, i32, double*, double*, ...) bitcast (i32 (...)* @dp_build_gamma to i32 (i32*, double*, i32, double*, i32, double*, double*, ...)*)(i32* %87, double* %88, i32 %89, double* %90, i32 %91, double* %92, double* %93)
%95 = sitofp i32 %94 to double
%96 = load double*, double** %29
store double %95, double* %96
%97 = load i32*, i32** %31
%98 = bitcast i32* %97 to i8*
%99 = load i32*, i32** %32
%100 = bitcast i32* %99 to i8*
%101 = load double*, double** %33
%102 = bitcast double* %101 to i8*
%103 = load i32*, i32** %34
%104 = bitcast i32* %103 to i8*
ret void
}

LLVM IR (-O2):
define void @DynamicProgrammingQ2(double* %0, double* %1, double* %2, double* %3, i32 %4, i32 %5, i32 %6, double* %7, double* %8, i32 %9, i32 %10, double* %11, double* %12, double* nocapture writeonly %13, double %14) {
%16 = sext i32 %9 to i64
%17 = shl nsw i64 %16, 2
%18 = tail call i8* @malloc(i64 %17)
%19 = bitcast i8* %18 to i32*
%20 = sext i32 %10 to i64
%21 = shl nsw i64 %20, 2
%22 = tail call i8* @malloc(i64 %21)
%23 = bitcast i8* %22 to i32*
%24 = mul nsw i32 %10, %9
%25 = sext i32 %24 to i64
%26 = shl nsw i64 %25, 3
%27 = tail call i8* @malloc(i64 %26)
%28 = bitcast i8* %27 to double*
%29 = tail call i8* @calloc(i64 %25, i64 4)
%30 = bitcast i8* %29 to i32*
%31 = tail call i32 (double*, i32, double*, i32, i32*, ...) bitcast (i32 (...)* @dp_all_indexes to i32 (double*, i32, double*, i32, i32*, ...)*)(double* %1, i32 %5, double* %7, i32 %9, i32* %19)
%32 = tail call i32 (double*, i32, double*, i32, i32*, ...) bitcast (i32 (...)* @dp_all_indexes to i32 (double*, i32, double*, i32, i32*, ...)*)(double* %3, i32 %6, double* %8, i32 %10, i32* %23)
%33 = tail call i32 (double*, double*, i32, double*, double*, i32, i32, double*, i32*, i32, double*, i32*, i32, double*, i32*, double, ...) bitcast (i32 (...)* @dp_costs to i32 (double*, double*, i32, double*, double*, i32, i32, double*, i32*, i32, double*, i32*, i32, double*, i32*, double, ...)*)(double* %0, double* %1, i32 %5, double* %2, double* %3, i32 %6, i32 %4, double* %7, i32* %19, i32 %9, double* %8, i32* %23, i32 %10, double* %28, i32* %30, double %14)
%34 = tail call i32 (i32*, double*, i32, double*, i32, double*, double*, ...) bitcast (i32 (...)* @dp_build_gamma to i32 (i32*, double*, i32, double*, i32, double*, double*, ...)*)(i32* %30, double* %7, i32 %9, double* %8, i32 %10, double* %11, double* %12)
%35 = sitofp i32 %34 to double
store double %35, double* %13
tail call void @free(i8* %18)
tail call void @free(i8* %22)
tail call void @free(i8* %27)
tail call void @free(i8* %29)
ret void
}