void r_sum_w_x_xprime(double **x, double *w, int n, int p, double **tmp,
                      double **ans) {
  void sum_mat(double **a, double **b, double **c, int n, int m);
  void matias_vec_vec(double **a, double *v1, double *v2, int n);
  void scalar_mat(double **a, double b, double **c, int n, int m);
  void reset_mat(double **a, int n, int m);
  register int i;
  reset_mat(ans, p, p);
  for (i = 0; i < n; i++) {
    matias_vec_vec(tmp, x[i], x[i], p);
    scalar_mat(tmp, w[i], tmp, p, p);
    sum_mat(ans, tmp, ans, p, p);
  };
}


x86 assembly (clang, -O0):
<r_sum_w_x_xprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <reset_mat@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <r_sum_w_x_xprime+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%ecx
call   1050 <matias_vec_vec@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <scalar_mat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <sum_mat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1174 <r_sum_w_x_xprime+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_sum_w_x_xprime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%rbx
mov    %ecx,%ebp
mov    %edx,%r13d
mov    %rsi,(%rsp)
mov    %rdi,%r12
mov    %r9,%rdi
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <reset_mat@plt>
test   %r13d,%r13d
jle    11c6 <r_sum_w_x_xprime+0x86>
mov    %r13d,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%r15,8),%rdx
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %ebp,%ecx
call   1050 <matias_vec_vec@plt>
mov    (%rsp),%rax
movsd  (%rax,%r15,8),%xmm0
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
call   1040 <scalar_mat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1030 <sum_mat@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1180 <r_sum_w_x_xprime+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @r_sum_w_x_xprime(double** %0, double* %1, i32 %2, i32 %3, double** %4, double** %5) {
%7 = alloca double**
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
%12 = alloca double**
%13 = alloca i32
store double** %0, double*** %7
store double* %1, double** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double** %4, double*** %11
store double** %5, double*** %12
%14 = load double**, double*** %12
%15 = load i32, i32* %10
%16 = load i32, i32* %10
store i32 0, i32* %13
br label %17
17: ; preds = %48, %6
%18 = load i32, i32* %13
%19 = load i32, i32* %9
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %51
21: ; preds = %17
%22 = load double**, double*** %11
%23 = load double**, double*** %7
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double*, double** %23, i64 %25
%27 = load double*, double** %26
%28 = load double**, double*** %7
%29 = load i32, i32* %13
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = load i32, i32* %10
%34 = load double**, double*** %11
%35 = load double*, double** %8
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double**, double*** %11
%41 = load i32, i32* %10
%42 = load i32, i32* %10
%43 = load double**, double*** %12
%44 = load double**, double*** %11
%45 = load double**, double*** %12
%46 = load i32, i32* %10
%47 = load i32, i32* %10
br label %48
48: ; preds = %21
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
br label %17
51: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @r_sum_w_x_xprime(double** nocapture %0, double* nocapture %1, i32 %2, i32 %3, double** %4, double** %5) {
tail call void @reset_mat(double** %5, i32 %3, i32 %3)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %18
8: ; preds = %6
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds double*, double** %0, i64 %11
%13 = load double*, double** %12
tail call void @matias_vec_vec(double** %4, double* %13, double* %13, i32 %3)
%14 = getelementptr inbounds double, double* %1, i64 %11
%15 = load double, double* %14
tail call void @scalar_mat(double** %4, double %15, double** %4, i32 %3, i32 %3)
tail call void @sum_mat(double** %5, double** %4, double** %5, i32 %3, i32 %3)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %6
ret void
}