void calc_dotprod(int numt, double sinx[], double cosx[], double wt[], int dord,
                  double *st, double *ct) {
  int i;
  unsigned long n2 = numt * dord;
  for (*st = 0, *ct = 0, i = 0; i < numt; i++) {
    *st += sinx[i] * wt[i + n2];
    *ct += cosx[i] * wt[i + n2];
  }
}


x86 assembly (clang, -O0):
<calc_dotprod>:
push   %rbp
mov    %rsp,%rbp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c7 <calc_dotprod+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    0x10(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1149 <calc_dotprod+0x49>
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_dotprod>:
mov    0x8(%rsp),%r10
movq   $0x0,(%r9)
movq   $0x0,(%r10)
test   %edi,%edi
jle    1161 <calc_dotprod+0x61>
imul   %edi,%r8d
movslq %r8d,%rax
mov    %edi,%edi
lea    (%rcx,%rax,8),%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movsd  (%rsi,%rax,8),%xmm0
mulsd  (%rcx,%rax,8),%xmm0
addsd  (%r9),%xmm0
movsd  %xmm0,(%r9)
movsd  (%rdx,%rax,8),%xmm0
mulsd  (%rcx,%rax,8),%xmm0
addsd  (%r10),%xmm0
movsd  %xmm0,(%r10)
add    $0x1,%rax
cmp    %rax,%rdi
jne    1130 <calc_dotprod+0x30>
ret

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

LLVM IR (-O2):
define void @calc_dotprod(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4, double* nocapture %5, double* nocapture %6) {
%8 = mul nsw i32 %4, %0
%9 = sext i32 %8 to i64
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %27, %13 ]
%15 = getelementptr inbounds double, double* %1, i64 %14
%16 = load double, double* %15
%17 = add nsw i64 %14, %9
%18 = getelementptr inbounds double, double* %3, i64 %17
%19 = load double, double* %18
%20 = load double, double* %5
%21 = tail call double @llvm.fmuladd.f64(double %16, double %19, double %20)
store double %21, double* %5
%22 = getelementptr inbounds double, double* %2, i64 %14
%23 = load double, double* %22
%24 = load double, double* %18
%25 = load double, double* %6
%26 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %25)
store double %26, double* %6
%27 = add nuw nsw i64 %14, 1
%28 = icmp eq i64 %27, %12
br i1 %28, label %29, label %13
29: ; preds = %13, %7
ret void
}