void r_sum_w_x(double **x, double *w, int n, int p, double *tmp, double *sum) {
  void scalar_vec(double *a, double b, double *c, int n);
  void sum_vec(double *a, double *b, double *c, int n);
  void reset_vec(double *a, int n);
  register int i;
  reset_vec(sum, p);
  for (i = 0; i < n; i++) {
    scalar_vec(x[i], w[i], tmp, p);
    sum_vec(sum, tmp, sum, p);
  };
}


x86 assembly (clang, -O0):
<r_sum_w_x>:
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
call   1050 <reset_vec@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b4 <r_sum_w_x+0x84>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <scalar_vec@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1040 <sum_vec@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1161 <r_sum_w_x+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_sum_w_x>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8,%r14
mov    %ecx,%ebp
mov    %edx,%r13d
mov    %rsi,(%rsp)
mov    %rdi,%r12
mov    %r9,%rdi
mov    %ecx,%esi
call   1050 <reset_vec@plt>
test   %r13d,%r13d
jle    11a1 <r_sum_w_x+0x71>
mov    %r13d,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%r15,8),%rdi
mov    (%rsp),%rax
movsd  (%rax,%r15,8),%xmm0
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <scalar_vec@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <sum_vec@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1170 <r_sum_w_x+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(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
store i32 0, i32* %13
br label %16
16: ; preds = %37, %6
%17 = load i32, i32* %13
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load double**, double*** %7
%22 = load i32, i32* %13
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double*, double** %21, i64 %23
%25 = load double*, double** %24
%26 = load double*, double** %8
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %11
%32 = load i32, i32* %10
%33 = load double*, double** %12
%34 = load double*, double** %11
%35 = load double*, double** %12
%36 = load i32, i32* %10
br label %37
37: ; preds = %20
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
store i32 %39, i32* %13
br label %16
40: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @r_sum_w_x(double** nocapture %0, double* nocapture %1, i32 %2, i32 %3, double* %4, double* %5) {
tail call void @reset_vec(double* %5, 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
%14 = getelementptr inbounds double, double* %1, i64 %11
%15 = load double, double* %14
tail call void @scalar_vec(double* %13, double %15, double* %4, i32 %3)
tail call void @sum_vec(double* %5, double* %4, double* %5, 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
}