#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double sqrt(double);
void cross(double res[3], const double v1[3], const double v2[3], int unitize) {
  res[0] = v1[1] * v2[2] - v1[2] * v2[1];
  res[1] = v1[2] * v2[0] - v1[0] * v2[2];
  res[2] = v1[0] * v2[1] - v1[1] * v2[0];
  if (unitize) {
    double l = sqrt(res[0] * res[0] + res[1] * res[1] + res[2] * res[2]);
    res[0] /= l;
    res[1] /= l;
    res[2] /= l;
  }
}


x86 assembly (clang, -O0):
<cross>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
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    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x10(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%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    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
cmpl   $0x0,-0x1c(%rbp)
je     12a1 <cross+0x191>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cross>:
push   %rbx
movsd  0x8(%rsi),%xmm1
movsd  0x8(%rdx),%xmm0
mulsd  0x10(%rsi),%xmm0
mulsd  0x10(%rdx),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
movsd  0x10(%rsi),%xmm2
movsd  0x10(%rdx),%xmm0
mulsd  (%rsi),%xmm0
mulsd  (%rdx),%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rdi)
movsd  (%rsi),%xmm0
movsd  (%rdx),%xmm3
mulsd  0x8(%rsi),%xmm3
mulsd  0x8(%rdx),%xmm0
subsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rdi)
test   %ecx,%ecx
je     11b5 <cross+0xa5>
mov    %rdi,%rbx
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     118e <cross+0x7e>
sqrtsd %xmm0,%xmm0
jmp    1193 <cross+0x83>
call   1030 <sqrt@plt>
movupd (%rbx),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,(%rbx)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @cross(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = getelementptr inbounds double, double* %1, i64 1
%6 = load double, double* %5
%7 = getelementptr inbounds double, double* %2, i64 2
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %1, i64 2
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %2, i64 1
%12 = load double, double* %11
%13 = fneg double %10
%14 = fmul double %12, %13
%15 = tail call double @llvm.fmuladd.f64(double %6, double %8, double %14)
store double %15, double* %0
%16 = load double, double* %9
%17 = load double, double* %2
%18 = load double, double* %1
%19 = load double, double* %7
%20 = fneg double %18
%21 = fmul double %19, %20
%22 = tail call double @llvm.fmuladd.f64(double %16, double %17, double %21)
%23 = getelementptr inbounds double, double* %0, i64 1
store double %22, double* %23
%24 = load double, double* %1
%25 = load double, double* %11
%26 = load double, double* %5
%27 = load double, double* %2
%28 = fneg double %26
%29 = fmul double %27, %28
%30 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %29)
%31 = getelementptr inbounds double, double* %0, i64 2
store double %30, double* %31
%32 = icmp eq i32 %3, 0
br i1 %32, label %46, label %33
33: ; preds = %4
%34 = fmul double %22, %22
%35 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %34)
%36 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %35)
%37 = tail call double @sqrt(double %36)
%38 = bitcast double* %0 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = insertelement <2 x double> poison, double %37, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
%42 = fdiv <2 x double> %39, %41
%43 = bitcast double* %0 to <2 x double>*
store <2 x double> %42, <2 x double>* %43
%44 = load double, double* %31
%45 = fdiv double %44, %37
store double %45, double* %31
br label %46
46: ; preds = %33, %4
ret void
}