#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*/ debug(char *, double);
double sqrt(double);
double cosine(double *s, double *z, int len, double bsf, double epsilon) {
  double dist = 0;
  double norm1 = 0, norm2 = 0;
  while (--len) {
    dist += *s * *z;
    norm1 += *s * *s;
    norm2 += *z * *z;
    s++;
    z++;
  }
  dist = 1 - dist / (sqrt(norm1) * sqrt(norm2));
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<cosine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11ea <cosine+0xca>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1155 <cosine+0x35>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xdd6(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdc9(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosine>:
sub    $0x28,%rsp
mov    %edx,%eax
xorpd  %xmm1,%xmm1
add    $0xffffffff,%eax
je     1145 <cosine+0x25>
test   $0x1,%al
jne    1152 <cosine+0x32>
xorpd  %xmm6,%xmm6
xorpd  %xmm5,%xmm5
cmp    $0x2,%edx
jne    118e <cosine+0x6e>
jmp    1202 <cosine+0xe2>
xorpd  %xmm6,%xmm6
xorpd  %xmm5,%xmm5
jmp    1202 <cosine+0xe2>
movsd  (%rsi),%xmm0
movsd  (%rdi),%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm2,%xmm3
unpcklpd %xmm2,%xmm2
mulpd  %xmm3,%xmm2
xorpd  %xmm6,%xmm6
addpd  %xmm2,%xmm6
mulsd  %xmm0,%xmm0
xorpd  %xmm5,%xmm5
addsd  %xmm0,%xmm5
add    $0x8,%rdi
add    $0x8,%rsi
lea    -0x2(%rdx),%eax
cmp    $0x2,%edx
je     1202 <cosine+0xe2>
mov    %eax,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rdi,%rcx,8),%xmm2
movsd  0x8(%rdi,%rcx,8),%xmm0
movsd  (%rsi,%rcx,8),%xmm3
movapd %xmm3,%xmm4
mulsd  %xmm3,%xmm3
addsd  %xmm5,%xmm3
movsd  0x8(%rsi,%rcx,8),%xmm5
unpcklpd %xmm2,%xmm4
unpcklpd %xmm2,%xmm2
mulpd  %xmm4,%xmm2
addpd  %xmm6,%xmm2
movapd %xmm5,%xmm4
unpcklpd %xmm0,%xmm4
unpcklpd %xmm0,%xmm0
mulpd  %xmm4,%xmm0
movapd %xmm0,%xmm6
addpd  %xmm2,%xmm6
mulsd  %xmm5,%xmm5
addsd  %xmm3,%xmm5
add    $0x2,%rcx
cmp    %ecx,%eax
jne    11a0 <cosine+0x80>
addpd  %xmm2,%xmm0
movapd %xmm0,%xmm6
movapd %xmm6,%xmm0
unpckhpd %xmm6,%xmm0
ucomisd %xmm1,%xmm0
movapd %xmm6,(%rsp)
jb     121e <cosine+0xfe>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    1233 <cosine+0x113>
movapd %xmm5,0x10(%rsp)
call   1040 <sqrt@plt>
movapd 0x10(%rsp),%xmm5
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm5
jb     1246 <cosine+0x126>
xorps  %xmm0,%xmm0
sqrtsd %xmm5,%xmm0
jmp    125b <cosine+0x13b>
movapd %xmm5,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
movapd (%rsp),%xmm1
mulsd  %xmm0,%xmm2
divsd  %xmm2,%xmm1
movsd  0xd90(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0xd88(%rip),%rdi
call   1030 <debug@plt>
movsd  (%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [7 x i8] c" %.6f\0A\00"
define double @cosine(double* %0, double* %1, i32 %2, double %3, double %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store double %3, double* %9
store double %4, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
br label %14
14: ; preds = %18, %5
%15 = load i32, i32* %8
%16 = add nsw i32 %15, -1
store i32 %16, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = load double*, double** %6
%20 = load double, double* %19
%21 = load double*, double** %7
%22 = load double, double* %21
%23 = load double, double* %11
%24 = call double @llvm.fmuladd.f64(double %20, double %22, double %23)
store double %24, double* %11
%25 = load double*, double** %6
%26 = load double, double* %25
%27 = load double*, double** %6
%28 = load double, double* %27
%29 = load double, double* %12
%30 = call double @llvm.fmuladd.f64(double %26, double %28, double %29)
store double %30, double* %12
%31 = load double*, double** %7
%32 = load double, double* %31
%33 = load double*, double** %7
%34 = load double, double* %33
%35 = load double, double* %13
%36 = call double @llvm.fmuladd.f64(double %32, double %34, double %35)
store double %36, double* %13
%37 = load double*, double** %6
%38 = getelementptr inbounds double, double* %37, i32 1
store double* %38, double** %6
%39 = load double*, double** %7
%40 = getelementptr inbounds double, double* %39, i32 1
store double* %40, double** %7
br label %14
41: ; preds = %14
%42 = load double, double* %11
%43 = load double, double* %12
%44 = call double @sqrt(double %43)
%45 = load double, double* %13
%46 = call double @sqrt(double %45)
%47 = fmul double %44, %46
%48 = fdiv double %42, %47
%49 = fsub double 1.000000e+00, %48
store double %49, double* %11
%50 = load double, double* %11
%51 = call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %50)
%52 = load double, double* %11
ret double %52
}

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