#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ matMultMM(double *, double *, double *);
int /*<<< orphan*/ matMultMV(double *, double *, double *);
int /*<<< orphan*/ matNormalize(double *, double *);
scalar_t__ matTransformAtoB(double *, double *, double *);
int /*<<< orphan*/ stderr;
int matTransformXYtoNM(double on[3], double om[3], double mat[16]) {
  double x[] = {1.0, 0.0, 0.0, 1.0}, y[] = {0.0, 0.0, 1.0, 1.0};
  double n[4], m[4], y2[4], m2[4], c[4];
  double dot, axis[4], angle;
  double mat1[16], mat2[16];
  n[0] = on[0];
  n[1] = on[1];
  n[2] = on[2];
  n[3] = 1.0;
  m[0] = om[0];
  m[1] = om[1];
  m[2] = om[2];
  m[3] = 1.0;
  matNormalize(n, n);
  matNormalize(m, m);
  if (matTransformAtoB(x, n, mat1) < 0) {
    fprintf(stderr, "error in matTransform\n");
    return -1;
  }
  matMultMV(mat1, y, y2);
  matMultMV(mat1, m, m2);
  matMultMV(mat2, n, c);
  matMultMM(mat2, mat1, mat);
  return 0;
}


x86 assembly (clang, -O0):
<matTransformXYtoNM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe9c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xe10(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xdd1(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
lea    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <matNormalize@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <matNormalize@plt>
lea    -0x40(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x1c0(%rbp),%rdx
call   1060 <matTransformAtoB@plt>
cmp    $0x0,%rax
jge    1296 <matTransformXYtoNM+0x146>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fc <matTransformXYtoNM+0x1ac>
lea    -0x1c0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
call   1070 <matMultMV@plt>
lea    -0x1c0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
call   1070 <matMultMV@plt>
lea    -0x240(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x100(%rbp),%rdx
call   1070 <matMultMV@plt>
lea    -0x240(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <matMultMM@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matTransformXYtoNM>:
push   %r15
push   %r14
push   %rbx
sub    $0x1e0,%rsp
mov    %rdx,%r14
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups (%rdi),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x30(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x38(%rsp)
movups (%rsi),%xmm0
movaps %xmm0,(%rsp)
movsd  0x10(%rsi),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <matNormalize@plt>
mov    %rsp,%rdi
mov    %rdi,%rsi
call   1030 <matNormalize@plt>
lea    0x60(%rsp),%rdi
lea    0xe0(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <matTransformAtoB@plt>
test   %rax,%rax
js     125c <matTransformXYtoNM+0x10c>
lea    0xe0(%rsp),%r15
lea    0x40(%rsp),%rsi
lea    0xc0(%rsp),%rdx
mov    %r15,%rdi
call   1070 <matMultMV@plt>
mov    %rsp,%rsi
lea    0xa0(%rsp),%rdx
mov    %r15,%rdi
call   1070 <matMultMV@plt>
lea    0x160(%rsp),%rbx
lea    0x20(%rsp),%rsi
lea    0x80(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <matMultMV@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <matMultMM@plt>
xor    %eax,%eax
jmp    1276 <matTransformXYtoNM+0x126>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1e0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.matTransformXYtoNM.x = [4 x double] [double 1.000000e+00, double 0.000000e+00, double 0.000000e+00, double 1.000000e+00]
@__const.matTransformXYtoNM.y = [4 x double] [double 0.000000e+00, double 0.000000e+00, double 1.000000e+00, double 1.000000e+00]
@stderr = global i32 0
@.str = [23 x i8] c"error in matTransform\0A\00"
define i32 @matTransformXYtoNM(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 [4 x double]
%11 = alloca [4 x double]
%12 = alloca [4 x double]
%13 = alloca [4 x double]
%14 = alloca [4 x double]
%15 = alloca double
%16 = alloca [4 x double]
%17 = alloca double
%18 = alloca [16 x double]
%19 = alloca [16 x double]
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
%20 = bitcast [4 x double]* %8 to i8*
%21 = bitcast [4 x double]* %9 to i8*
%22 = load double*, double** %5
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = load double, double* %23
%25 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
store double %24, double* %25
%26 = load double*, double** %5
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
%29 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 1
store double %28, double* %29
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 2
%32 = load double, double* %31
%33 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 2
store double %32, double* %33
%34 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 3
store double 1.000000e+00, double* %34
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i64 0
%37 = load double, double* %36
%38 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
store double %37, double* %38
%39 = load double*, double** %6
%40 = getelementptr inbounds double, double* %39, i64 1
%41 = load double, double* %40
%42 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 1
store double %41, double* %42
%43 = load double*, double** %6
%44 = getelementptr inbounds double, double* %43, i64 2
%45 = load double, double* %44
%46 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 2
store double %45, double* %46
%47 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 3
store double 1.000000e+00, double* %47
%48 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%49 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%50 = call i32 @matNormalize(double* %48, double* %49)
%51 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%52 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%53 = call i32 @matNormalize(double* %51, double* %52)
%54 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%55 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%56 = getelementptr inbounds [16 x double], [16 x double]* %18, i64 0, i64 0
%57 = call i64 @matTransformAtoB(double* %54, double* %55, double* %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %3
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %79
62: ; preds = %3
%63 = getelementptr inbounds [16 x double], [16 x double]* %18, i64 0, i64 0
%64 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%65 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 0
%66 = call i32 @matMultMV(double* %63, double* %64, double* %65)
%67 = getelementptr inbounds [16 x double], [16 x double]* %18, i64 0, i64 0
%68 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%69 = getelementptr inbounds [4 x double], [4 x double]* %13, i64 0, i64 0
%70 = call i32 @matMultMV(double* %67, double* %68, double* %69)
%71 = getelementptr inbounds [16 x double], [16 x double]* %19, i64 0, i64 0
%72 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%73 = getelementptr inbounds [4 x double], [4 x double]* %14, i64 0, i64 0
%74 = call i32 @matMultMV(double* %71, double* %72, double* %73)
%75 = getelementptr inbounds [16 x double], [16 x double]* %19, i64 0, i64 0
%76 = getelementptr inbounds [16 x double], [16 x double]* %18, i64 0, i64 0
%77 = load double*, double** %7
%78 = call i32 @matMultMM(double* %75, double* %76, double* %77)
store i32 0, i32* %4
br label %79
79: ; preds = %62, %59
%80 = load i32, i32* %4
ret i32 %80
}

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