void malign(double v[3], double axis[3], double m[3][3]) {
  double vn[3], axisn[3], cross[3], dot, skew[3][3], across, k;
  vnorm2(v, vn);
  vnorm2(axis, axisn);
  dot = vdot(vn, axisn);
  if (dot >= 1.0) {
    mleye(3, m);
  } else if (dot <= -1.0) {
    vcomplement(axis, cross);
    mrotate(3.14159265358979323846264338327950288419716939937510582, cross, m);
  } else {
    vcross(vn, axisn, cross);
    across = vabs(cross);
    k = (1 - dot) / (((across) * (across)));
    skew[0][0] = 0.0;
    skew[0][1] = -cross[2];
    skew[0][2] = cross[1];
    skew[1][0] = cross[2];
    skew[1][1] = 0.0;
    skew[1][2] = -cross[0];
    skew[2][0] = -cross[1];
    skew[2][1] = cross[0];
    skew[2][2] = 0.0;
    mleye(3, m);
    madd(m, skew, m);
    mmmul(skew, skew, skew);
    mscale(k, skew, skew);
    madd(m, skew, m);
  }
}


x86 assembly (clang, -O0):
<malign>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x0,%al
call   1040 <vnorm2@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1040 <vnorm2@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1090 <vdot@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  0xe06(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1219 <malign+0x79>
mov    -0x18(%rbp),%rsi
mov    $0x3,%edi
mov    $0x0,%al
call   1030 <mleye@plt>
jmp    13d5 <malign+0x235>
movsd  0xde7(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jb     1257 <malign+0xb7>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1080 <vcomplement@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  0xdc5(%rip),%xmm0
mov    $0x1,%al
call   1060 <mrotate@plt>
jmp    13d0 <malign+0x230>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
mov    $0x0,%al
call   1070 <vcross@plt>
lea    -0x70(%rbp),%rdi
mov    $0x0,%al
call   10b0 <vabs@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  0xd77(%rip),%xmm0
subsd  -0x78(%rbp),%xmm0
movsd  -0xc8(%rbp),%xmm1
ff
mulsd  -0xc8(%rbp),%xmm1
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x3,%edi
mov    $0x0,%al
call   1030 <mleye@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   10a0 <madd@plt>
lea    -0xc0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
mov    $0x0,%al
call   10c0 <mmmul@plt>
movsd  -0xd0(%rbp),%xmm0
ff
lea    -0xc0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    $0x1,%al
call   1050 <mscale@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   10a0 <madd@plt>
jmp    13d5 <malign+0x235>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malign>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xa0(%rsp),%r12
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <vnorm2@plt>
lea    0x80(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <vnorm2@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <vdot@plt>
test   %eax,%eax
jle    1200 <malign+0x60>
mov    $0x3,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <mleye@plt>
jmp    132b <malign+0x18b>
js     1304 <malign+0x164>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xa0(%rsp),%rdi
lea    0x80(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <vcross@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   10b0 <vabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdb8(%rip),%xmm1
subsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movq   $0x0,0x30(%rsp)
movsd  0x20(%rsp),%xmm0
movaps 0xd9e(%rip),%xmm1
movaps %xmm0,%xmm2
xorps  %xmm1,%xmm2
movaps 0x10(%rsp),%xmm3
shufps $0xe4,%xmm3,%xmm2
movups %xmm2,0x38(%rsp)
movsd  %xmm0,0x48(%rsp)
movq   $0x0,0x50(%rsp)
xorps  %xmm3,%xmm1
movups %xmm1,0x58(%rsp)
movlps %xmm3,0x68(%rsp)
movq   $0x0,0x70(%rsp)
mov    $0x3,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <mleye@plt>
lea    0x30(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <madd@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <mmmul@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <mscale@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <madd@plt>
jmp    132b <malign+0x18b>
lea    0x10(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <vcomplement@plt>
movsd  0xcea(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <mrotate@plt>
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @malign(double* %0, double* %1, [3 x double]* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca [3 x double]*
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = alloca [3 x double]
%10 = alloca double
%11 = alloca [3 x [3 x double]]
%12 = alloca double
%13 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store [3 x double]* %2, [3 x double]** %6
%14 = load double*, double** %4
%15 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%16 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vnorm2 to i32 (double*, double*, ...)*)(double* %14, double* %15)
%17 = load double*, double** %5
%18 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%19 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vnorm2 to i32 (double*, double*, ...)*)(double* %17, double* %18)
%20 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%21 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%22 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vdot to i32 (double*, double*, ...)*)(double* %20, double* %21)
%23 = sitofp i32 %22 to double
store double %23, double* %10
%24 = load double, double* %10
%25 = fcmp oge double %24, 1.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %3
%27 = load [3 x double]*, [3 x double]** %6
%28 = call i32 (i32, [3 x double]*, ...) bitcast (i32 (...)* @mleye to i32 (i32, [3 x double]*, ...)*)(i32 3, [3 x double]* %27)
br label %105
29: ; preds = %3
%30 = load double, double* %10
%31 = fcmp ole double %30, -1.000000e+00
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load double*, double** %5
%34 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%35 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vcomplement to i32 (double*, double*, ...)*)(double* %33, double* %34)
%36 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%37 = load [3 x double]*, [3 x double]** %6
%38 = call i32 (double, double*, [3 x double]*, ...) bitcast (i32 (...)* @mrotate to i32 (double, double*, [3 x double]*, ...)*)(double 0x400921FB54442D18, double* %36, [3 x double]* %37)
br label %104
39: ; preds = %29
%40 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%41 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%42 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%43 = call i32 (double*, double*, double*, ...) bitcast (i32 (...)* @vcross to i32 (double*, double*, double*, ...)*)(double* %40, double* %41, double* %42)
%44 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%45 = call i32 (double*, ...) bitcast (i32 (...)* @vabs to i32 (double*, ...)*)(double* %44)
%46 = sitofp i32 %45 to double
store double %46, double* %12
%47 = load double, double* %10
%48 = fsub double 1.000000e+00, %47
%49 = load double, double* %12
%50 = load double, double* %12
%51 = fmul double %49, %50
%52 = fdiv double %48, %51
store double %52, double* %13
%53 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%54 = getelementptr inbounds [3 x double], [3 x double]* %53, i64 0, i64 0
store double 0.000000e+00, double* %54
%55 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%56 = load double, double* %55
%57 = fneg double %56
%58 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%59 = getelementptr inbounds [3 x double], [3 x double]* %58, i64 0, i64 1
store double %57, double* %59
%60 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%61 = load double, double* %60
%62 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%63 = getelementptr inbounds [3 x double], [3 x double]* %62, i64 0, i64 2
store double %61, double* %63
%64 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%65 = load double, double* %64
%66 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 1
%67 = getelementptr inbounds [3 x double], [3 x double]* %66, i64 0, i64 0
store double %65, double* %67
%68 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 1
%69 = getelementptr inbounds [3 x double], [3 x double]* %68, i64 0, i64 1
store double 0.000000e+00, double* %69
%70 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%71 = load double, double* %70
%72 = fneg double %71
%73 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 1
%74 = getelementptr inbounds [3 x double], [3 x double]* %73, i64 0, i64 2
store double %72, double* %74
%75 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%76 = load double, double* %75
%77 = fneg double %76
%78 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 2
%79 = getelementptr inbounds [3 x double], [3 x double]* %78, i64 0, i64 0
store double %77, double* %79
%80 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%81 = load double, double* %80
%82 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 2
%83 = getelementptr inbounds [3 x double], [3 x double]* %82, i64 0, i64 1
store double %81, double* %83
%84 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 2
%85 = getelementptr inbounds [3 x double], [3 x double]* %84, i64 0, i64 2
store double 0.000000e+00, double* %85
%86 = load [3 x double]*, [3 x double]** %6
%87 = call i32 (i32, [3 x double]*, ...) bitcast (i32 (...)* @mleye to i32 (i32, [3 x double]*, ...)*)(i32 3, [3 x double]* %86)
%88 = load [3 x double]*, [3 x double]** %6
%89 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%90 = load [3 x double]*, [3 x double]** %6
%91 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @madd to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %88, [3 x double]* %89, [3 x double]* %90)
%92 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%93 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%94 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%95 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @mmmul to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %92, [3 x double]* %93, [3 x double]* %94)
%96 = load double, double* %13
%97 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%98 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%99 = call i32 (double, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @mscale to i32 (double, [3 x double]*, [3 x double]*, ...)*)(double %96, [3 x double]* %97, [3 x double]* %98)
%100 = load [3 x double]*, [3 x double]** %6
%101 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%102 = load [3 x double]*, [3 x double]** %6
%103 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @madd to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %100, [3 x double]* %101, [3 x double]* %102)
br label %104
104: ; preds = %39, %32
br label %105
105: ; preds = %104, %26
ret void
}

