#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 M_PI;
double acos(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ matCalcCross(double *, double *, double *);
double matCalcDot(double *, double *);
int /*<<< orphan*/ matMakeRotMat(double, double, double, double, double *);
int /*<<< orphan*/ matTranspose(double *, double *);
double sqrt(double);
int /*<<< orphan*/ stderr;
int matTransformAtoB(double oa[3], double ob[3], double mat[16]) {
  double a[4], b[4];
  double axis[3], angle, dot, la, lb;
  a[0] = oa[0];
  a[1] = oa[1];
  a[2] = oa[2];
  a[3] = 1.0;
  b[0] = ob[0];
  b[1] = ob[1];
  b[2] = ob[2];
  b[3] = 1.0;
  la = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
  lb = sqrt(b[0] * b[0] + b[1] * b[1] + b[2] * b[2]);
  if (la * lb == 0.0) {
    fprintf(stderr, "error in matTransform\n");
    return -1;
  }
  matCalcCross(a, b, axis);
  dot = matCalcDot(a, b);
  angle = (180.0 / M_PI) * (acos(dot / (la * lb)));
  matMakeRotMat(angle, axis[0], axis[1], axis[2], mat);
  matTranspose(mat, mat);
  return 0;
}


x86 assembly (clang, -O0):
<matTransformAtoB>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe48(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe12(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x60(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
mulsd  -0xa0(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ad <matTransformAtoB+0x13d>
jp     12ad <matTransformAtoB+0x13d>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135a <matTransformAtoB+0x1ea>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1040 <matCalcCross@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <matCalcDot@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xd2d(%rip),%xmm0
mov    0x2d06(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x98(%rbp),%xmm1
ff
mulsd  -0xa0(%rbp),%xmm1
ff
divsd  %xmm1,%xmm0
call   1050 <acos@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x80(%rbp),%xmm1
movsd  -0x78(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm3
mov    -0x20(%rbp),%rdi
call   1080 <matMakeRotMat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <matTranspose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matTransformAtoB>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdx,%r14
movupd (%rdi),%xmm1
movapd %xmm1,0x60(%rsp)
movsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x70(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x78(%rsp)
movupd (%rsi),%xmm4
movapd %xmm4,0x40(%rsp)
movsd  0x10(%rsi),%xmm3
movsd  %xmm3,0x50(%rsp)
mov    %rax,0x58(%rsp)
movapd %xmm1,%xmm2
mulpd  %xmm1,%xmm2
unpckhpd %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11ec <matTransformAtoB+0x7c>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1211 <matTransformAtoB+0xa1>
movsd  %xmm3,0x8(%rsp)
movapd %xmm4,0x10(%rsp)
call   1070 <sqrt@plt>
xorpd  %xmm2,%xmm2
movapd 0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm1
movapd %xmm4,%xmm0
mulpd  %xmm4,%xmm0
unpckhpd %xmm0,%xmm0
mulsd  %xmm4,%xmm4
addsd  %xmm0,%xmm4
mulsd  %xmm3,%xmm3
addsd  %xmm4,%xmm3
ucomisd %xmm2,%xmm3
jb     123c <matTransformAtoB+0xcc>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    1251 <matTransformAtoB+0xe1>
movapd %xmm3,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    127d <matTransformAtoB+0x10d>
jp     127d <matTransformAtoB+0x10d>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12f9 <matTransformAtoB+0x189>
lea    0x60(%rsp),%rbx
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
movsd  %xmm1,0x8(%rsp)
call   1040 <matCalcCross@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <matCalcDot@plt>
mov    0x2d39(%rip),%rax
movsd  0xd49(%rip),%xmm1
divsd  (%rax),%xmm1
movsd  %xmm1,0x10(%rsp)
divsd  0x8(%rsp),%xmm0
call   1050 <acos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
movsd  0x30(%rsp),%xmm3
mov    %r14,%rdi
call   1080 <matMakeRotMat@plt>
mov    %r14,%rdi
mov    %r14,%rsi
call   1030 <matTranspose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"error in matTransform\0A\00"
@M_PI = global double 0.000000e+00
define i32 @matTransformAtoB(double* %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca [4 x double]
%9 = alloca [4 x double]
%10 = alloca [3 x double]
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
store double %17, double* %18
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
store double %21, double* %22
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 2
%25 = load double, double* %24
%26 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
store double %25, double* %26
%27 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 3
store double 1.000000e+00, double* %27
%28 = load double*, double** %6
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = load double, double* %29
%31 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
store double %30, double* %31
%32 = load double*, double** %6
%33 = getelementptr inbounds double, double* %32, i64 1
%34 = load double, double* %33
%35 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 1
store double %34, double* %35
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 2
%38 = load double, double* %37
%39 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
store double %38, double* %39
%40 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 3
store double 1.000000e+00, double* %40
%41 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%42 = load double, double* %41
%43 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%44 = load double, double* %43
%45 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
%46 = load double, double* %45
%47 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
%48 = load double, double* %47
%49 = fmul double %46, %48
%50 = call double @llvm.fmuladd.f64(double %42, double %44, double %49)
%51 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
%52 = load double, double* %51
%53 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
%54 = load double, double* %53
%55 = call double @llvm.fmuladd.f64(double %52, double %54, double %50)
%56 = call double @sqrt(double %55)
store double %56, double* %13
%57 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%58 = load double, double* %57
%59 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%60 = load double, double* %59
%61 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 1
%62 = load double, double* %61
%63 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 1
%64 = load double, double* %63
%65 = fmul double %62, %64
%66 = call double @llvm.fmuladd.f64(double %58, double %60, double %65)
%67 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
%68 = load double, double* %67
%69 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
%70 = load double, double* %69
%71 = call double @llvm.fmuladd.f64(double %68, double %70, double %66)
%72 = call double @sqrt(double %71)
store double %72, double* %14
%73 = load double, double* %13
%74 = load double, double* %14
%75 = fmul double %73, %74
%76 = fcmp oeq double %75, 0.000000e+00
br i1 %76, label %77, label %80
77: ; preds = %3
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %109
80: ; preds = %3
%81 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%82 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%83 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%84 = call i32 @matCalcCross(double* %81, double* %82, double* %83)
%85 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%86 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%87 = call double @matCalcDot(double* %85, double* %86)
store double %87, double* %12
%88 = load double, double* @M_PI
%89 = fdiv double 1.800000e+02, %88
%90 = load double, double* %12
%91 = load double, double* %13
%92 = load double, double* %14
%93 = fmul double %91, %92
%94 = fdiv double %90, %93
%95 = call double @acos(double %94)
%96 = fmul double %89, %95
store double %96, double* %11
%97 = load double, double* %11
%98 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%99 = load double, double* %98
%100 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%101 = load double, double* %100
%102 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%103 = load double, double* %102
%104 = load double*, double** %7
%105 = call i32 @matMakeRotMat(double %97, double %99, double %101, double %103, double* %104)
%106 = load double*, double** %7
%107 = load double*, double** %7
%108 = call i32 @matTranspose(double* %106, double* %107)
store i32 0, i32* %4
br label %109
109: ; preds = %80, %77
%110 = load i32, i32* %4
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"error in matTransform\0A\00"
@M_PI = global double 0.000000e+00
define i32 @matTransformAtoB(double* nocapture %0, double* nocapture %1, double* %2) {
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [3 x double]
%7 = bitcast [4 x double]* %4 to i8*
%8 = bitcast [4 x double]* %5 to i8*
%9 = bitcast [3 x double]* %6 to i8*
%10 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%11 = bitcast double* %0 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
%13 = bitcast [4 x double]* %4 to <2 x double>*
store <2 x double> %12, <2 x double>* %13
%14 = getelementptr inbounds double, double* %0, i64 2
%15 = load double, double* %14
%16 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
store double %15, double* %16
%17 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
store double 1.000000e+00, double* %17
%18 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%19 = bitcast double* %1 to <2 x double>*
%20 = load <2 x double>, <2 x double>* %19
%21 = bitcast [4 x double]* %5 to <2 x double>*
store <2 x double> %20, <2 x double>* %21
%22 = getelementptr inbounds double, double* %1, i64 2
%23 = load double, double* %22
%24 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
store double %23, double* %24
%25 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
store double 1.000000e+00, double* %25
%26 = fmul <2 x double> %12, %12
%27 = extractelement <2 x double> %26, i64 1
%28 = extractelement <2 x double> %12, i64 0
%29 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %27)
%30 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %29)
%31 = tail call double @sqrt(double %30)
%32 = fmul <2 x double> %20, %20
%33 = extractelement <2 x double> %32, i64 1
%34 = extractelement <2 x double> %20, i64 0
%35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %33)
%36 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %35)
%37 = tail call double @sqrt(double %36)
%38 = fmul double %31, %37
%39 = fcmp oeq double %38, 0.000000e+00
br i1 %39, label %40, label %43
40: ; preds = %3
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %59
43: ; preds = %3
%44 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%45 = call i32 @matCalcCross(double* %10, double* %18, double* %44)
%46 = call double @matCalcDot(double* %10, double* %18)
%47 = load double, double* @M_PI
%48 = fdiv double 1.800000e+02, %47
%49 = fdiv double %46, %38
%50 = call double @acos(double %49)
%51 = fmul double %48, %50
%52 = load double, double* %44
%53 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%54 = load double, double* %53
%55 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%56 = load double, double* %55
%57 = call i32 @matMakeRotMat(double %51, double %52, double %54, double %56, double* %2)
%58 = call i32 @matTranspose(double* %2, double* %2)
br label %59
59: ; preds = %43, %40
%60 = phi i32 [ -1, %40 ], [ 0, %43 ]
ret i32 %60
}