double DotProduct(x1, Y1, x2, y2)
double x1, Y1, x2, y2;
{
  double temp;
  if ((x1 == 0.0 && Y1 == 0.0)) {
    return 1.0;
  }
  temp = sqrt(x1 * x1 + Y1 * Y1);
  x1 = x1 / temp;
  Y1 = Y1 / temp;
  temp = x1 * x2 + Y1 * y2;
  if (temp > 1.0)
    temp = fmod(temp, 1.0);
  if (temp < -1.0)
    temp = -fmod(-temp, 1.0);
  return (temp);
}


x86 assembly (clang, -O0):
<DotProduct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117e <DotProduct+0x5e>
jp     117e <DotProduct+0x5e>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117e <DotProduct+0x5e>
jp     117e <DotProduct+0x5e>
movsd  0xe8c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <DotProduct+0x153>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe10(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1211 <DotProduct+0xf1>
movsd  -0x30(%rbp),%xmm0
movsd  0xdf9(%rip),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xdef(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1269 <DotProduct+0x149>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdb8(%rip),%xmm1
call   1030 <fmod@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DotProduct>:
sub    $0x38,%rsp
movapd %xmm0,%xmm6
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm0
jne    1149 <DotProduct+0x29>
jp     1149 <DotProduct+0x29>
ucomisd %xmm4,%xmm1
jne    1149 <DotProduct+0x29>
jp     1149 <DotProduct+0x29>
movsd  0xebc(%rip),%xmm6
jmp    1204 <DotProduct+0xe4>
movapd %xmm1,%xmm5
mulsd  %xmm1,%xmm5
movapd %xmm6,%xmm0
mulsd  %xmm6,%xmm0
addsd  %xmm5,%xmm0
ucomisd %xmm4,%xmm0
jb     1169 <DotProduct+0x49>
sqrtsd %xmm0,%xmm0
jmp    119e <DotProduct+0x7e>
movapd %xmm6,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
movapd 0x20(%rsp),%xmm6
divsd  %xmm0,%xmm6
divsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm6
addsd  %xmm1,%xmm6
ucomisd 0xe46(%rip),%xmm6
jbe    11d1 <DotProduct+0xb1>
movsd  0xe3c(%rip),%xmm1
movapd %xmm6,%xmm0
call   1030 <fmod@plt>
movapd %xmm0,%xmm6
movsd  0xe2f(%rip),%xmm0
ucomisd %xmm6,%xmm0
jbe    1204 <DotProduct+0xe4>
xorpd  0xe29(%rip),%xmm6
movsd  0xe11(%rip),%xmm1
movapd %xmm6,%xmm0
call   1030 <fmod@plt>
movapd %xmm0,%xmm6
xorpd  0xe0c(%rip),%xmm6
movapd %xmm6,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @DotProduct(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%11 = load double, double* %6
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load double, double* %7
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %13
store double 1.000000e+00, double* %5
br label %52
17: ; preds = %13, %4
%18 = load double, double* %6
%19 = load double, double* %6
%20 = load double, double* %7
%21 = load double, double* %7
%22 = fmul double %20, %21
%23 = call double @llvm.fmuladd.f64(double %18, double %19, double %22)
%24 = call double @sqrt(double %23)
store double %24, double* %10
%25 = load double, double* %6
%26 = load double, double* %10
%27 = fdiv double %25, %26
store double %27, double* %6
%28 = load double, double* %7
%29 = load double, double* %10
%30 = fdiv double %28, %29
store double %30, double* %7
%31 = load double, double* %6
%32 = load double, double* %8
%33 = load double, double* %7
%34 = load double, double* %9
%35 = fmul double %33, %34
%36 = call double @llvm.fmuladd.f64(double %31, double %32, double %35)
store double %36, double* %10
%37 = load double, double* %10
%38 = fcmp ogt double %37, 1.000000e+00
br i1 %38, label %39, label %42
39: ; preds = %17
%40 = load double, double* %10
%41 = call double @fmod(double %40, double 1.000000e+00)
store double %41, double* %10
br label %42
42: ; preds = %39, %17
%43 = load double, double* %10
%44 = fcmp olt double %43, -1.000000e+00
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load double, double* %10
%47 = fneg double %46
%48 = call double @fmod(double %47, double 1.000000e+00)
%49 = fneg double %48
store double %49, double* %10
br label %50
50: ; preds = %45, %42
%51 = load double, double* %10
store double %51, double* %5
br label %52
52: ; preds = %50, %16
%53 = load double, double* %5
ret double %53
}

LLVM IR (-O2):
define double @DotProduct(double %0, double %1, double %2, double %3) {
%5 = fcmp oeq double %0, 0.000000e+00
%6 = fcmp oeq double %1, 0.000000e+00
%7 = and i1 %5, %6
br i1 %7, label %26, label %8
8: ; preds = %4
%9 = fmul double %1, %1
%10 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %9)
%11 = tail call double @sqrt(double %10)
%12 = fdiv double %0, %11
%13 = fdiv double %1, %11
%14 = fmul double %13, %3
%15 = tail call double @llvm.fmuladd.f64(double %12, double %2, double %14)
%16 = fcmp ogt double %15, 1.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call double @fmod(double %15, double 1.000000e+00)
br label %19
19: ; preds = %17, %8
%20 = phi double [ %18, %17 ], [ %15, %8 ]
%21 = fcmp olt double %20, -1.000000e+00
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = fneg double %20
%24 = tail call double @fmod(double %23, double 1.000000e+00)
%25 = fneg double %24
br label %26
26: ; preds = %19, %22, %4
%27 = phi double [ 1.000000e+00, %4 ], [ %25, %22 ], [ %20, %19 ]
ret double %27
}