void qh_crossproduct(int dim, double vecA[3], double vecB[3], double vecC[3]) {
  if (dim == 3) {
    vecC[0] = ((vecA[1]) * (vecB[2]) - (vecA[2]) * (vecB[1]));
    vecC[1] = -((vecA[0]) * (vecB[2]) - (vecA[2]) * (vecB[0]));
    vecC[2] = ((vecA[0]) * (vecB[1]) - (vecA[1]) * (vecB[0]));
  }
}


x86 assembly (clang, -O0):
<qh_crossproduct>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    1213 <qh_crossproduct+0x113>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<qh_crossproduct>:
cmp    $0x3,%edi
jne    115f <qh_crossproduct+0x5f>
movsd  0x8(%rsi),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  0x10(%rsi),%xmm1
mulsd  0x10(%rdx),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rcx)
movsd  (%rsi),%xmm0
movsd  (%rdx),%xmm1
mulsd  0x10(%rsi),%xmm1
mulsd  0x10(%rdx),%xmm0
subsd  %xmm1,%xmm0
xorpd  0xec1(%rip),%xmm0
movlpd %xmm0,0x8(%rcx)
movsd  (%rsi),%xmm0
movsd  (%rdx),%xmm1
mulsd  0x8(%rsi),%xmm1
mulsd  0x8(%rdx),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rcx)
ret

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

LLVM IR (-O2):
define void @qh_crossproduct(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture writeonly %3) {
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %35
6: ; preds = %4
%7 = getelementptr inbounds double, double* %1, i64 1
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %2, i64 2
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %1, i64 2
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %2, i64 1
%14 = load double, double* %13
%15 = fneg double %12
%16 = fmul double %14, %15
%17 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %16)
store double %17, double* %3
%18 = load double, double* %1
%19 = load double, double* %9
%20 = load double, double* %11
%21 = load double, double* %2
%22 = fneg double %20
%23 = fmul double %21, %22
%24 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %23)
%25 = fneg double %24
%26 = getelementptr inbounds double, double* %3, i64 1
store double %25, double* %26
%27 = load double, double* %1
%28 = load double, double* %13
%29 = load double, double* %7
%30 = load double, double* %2
%31 = fneg double %29
%32 = fmul double %30, %31
%33 = tail call double @llvm.fmuladd.f64(double %27, double %28, double %32)
%34 = getelementptr inbounds double, double* %3, i64 2
store double %33, double* %34
br label %35
35: ; preds = %6, %4
ret void
}