#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 acos(double);
double sqrt(double);
double angledist(double *c1, double *c2, int d) {
  int k;
  double n1 = 0.0;
  double n2 = 0.0;
  double ps = 0.0;
  double x;
  for (k = 0; k < d; k++) {
    n1 += c1[k] * c1[k];
    n2 += c2[k] * c2[k];
    ps += c1[k] * c2[k];
  }
  x = ps / sqrt(n1) / sqrt(n2);
  if (x > 1)
    x = 1;
  if (x < -1)
    x = -1;
  return acos(x);
}


x86 assembly (clang, -O0):
<angledist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f0 <angledist+0xd0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <angledist+0x32>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdc3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1254 <angledist+0x134>
movsd  0xdb1(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdac(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1274 <angledist+0x154>
movsd  0xd99(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <acos@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<angledist>:
sub    $0x28,%rsp
xorpd  %xmm0,%xmm0
test   %edx,%edx
jle    114a <angledist+0x2a>
mov    %edx,%eax
cmp    $0x1,%edx
jne    1157 <angledist+0x37>
xorpd  %xmm1,%xmm1
xorpd  %xmm6,%xmm6
xor    %ecx,%ecx
test   $0x1,%al
jne    11cb <angledist+0xab>
jmp    11ed <angledist+0xcd>
xorpd  %xmm7,%xmm7
xorpd  %xmm6,%xmm6
jmp    11ed <angledist+0xcd>
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm1,%xmm1
xorpd  %xmm6,%xmm6
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movsd  (%rsi,%rcx,8),%xmm3
movsd  0x8(%rsi,%rcx,8),%xmm4
movsd  (%rdi,%rcx,8),%xmm5
movapd %xmm5,%xmm2
mulsd  %xmm3,%xmm5
addsd  %xmm6,%xmm5
movsd  0x8(%rdi,%rcx,8),%xmm6
unpcklpd %xmm3,%xmm2
mulpd  %xmm2,%xmm2
addpd  %xmm1,%xmm2
movapd %xmm6,%xmm7
unpcklpd %xmm4,%xmm7
mulpd  %xmm7,%xmm7
movapd %xmm7,%xmm1
addpd  %xmm2,%xmm1
mulsd  %xmm4,%xmm6
addsd  %xmm5,%xmm6
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1170 <angledist+0x50>
addpd  %xmm2,%xmm7
test   $0x1,%al
je     11ed <angledist+0xcd>
movsd  (%rdi,%rcx,8),%xmm2
movsd  (%rsi,%rcx,8),%xmm3
movapd %xmm2,%xmm7
unpcklpd %xmm3,%xmm7
mulpd  %xmm7,%xmm7
addpd  %xmm1,%xmm7
mulsd  %xmm3,%xmm2
addsd  %xmm2,%xmm6
ucomisd %xmm0,%xmm7
jb     11fc <angledist+0xdc>
xorps  %xmm0,%xmm0
sqrtsd %xmm7,%xmm0
jmp    121b <angledist+0xfb>
movapd %xmm7,%xmm0
movapd %xmm6,(%rsp)
movapd %xmm7,0x10(%rsp)
call   1040 <sqrt@plt>
movapd 0x10(%rsp),%xmm7
movapd (%rsp),%xmm6
divsd  %xmm0,%xmm6
unpckhpd %xmm7,%xmm7
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm7
jb     1236 <angledist+0x116>
xorps  %xmm0,%xmm0
sqrtsd %xmm7,%xmm0
jmp    1249 <angledist+0x129>
movapd %xmm7,%xmm0
movapd %xmm6,(%rsp)
call   1040 <sqrt@plt>
movapd (%rsp),%xmm6
divsd  %xmm0,%xmm6
movsd  0xdab(%rip),%xmm1
minsd  %xmm6,%xmm1
movsd  0xda7(%rip),%xmm0
maxsd  %xmm1,%xmm0
add    $0x28,%rsp
jmp    1030 <acos@plt>

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

LLVM IR (-O2):
define double @angledist(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %54
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %2, 1
br i1 %8, label %38, label %9
9: ; preds = %5
%10 = and i64 %6, 4294967294
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %33, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %32, %11 ]
%14 = phi <2 x double> [ zeroinitializer, %9 ], [ %31, %11 ]
%15 = phi i64 [ 0, %9 ], [ %34, %11 ]
%16 = getelementptr inbounds double, double* %0, i64 %12
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %1, i64 %12
%19 = load double, double* %18
%20 = insertelement <2 x double> poison, double %17, i64 0
%21 = insertelement <2 x double> %20, double %19, i64 1
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %21, <2 x double> %14)
%23 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %13)
%24 = or i64 %12, 1
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %1, i64 %24
%28 = load double, double* %27
%29 = insertelement <2 x double> poison, double %26, i64 0
%30 = insertelement <2 x double> %29, double %28, i64 1
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %30, <2 x double> %22)
%32 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
%33 = add nuw nsw i64 %12, 2
%34 = add i64 %15, 2
%35 = icmp eq i64 %34, %10
br i1 %35, label %36, label %11
36: ; preds = %11
%37 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %30, <2 x double> %22)
br label %38
38: ; preds = %36, %5
%39 = phi <2 x double> [ undef, %5 ], [ %37, %36 ]
%40 = phi double [ undef, %5 ], [ %32, %36 ]
%41 = phi i64 [ 0, %5 ], [ %33, %36 ]
%42 = phi double [ 0.000000e+00, %5 ], [ %32, %36 ]
%43 = phi <2 x double> [ zeroinitializer, %5 ], [ %31, %36 ]
%44 = icmp eq i64 %7, 0
br i1 %44, label %54, label %45
45: ; preds = %38
%46 = getelementptr inbounds double, double* %0, i64 %41
%47 = load double, double* %46
%48 = getelementptr inbounds double, double* %1, i64 %41
%49 = load double, double* %48
%50 = insertelement <2 x double> poison, double %47, i64 0
%51 = insertelement <2 x double> %50, double %49, i64 1
%52 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %51, <2 x double> %51, <2 x double> %43)
%53 = tail call double @llvm.fmuladd.f64(double %47, double %49, double %42)
br label %54
54: ; preds = %45, %38, %3
%55 = phi double [ 0.000000e+00, %3 ], [ %40, %38 ], [ %53, %45 ]
%56 = phi <2 x double> [ zeroinitializer, %3 ], [ %39, %38 ], [ %52, %45 ]
%57 = extractelement <2 x double> %56, i64 0
%58 = tail call double @sqrt(double %57)
%59 = fdiv double %55, %58
%60 = extractelement <2 x double> %56, i64 1
%61 = tail call double @sqrt(double %60)
%62 = fdiv double %59, %61
%63 = fcmp ogt double %62, 1.000000e+00
%64 = select i1 %63, double 1.000000e+00, double %62
%65 = fcmp olt double %64, -1.000000e+00
%66 = select i1 %65, double -1.000000e+00, double %64
%67 = tail call double @acos(double %66)
ret double %67
}