#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 sqrt(double);
double swi_dot_prod_unit(double *x, double *y) {
  double dop = x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
  double e1 = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
  double e2 = sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
  dop /= e1;
  dop /= e2;
  if (dop > 1)
    dop = 1;
  if (dop < -1)
    dop = -1;
  return dop;
}


x86 assembly (clang, -O0):
<swi_dot_prod_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdc8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    124f <swi_dot_prod_unit+0x13f>
movsd  0xdb6(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xdb1(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    126f <swi_dot_prod_unit+0x15f>
movsd  0xd9e(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swi_dot_prod_unit>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
movsd  0x8(%rsi),%xmm0
mulsd  %xmm2,%xmm0
movsd  (%rsi),%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm0,%xmm4
movsd  0x10(%rdi),%xmm0
movsd  0x10(%rsi),%xmm3
mulsd  %xmm0,%xmm3
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm0
jb     116b <swi_dot_prod_unit+0x5b>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    118e <swi_dot_prod_unit+0x7e>
movsd  %xmm3,0x8(%rsp)
movsd  %xmm4,(%rsp)
call   1030 <sqrt@plt>
xorpd  %xmm5,%xmm5
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm2
addsd  %xmm4,%xmm3
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm5,%xmm0
jb     11c0 <swi_dot_prod_unit+0xb0>
sqrtsd %xmm0,%xmm0
jmp    11db <swi_dot_prod_unit+0xcb>
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
divsd  %xmm2,%xmm3
divsd  %xmm0,%xmm3
movsd  0xe15(%rip),%xmm1
minsd  %xmm3,%xmm1
movsd  0xe11(%rip),%xmm0
maxsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @swi_dot_prod_unit(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = load double, double* %1
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = getelementptr inbounds double, double* %1, i64 1
%8 = load double, double* %7
%9 = fmul double %6, %8
%10 = tail call double @llvm.fmuladd.f64(double %3, double %4, double %9)
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %1, i64 2
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double %14, double %10)
%16 = fmul double %6, %6
%17 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %16)
%18 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %17)
%19 = tail call double @sqrt(double %18)
%20 = load double, double* %1
%21 = load double, double* %7
%22 = fmul double %21, %21
%23 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %22)
%24 = load double, double* %13
%25 = tail call double @llvm.fmuladd.f64(double %24, double %24, double %23)
%26 = tail call double @sqrt(double %25)
%27 = fdiv double %15, %19
%28 = fdiv double %27, %26
%29 = fcmp ogt double %28, 1.000000e+00
%30 = select i1 %29, double 1.000000e+00, double %28
%31 = fcmp olt double %30, -1.000000e+00
%32 = select i1 %31, double -1.000000e+00, double %30
ret double %32
}