void compute(int flag, double rows[2][1024], double col[1024][32], double *prod,
             int num_rows) {
#pragma HLS inline off
  if (flag) {
    double local_prod[2][32];
#pragma HLS array_partition variable = local_prod dim = 1 complete
    int i, j, k;
    for (j = 0; j < 32; j++) {
#pragma HLS pipeline
      for (i = 0; i < 2; i++) {
#pragma HLS unroll
        local_prod[i][j] = 0.0;
      }
    }
    for (j = 0; j < 1024; j++) {
      for (k = 0; k < 32; k++) {
#pragma HLS pipeline
#pragma HLS dependence variable = local_prod inter false
        for (i = 0; i < 2; i++) {
#pragma HLS unroll
          local_prod[i][k] += rows[i][j] * col[j][k];
        }
      }
    }
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 32; j++) {
#pragma HLS pipeline
        prod[i * 1024 + j] = local_prod[i][j];
      }
    }
  }
}


x86 assembly (clang, -O0):
<compute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     133b <compute+0x23b>
movl   $0x0,-0x238(%rbp)
cmpl   $0x20,-0x238(%rbp)
jge    11a7 <compute+0xa7>
movl   $0x0,-0x234(%rbp)
cmpl   $0x2,-0x234(%rbp)
jge    118e <compute+0x8e>
movslq -0x234(%rbp),%rcx
lea    -0x230(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x238(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    1149 <compute+0x49>
jmp    1193 <compute+0x93>
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    1132 <compute+0x32>
movl   $0x0,-0x238(%rbp)
cmpl   $0x400,-0x238(%rbp)
jge    129f <compute+0x19f>
movl   $0x0,-0x23c(%rbp)
cmpl   $0x20,-0x23c(%rbp)
jge    1286 <compute+0x186>
movl   $0x0,-0x234(%rbp)
cmpl   $0x2,-0x234(%rbp)
jge    126d <compute+0x16d>
mov    -0x10(%rbp),%rax
movslq -0x234(%rbp),%rcx
shl    $0xd,%rcx
add    %rcx,%rax
movslq -0x238(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x238(%rbp),%rcx
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x23c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movslq -0x234(%rbp),%rcx
lea    -0x230(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x23c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11e2 <compute+0xe2>
jmp    1272 <compute+0x172>
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    11cb <compute+0xcb>
jmp    128b <compute+0x18b>
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    11b1 <compute+0xb1>
movl   $0x0,-0x234(%rbp)
cmpl   $0x2,-0x234(%rbp)
jge    1336 <compute+0x236>
movl   $0x0,-0x238(%rbp)
cmpl   $0x20,-0x238(%rbp)
jge    131d <compute+0x21d>
movslq -0x234(%rbp),%rcx
lea    -0x230(%rbp),%rax
shl    $0x8,%rcx
add    %rcx,%rax
movslq -0x238(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x234(%rbp),%ecx
shl    $0xa,%ecx
add    -0x238(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    12c0 <compute+0x1c0>
jmp    1322 <compute+0x222>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    12a9 <compute+0x1a9>
jmp    133b <compute+0x23b>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute>:
test   %edi,%edi
je     1236 <compute+0x116>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
lea    0x100(%rsp),%r14
mov    %rsp,%rdi
xor    %r13d,%r13d
mov    $0x200,%edx
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x10,%rbx
nop
movsd  (%r12,%r13,8),%xmm0
unpcklpd %xmm0,%xmm0
movsd  0x2000(%r12,%r13,8),%xmm1
unpcklpd %xmm1,%xmm1
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movupd -0x10(%rbx,%rax,8),%xmm2
movapd %xmm0,%xmm3
mulpd  %xmm2,%xmm3
addpd  (%rsp,%rax,8),%xmm3
movapd %xmm3,(%rsp,%rax,8)
mulpd  %xmm1,%xmm2
addpd  0x100(%rsp,%rax,8),%xmm2
movapd %xmm2,0x100(%rsp,%rax,8)
movupd (%rbx,%rax,8),%xmm2
movapd %xmm0,%xmm3
mulpd  %xmm2,%xmm3
addpd  0x10(%rsp,%rax,8),%xmm3
movapd %xmm3,0x10(%rsp,%rax,8)
mulpd  %xmm1,%xmm2
addpd  0x110(%rsp,%rax,8),%xmm2
movapd %xmm2,0x110(%rsp,%rax,8)
add    $0x4,%rax
cmp    $0x20,%rax
jne    1180 <compute+0x60>
add    $0x1,%r13
add    $0x100,%rbx
cmp    $0x400,%r13
jne    1160 <compute+0x40>
mov    %rsp,%rsi
mov    $0x100,%edx
mov    %r15,%rdi
call   1040 <memcpy@plt>
add    $0x2000,%r15
mov    $0x100,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @compute(i32 %0, [1024 x double]* %1, [32 x double]* %2, double* %3, i32 %4) {
%6 = alloca i32
%7 = alloca [1024 x double]*
%8 = alloca [32 x double]*
%9 = alloca double*
%10 = alloca i32
%11 = alloca [2 x [32 x double]]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store [1024 x double]* %1, [1024 x double]** %7
store [32 x double]* %2, [32 x double]** %8
store double* %3, double** %9
store i32 %4, i32* %10
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %118
17: ; preds = %5
store i32 0, i32* %13
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %13
%20 = icmp slt i32 %19, 32
br i1 %20, label %21, label %39
21: ; preds = %18
store i32 0, i32* %12
br label %22
22: ; preds = %32, %21
%23 = load i32, i32* %12
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %12
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %11, i64 0, i64 %27
%29 = load i32, i32* %13
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x double], [32 x double]* %28, i64 0, i64 %30
store double 0.000000e+00, double* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %12
%34 = add nsw i32 %33, 1
store i32 %34, i32* %12
br label %22
35: ; preds = %22
br label %36
36: ; preds = %35
%37 = load i32, i32* %13
%38 = add nsw i32 %37, 1
store i32 %38, i32* %13
br label %18
39: ; preds = %18
store i32 0, i32* %13
br label %40
40: ; preds = %84, %39
%41 = load i32, i32* %13
%42 = icmp slt i32 %41, 1024
br i1 %42, label %43, label %87
43: ; preds = %40
store i32 0, i32* %14
br label %44
44: ; preds = %80, %43
%45 = load i32, i32* %14
%46 = icmp slt i32 %45, 32
br i1 %46, label %47, label %83
47: ; preds = %44
store i32 0, i32* %12
br label %48
48: ; preds = %76, %47
%49 = load i32, i32* %12
%50 = icmp slt i32 %49, 2
br i1 %50, label %51, label %79
51: ; preds = %48
%52 = load [1024 x double]*, [1024 x double]** %7
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1024 x double], [1024 x double]* %52, i64 %54
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1024 x double], [1024 x double]* %55, i64 0, i64 %57
%59 = load double, double* %58
%60 = load [32 x double]*, [32 x double]** %8
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [32 x double], [32 x double]* %60, i64 %62
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [32 x double], [32 x double]* %63, i64 0, i64 %65
%67 = load double, double* %66
%68 = load i32, i32* %12
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %11, i64 0, i64 %69
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [32 x double], [32 x double]* %70, i64 0, i64 %72
%74 = load double, double* %73
%75 = call double @llvm.fmuladd.f64(double %59, double %67, double %74)
store double %75, double* %73
br label %76
76: ; preds = %51
%77 = load i32, i32* %12
%78 = add nsw i32 %77, 1
store i32 %78, i32* %12
br label %48
79: ; preds = %48
br label %80
80: ; preds = %79
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 1
store i32 %82, i32* %14
br label %44
83: ; preds = %44
br label %84
84: ; preds = %83
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %40
87: ; preds = %40
store i32 0, i32* %12
br label %88
88: ; preds = %114, %87
%89 = load i32, i32* %12
%90 = icmp slt i32 %89, 2
br i1 %90, label %91, label %117
91: ; preds = %88
store i32 0, i32* %13
br label %92
92: ; preds = %110, %91
%93 = load i32, i32* %13
%94 = icmp slt i32 %93, 32
br i1 %94, label %95, label %113
95: ; preds = %92
%96 = load i32, i32* %12
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %11, i64 0, i64 %97
%99 = load i32, i32* %13
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [32 x double], [32 x double]* %98, i64 0, i64 %100
%102 = load double, double* %101
%103 = load double*, double** %9
%104 = load i32, i32* %12
%105 = mul nsw i32 %104, 1024
%106 = load i32, i32* %13
%107 = add nsw i32 %105, %106
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds double, double* %103, i64 %108
store double %102, double* %109
br label %110
110: ; preds = %95
%111 = load i32, i32* %13
%112 = add nsw i32 %111, 1
store i32 %112, i32* %13
br label %92
113: ; preds = %92
br label %114
114: ; preds = %113
%115 = load i32, i32* %12
%116 = add nsw i32 %115, 1
store i32 %116, i32* %12
br label %88
117: ; preds = %88
br label %118
118: ; preds = %117, %5
ret void
}

LLVM IR (-O2):
define void @compute(i32 %0, [1024 x double]* nocapture %1, [32 x double]* nocapture %2, double* nocapture writeonly %3, i32 %4) {
%6 = alloca [2 x [32 x double]]
%7 = bitcast [2 x [32 x double]]* %6 to i8*
%8 = icmp eq i32 %0, 0
br i1 %8, label %62, label %9
9: ; preds = %5
%10 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %6, i64 0, i64 1, i64 0
%11 = bitcast double* %10 to i8*
%12 = bitcast [2 x [32 x double]]* %6 to i8*
br label %13
13: ; preds = %54, %9
%14 = phi i64 [ 0, %9 ], [ %55, %54 ]
%15 = getelementptr inbounds [1024 x double], [1024 x double]* %1, i64 1, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds [1024 x double], [1024 x double]* %1, i64 0, i64 %14
%18 = load double, double* %17
%19 = insertelement <2 x double> poison, double %18, i64 0
%20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
%21 = insertelement <2 x double> poison, double %16, i64 0
%22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
br label %23
23: ; preds = %23, %13
%24 = phi i64 [ 0, %13 ], [ %52, %23 ]
%25 = getelementptr inbounds [32 x double], [32 x double]* %2, i64 %14, i64 %24
%26 = bitcast double* %25 to <2 x double>*
%27 = load <2 x double>, <2 x double>* %26
%28 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %6, i64 0, i64 0, i64 %24
%29 = bitcast double* %28 to <2 x double>*
%30 = load <2 x double>, <2 x double>* %29
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %20, <2 x double> %27, <2 x double> %30)
%32 = bitcast double* %28 to <2 x double>*
store <2 x double> %31, <2 x double>* %32
%33 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %6, i64 0, i64 1, i64 %24
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> %27, <2 x double> %35)
%37 = bitcast double* %33 to <2 x double>*
store <2 x double> %36, <2 x double>* %37
%38 = or i64 %24, 2
%39 = getelementptr inbounds [32 x double], [32 x double]* %2, i64 %14, i64 %38
%40 = bitcast double* %39 to <2 x double>*
%41 = load <2 x double>, <2 x double>* %40
%42 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %6, i64 0, i64 0, i64 %38
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %20, <2 x double> %41, <2 x double> %44)
%46 = bitcast double* %42 to <2 x double>*
store <2 x double> %45, <2 x double>* %46
%47 = getelementptr inbounds [2 x [32 x double]], [2 x [32 x double]]* %6, i64 0, i64 1, i64 %38
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> %41, <2 x double> %49)
%51 = bitcast double* %47 to <2 x double>*
store <2 x double> %50, <2 x double>* %51
%52 = add nuw nsw i64 %24, 4
%53 = icmp eq i64 %52, 32
br i1 %53, label %54, label %23
54: ; preds = %23
%55 = add nuw nsw i64 %14, 1
%56 = icmp eq i64 %55, 1024
br i1 %56, label %57, label %13
57: ; preds = %54
%58 = bitcast double* %3 to i8*
%59 = bitcast [2 x [32 x double]]* %6 to i8*
%60 = getelementptr double, double* %3, i64 1024
%61 = bitcast double* %60 to i8*
br label %62
62: ; preds = %57, %5
ret void
}