void foo(double (*__restrict p)[4], double (*__restrict q)[4],
         double *__restrict prim, double scale, double pp, double pq) {
  int md, mc, mb, ma, p_index = 0;
  for (md = 0; md < 1; md++)
    for (mc = 0; mc < 1; mc++)
      for (mb = 0; mb < 1; mb++)
        for (ma = 0; ma < 4; ma++) {
          double tmp = scale * prim[p_index++];
          p[md][ma] = p[md][ma] - tmp * pp;
          q[mc][ma] = q[mc][ma] - tmp * pq;
        }
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jge    1284 <foo+0x184>
movl   $0x0,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jge    1271 <foo+0x171>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jge    125e <foo+0x15e>
movl   $0x0,-0x40(%rbp)
cmpl   $0x4,-0x40(%rbp)
jge    124b <foo+0x14b>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1160 <foo+0x60>
jmp    1250 <foo+0x150>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    114f <foo+0x4f>
jmp    1263 <foo+0x163>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    113e <foo+0x3e>
jmp    1276 <foo+0x176>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    112d <foo+0x2d>
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
movupd (%rdx),%xmm3
movapd 0xef4(%rip),%xmm4
xorpd  %xmm4,%xmm3
unpcklpd %xmm0,%xmm0
mulpd  %xmm0,%xmm3
movupd (%rdi),%xmm5
unpcklpd %xmm1,%xmm1
movapd %xmm3,%xmm6
mulpd  %xmm1,%xmm6
addpd  %xmm5,%xmm6
movupd %xmm6,(%rdi)
movupd (%rsi),%xmm5
unpcklpd %xmm2,%xmm2
mulpd  %xmm2,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm3,(%rsi)
movupd 0x10(%rdx),%xmm3
xorpd  %xmm4,%xmm3
mulpd  %xmm0,%xmm3
movupd 0x10(%rdi),%xmm0
mulpd  %xmm3,%xmm1
addpd  %xmm0,%xmm1
movupd %xmm1,0x10(%rdi)
movupd 0x10(%rsi),%xmm0
mulpd  %xmm2,%xmm3
addpd  %xmm0,%xmm3
movupd %xmm3,0x10(%rsi)
ret

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

LLVM IR (-O2):
define void @foo([4 x double]* noalias nocapture %0, [4 x double]* noalias nocapture %1, double* noalias nocapture %2, double %3, double %4, double %5) {
%7 = bitcast double* %2 to <2 x double>*
%8 = load <2 x double>, <2 x double>* %7
%9 = fneg <2 x double> %8
%10 = insertelement <2 x double> poison, double %3, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = fmul <2 x double> %11, %9
%13 = bitcast [4 x double]* %0 to <2 x double>*
%14 = load <2 x double>, <2 x double>* %13
%15 = insertelement <2 x double> poison, double %4, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %16, <2 x double> %14)
%18 = bitcast [4 x double]* %0 to <2 x double>*
store <2 x double> %17, <2 x double>* %18
%19 = bitcast [4 x double]* %1 to <2 x double>*
%20 = load <2 x double>, <2 x double>* %19
%21 = insertelement <2 x double> poison, double %5, i64 0
%22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
%23 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %22, <2 x double> %20)
%24 = bitcast [4 x double]* %1 to <2 x double>*
store <2 x double> %23, <2 x double>* %24
%25 = getelementptr inbounds double, double* %2, i64 2
%26 = getelementptr inbounds [4 x double], [4 x double]* %0, i64 0, i64 2
%27 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 2
%28 = bitcast double* %25 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fneg <2 x double> %29
%31 = fmul <2 x double> %11, %30
%32 = bitcast double* %26 to <2 x double>*
%33 = load <2 x double>, <2 x double>* %32
%34 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %16, <2 x double> %33)
%35 = bitcast double* %26 to <2 x double>*
store <2 x double> %34, <2 x double>* %35
%36 = bitcast double* %27 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %22, <2 x double> %37)
%39 = bitcast double* %27 to <2 x double>*
store <2 x double> %38, <2 x double>* %39
ret void
}