LLVM IR (-O2):
define void @malign(double* %0, double* %1, [3 x double]* %2) {
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = alloca [3 x [3 x double]]
%8 = bitcast [3 x double]* %4 to i8*
%9 = bitcast [3 x double]* %5 to i8*
%10 = bitcast [3 x double]* %6 to i8*
%11 = bitcast [3 x [3 x double]]* %7 to i8*
%12 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%13 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vnorm2 to i32 (double*, double*, ...)*)(double* %0, double* %12)
%14 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%15 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vnorm2 to i32 (double*, double*, ...)*)(double* %1, double* %14)
%16 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vdot to i32 (double*, double*, ...)*)(double* %12, double* %14)
%17 = sitofp i32 %16 to double
%18 = icmp sgt i32 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = call i32 (i32, [3 x double]*, ...) bitcast (i32 (...)* @mleye to i32 (i32, [3 x double]*, ...)*)(i32 3, [3 x double]* %2)
br label %57
21: ; preds = %3
%22 = icmp slt i32 %16, 0
%23 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
br i1 %22, label %24, label %27
24: ; preds = %21
%25 = call i32 (double*, double*, ...) bitcast (i32 (...)* @vcomplement to i32 (double*, double*, ...)*)(double* %1, double* %23)
%26 = call i32 (double, double*, [3 x double]*, ...) bitcast (i32 (...)* @mrotate to i32 (double, double*, [3 x double]*, ...)*)(double 0x400921FB54442D18, double* %23, [3 x double]* %2)
br label %57
27: ; preds = %21
%28 = call i32 (double*, double*, double*, ...) bitcast (i32 (...)* @vcross to i32 (double*, double*, double*, ...)*)(double* %12, double* %14, double* %23)
%29 = call i32 (double*, ...) bitcast (i32 (...)* @vabs to i32 (double*, ...)*)(double* %23)
%30 = sitofp i32 %29 to double
%31 = fsub double 1.000000e+00, %17
%32 = fmul double %30, %30
%33 = fdiv double %31, %32
%34 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0
%35 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0, i64 0
store double 0.000000e+00, double* %35
%36 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%37 = load double, double* %36
%38 = fneg double %37
%39 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0, i64 1
store double %38, double* %39
%40 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0, i64 2
%41 = bitcast [3 x double]* %6 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = extractelement <2 x double> %42, i64 1
store double %43, double* %40
%44 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 1, i64 0
store double %37, double* %44
%45 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 1, i64 1
store double 0.000000e+00, double* %45
%46 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 1, i64 2
%47 = fneg <2 x double> %42
%48 = bitcast double* %46 to <2 x double>*
store <2 x double> %47, <2 x double>* %48
%49 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 2, i64 1
%50 = extractelement <2 x double> %42, i64 0
store double %50, double* %49
%51 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 2, i64 2
store double 0.000000e+00, double* %51
%52 = call i32 (i32, [3 x double]*, ...) bitcast (i32 (...)* @mleye to i32 (i32, [3 x double]*, ...)*)(i32 3, [3 x double]* %2)
%53 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @madd to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %2, [3 x double]* %34, [3 x double]* %2)
%54 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @mmmul to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %34, [3 x double]* %34, [3 x double]* %34)
%55 = call i32 (double, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @mscale to i32 (double, [3 x double]*, [3 x double]*, ...)*)(double %33, [3 x double]* %34, [3 x double]* %34)
%56 = call i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...) bitcast (i32 (...)* @madd to i32 ([3 x double]*, [3 x double]*, [3 x double]*, ...)*)([3 x double]* %2, [3 x double]* %34, [3 x double]* %2)
br label %57
57: ; preds = %24, %27, %19
ret void
}