#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 asin(double);
double norm(double *);
double glschool_computeNormalAndThetaToPlusZ(double *v, double *xV) {
  double x1 = 0.0;
  double y1 = 0.0;
  double z1 = 1.0;
  double x2 = v[0];
  double y2 = v[1];
  double z2 = v[2];
  double theta = 0.0;
  double xVNorm = 0.0;
  double sinTheta = 0.0;
  double v2Norm = norm(v);
  if (v2Norm == 0.0) {
    xV[1] = 1.0;
    xV[0] = xV[2] = 0.0;
    return theta;
  }
  xV[0] = (y1 * z2 - z1 * y2);
  xV[1] = -(x1 * z2 - z1 * x2);
  xV[2] = (x1 * y2 - y1 * x2);
  xVNorm = norm(xV);
  sinTheta = xVNorm / v2Norm;
  return (asin(sinTheta) * (180.0 / 3.1415926535));
}


x86 assembly (clang, -O0):
<glschool_computeNormalAndThetaToPlusZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <norm@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11eb <glschool_computeNormalAndThetaToPlusZ+0xcb>
jp     11eb <glschool_computeNormalAndThetaToPlusZ+0xcb>
mov    -0x18(%rbp),%rax
movsd  0xe40(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ed <glschool_computeNormalAndThetaToPlusZ+0x1cd>
movsd  -0x28(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%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    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <norm@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1040 <asin@plt>
movsd  0xd24(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glschool_computeNormalAndThetaToPlusZ>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rdi),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rdi),%xmm0
movapd %xmm0,(%rsp)
call   1030 <norm@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1176 <glschool_computeNormalAndThetaToPlusZ+0x56>
jp     1176 <glschool_computeNormalAndThetaToPlusZ+0x56>
movq   $0x0,0x10(%rbx)
xorpd  %xmm1,%xmm1
movhpd 0xeb0(%rip),%xmm1
movupd %xmm1,(%rbx)
jmp    11dc <glschool_computeNormalAndThetaToPlusZ+0xbc>
movapd (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm1,(%rsp)
movapd %xmm3,%xmm1
movsd  0x10(%rsp),%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,(%rbx)
movsd  0x18(%rsp),%xmm1
subsd  %xmm1,%xmm3
xorpd  0xe58(%rip),%xmm3
mulsd  0xe60(%rip),%xmm1
movlpd %xmm3,0x8(%rbx)
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rbx)
mov    %rbx,%rdi
call   1030 <norm@plt>
divsd  (%rsp),%xmm0
call   1040 <asin@plt>
mulsd  0xe3c(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @glschool_computeNormalAndThetaToPlusZ(double* %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 1.000000e+00, double* %8
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
store double %18, double* %9
%19 = load double*, double** %4
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
store double %21, double* %10
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
store double %24, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%25 = load double*, double** %4
%26 = call double @norm(double* %25)
store double %26, double* %15
%27 = load double, double* %15
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %37
29: ; preds = %2
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 1
store double 1.000000e+00, double* %31
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 2
store double 0.000000e+00, double* %33
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 0
store double 0.000000e+00, double* %35
%36 = load double, double* %12
store double %36, double* %3
br label %74
37: ; preds = %2
%38 = load double, double* %7
%39 = load double, double* %11
%40 = load double, double* %8
%41 = load double, double* %10
%42 = fmul double %40, %41
%43 = fneg double %42
%44 = call double @llvm.fmuladd.f64(double %38, double %39, double %43)
%45 = load double*, double** %5
%46 = getelementptr inbounds double, double* %45, i64 0
store double %44, double* %46
%47 = load double, double* %6
%48 = load double, double* %11
%49 = load double, double* %8
%50 = load double, double* %9
%51 = fmul double %49, %50
%52 = fneg double %51
%53 = call double @llvm.fmuladd.f64(double %47, double %48, double %52)
%54 = fneg double %53
%55 = load double*, double** %5
%56 = getelementptr inbounds double, double* %55, i64 1
store double %54, double* %56
%57 = load double, double* %6
%58 = load double, double* %10
%59 = load double, double* %7
%60 = load double, double* %9
%61 = fmul double %59, %60
%62 = fneg double %61
%63 = call double @llvm.fmuladd.f64(double %57, double %58, double %62)
%64 = load double*, double** %5
%65 = getelementptr inbounds double, double* %64, i64 2
store double %63, double* %65
%66 = load double*, double** %5
%67 = call double @norm(double* %66)
store double %67, double* %13
%68 = load double, double* %13
%69 = load double, double* %15
%70 = fdiv double %68, %69
store double %70, double* %14
%71 = load double, double* %14
%72 = call double @asin(double %71)
%73 = fmul double %72, 0x404CA5DC1A674644
store double %73, double* %3
br label %74
74: ; preds = %37, %29
%75 = load double, double* %3
ret double %75
}

LLVM IR (-O2):
define double @glschool_computeNormalAndThetaToPlusZ(double* %0, double* %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = getelementptr inbounds double, double* %0, i64 2
%7 = load double, double* %6
%8 = tail call double @norm(double* %0)
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds double, double* %1, i64 2
store double 0.000000e+00, double* %11
%12 = bitcast double* %1 to <2 x double>*
store <2 x double> <double 0.000000e+00, double 1.000000e+00>, <2 x double>* %12
br label %27
13: ; preds = %2
%14 = fneg double %5
%15 = tail call double @llvm.fmuladd.f64(double %7, double 0.000000e+00, double %14)
store double %15, double* %1
%16 = fneg double %3
%17 = tail call double @llvm.fmuladd.f64(double %7, double 0.000000e+00, double %16)
%18 = fneg double %17
%19 = getelementptr inbounds double, double* %1, i64 1
store double %18, double* %19
%20 = fmul double %3, -0.000000e+00
%21 = tail call double @llvm.fmuladd.f64(double %5, double 0.000000e+00, double %20)
%22 = getelementptr inbounds double, double* %1, i64 2
store double %21, double* %22
%23 = tail call double @norm(double* %1)
%24 = fdiv double %23, %8
%25 = tail call double @asin(double %24)
%26 = fmul double %25, 0x404CA5DC1A674644
br label %27
27: ; preds = %13, %10
%28 = phi double [ 0.000000e+00, %10 ], [ %26, %13 ]
ret double %28
}