#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*/ cross(double *, double *, double *);
scalar_t__ dot(double *, double *);
double magang(double *, double *);
int /*<<< orphan*/ vec_orth(double *, double *);
double vec_ang(double *va, double *vb, double *vref) {
  long i;
  double ang_deg, vc[4], va_cp[4], vb_cp[4];
  for (i = 1; i <= 3; i++) {
    va_cp[i] = va[i];
    vb_cp[i] = vb[i];
  }
  vec_orth(va_cp, vref);
  vec_orth(vb_cp, vref);
  ang_deg = magang(va_cp, vb_cp);
  cross(va_cp, vb_cp, vc);
  if (dot(vc, vref) < 0)
    ang_deg = -ang_deg;
  return ang_deg;
}


x86 assembly (clang, -O0):
<vec_ang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jg     11ac <vec_ang+0x6c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,-0x70(%rbp,%rax,8)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,-0x90(%rbp,%rax,8)
ff ff
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <vec_ang+0x1f>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <vec_orth@plt>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <vec_orth@plt>
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <magang@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <cross@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <dot@plt>
cmp    $0x0,%rax
jge    122a <vec_ang+0xea>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_ang>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%rbx
movups 0x8(%rdi),%xmm0
movups %xmm0,0x38(%rsp)
mov    0x18(%rdi),%rax
mov    %rax,0x48(%rsp)
movups 0x8(%rsi),%xmm0
movups %xmm0,0x18(%rsp)
mov    0x18(%rsi),%rax
mov    %rax,0x28(%rsp)
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    %rdx,%rsi
call   1060 <vec_orth@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <vec_orth@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <magang@plt>
movaps %xmm0,(%rsp)
lea    0x50(%rsp),%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <cross@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <dot@plt>
test   %rax,%rax
js     11ca <vec_ang+0x8a>
movaps (%rsp),%xmm0
jmp    11d5 <vec_ang+0x95>
movaps (%rsp),%xmm0
xorps  0xe2b(%rip),%xmm0
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @vec_ang(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i64
%8 = alloca double
%9 = alloca [4 x double]
%10 = alloca [4 x double]
%11 = alloca [4 x double]
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
store i64 1, i64* %7
br label %12
12: ; preds = %28, %3
%13 = load i64, i64* %7
%14 = icmp sle i64 %13, 3
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load double*, double** %4
%17 = load i64, i64* %7
%18 = getelementptr inbounds double, double* %16, i64 %17
%19 = load double, double* %18
%20 = load i64, i64* %7
%21 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %20
store double %19, double* %21
%22 = load double*, double** %5
%23 = load i64, i64* %7
%24 = getelementptr inbounds double, double* %22, i64 %23
%25 = load double, double* %24
%26 = load i64, i64* %7
%27 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 %26
store double %25, double* %27
br label %28
28: ; preds = %15
%29 = load i64, i64* %7
%30 = add nsw i64 %29, 1
store i64 %30, i64* %7
br label %12
31: ; preds = %12
%32 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%33 = load double*, double** %6
%34 = call i32 @vec_orth(double* %32, double* %33)
%35 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%36 = load double*, double** %6
%37 = call i32 @vec_orth(double* %35, double* %36)
%38 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%39 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%40 = call double @magang(double* %38, double* %39)
store double %40, double* %8
%41 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%42 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%43 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%44 = call i32 @cross(double* %41, double* %42, double* %43)
%45 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%46 = load double*, double** %6
%47 = call i64 @dot(double* %45, double* %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %31
%50 = load double, double* %8
%51 = fneg double %50
store double %51, double* %8
br label %52
52: ; preds = %49, %31
%53 = load double, double* %8
ret double %53
}

LLVM IR (-O2):
define double @vec_ang(double* nocapture %0, double* nocapture %1, double* %2) {
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = bitcast [4 x double]* %4 to i8*
%8 = bitcast [4 x double]* %5 to i8*
%9 = bitcast [4 x double]* %6 to i8*
%10 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%11 = bitcast double* %10 to i8*
%12 = getelementptr double, double* %0, i64 1
%13 = bitcast double* %12 to i8*
%14 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 1
%15 = bitcast double* %14 to i8*
%16 = getelementptr double, double* %1, i64 1
%17 = bitcast double* %16 to i8*
%18 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%19 = call i32 @vec_orth(double* %18, double* %2)
%20 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%21 = call i32 @vec_orth(double* %20, double* %2)
%22 = call double @magang(double* %18, double* %20)
%23 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%24 = call i32 @cross(double* %18, double* %20, double* %23)
%25 = call i64 @dot(double* %23, double* %2)
%26 = icmp slt i64 %25, 0
%27 = fneg double %22
%28 = select i1 %26, double %27, double %22
ret double %28
}