double multiplica_vector(int col1, int col2, double **matriz) {
  double multacum = 0;
  int i;
  for (i = 0; i < 10; i++) {
    multacum = multacum + matriz[i][col1] * matriz[i][col2];
  }
  return multacum;
}


x86 assembly (clang, -O0):
<multiplica_vector>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1171 <multiplica_vector+0x71>
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111d <multiplica_vector+0x1d>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiplica_vector>:
movslq %edi,%rcx
movslq %esi,%rax
mov    (%rdx),%rsi
mov    0x8(%rdx),%rdi
movsd  (%rsi,%rcx,8),%xmm0
mulsd  (%rsi,%rax,8),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%rdi,%rcx,8),%xmm0
mulsd  (%rdi,%rax,8),%xmm0
addsd  %xmm1,%xmm0
mov    0x10(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm1
mulsd  (%rsi,%rax,8),%xmm1
mov    0x18(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm2
mulsd  (%rsi,%rax,8),%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mov    0x20(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm0
mulsd  (%rsi,%rax,8),%xmm0
addsd  %xmm2,%xmm0
mov    0x28(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm1
mulsd  (%rsi,%rax,8),%xmm1
addsd  %xmm0,%xmm1
mov    0x30(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm0
mulsd  (%rsi,%rax,8),%xmm0
mov    0x38(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm2
mulsd  (%rsi,%rax,8),%xmm2
addsd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
mov    0x40(%rdx),%rsi
movsd  (%rsi,%rcx,8),%xmm1
mulsd  (%rsi,%rax,8),%xmm1
addsd  %xmm2,%xmm1
mov    0x48(%rdx),%rdx
movsd  (%rdx,%rcx,8),%xmm0
mulsd  (%rdx,%rax,8),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @multiplica_vector(i32 %0, i32 %1, double** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double**
%7 = alloca double
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double** %2, double*** %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %33, %3
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = load double, double* %7
%14 = load double**, double*** %6
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double*, double** %14, i64 %16
%18 = load double*, double** %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double**, double*** %6
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double*, double** %23, i64 %25
%27 = load double*, double** %26
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = call double @llvm.fmuladd.f64(double %22, double %31, double %13)
store double %32, double* %7
br label %33
33: ; preds = %12
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %9
36: ; preds = %9
%37 = load double, double* %7
ret double %37
}

LLVM IR (-O2):
define double @multiplica_vector(i32 %0, i32 %1, double** nocapture %2) {
%4 = sext i32 %0 to i64
%5 = sext i32 %1 to i64
%6 = load double*, double** %2
%7 = getelementptr inbounds double, double* %6, i64 %4
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %6, i64 %5
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double 0.000000e+00)
%12 = getelementptr inbounds double*, double** %2, i64 1
%13 = load double*, double** %12
%14 = getelementptr inbounds double, double* %13, i64 %4
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %13, i64 %5
%17 = load double, double* %16
%18 = tail call double @llvm.fmuladd.f64(double %15, double %17, double %11)
%19 = getelementptr inbounds double*, double** %2, i64 2
%20 = load double*, double** %19
%21 = getelementptr inbounds double, double* %20, i64 %4
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %20, i64 %5
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %18)
%26 = getelementptr inbounds double*, double** %2, i64 3
%27 = load double*, double** %26
%28 = getelementptr inbounds double, double* %27, i64 %4
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %27, i64 %5
%31 = load double, double* %30
%32 = tail call double @llvm.fmuladd.f64(double %29, double %31, double %25)
%33 = getelementptr inbounds double*, double** %2, i64 4
%34 = load double*, double** %33
%35 = getelementptr inbounds double, double* %34, i64 %4
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %34, i64 %5
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %36, double %38, double %32)
%40 = getelementptr inbounds double*, double** %2, i64 5
%41 = load double*, double** %40
%42 = getelementptr inbounds double, double* %41, i64 %4
%43 = load double, double* %42
%44 = getelementptr inbounds double, double* %41, i64 %5
%45 = load double, double* %44
%46 = tail call double @llvm.fmuladd.f64(double %43, double %45, double %39)
%47 = getelementptr inbounds double*, double** %2, i64 6
%48 = load double*, double** %47
%49 = getelementptr inbounds double, double* %48, i64 %4
%50 = load double, double* %49
%51 = getelementptr inbounds double, double* %48, i64 %5
%52 = load double, double* %51
%53 = tail call double @llvm.fmuladd.f64(double %50, double %52, double %46)
%54 = getelementptr inbounds double*, double** %2, i64 7
%55 = load double*, double** %54
%56 = getelementptr inbounds double, double* %55, i64 %4
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %55, i64 %5
%59 = load double, double* %58
%60 = tail call double @llvm.fmuladd.f64(double %57, double %59, double %53)
%61 = getelementptr inbounds double*, double** %2, i64 8
%62 = load double*, double** %61
%63 = getelementptr inbounds double, double* %62, i64 %4
%64 = load double, double* %63
%65 = getelementptr inbounds double, double* %62, i64 %5
%66 = load double, double* %65
%67 = tail call double @llvm.fmuladd.f64(double %64, double %66, double %60)
%68 = getelementptr inbounds double*, double** %2, i64 9
%69 = load double*, double** %68
%70 = getelementptr inbounds double, double* %69, i64 %4
%71 = load double, double* %70
%72 = getelementptr inbounds double, double* %69, i64 %5
%73 = load double, double* %72
%74 = tail call double @llvm.fmuladd.f64(double %71, double %73, double %67)
ret double %74
}