; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@ProjectVectOntoLine.Temp = external hidden global [3 x double], align 16
@ProjectVectOntoLine.u = external hidden global [3 x double], align 16

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @FillVect(ptr noundef, double noundef, double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @UnitVect(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ProjectVectOntoLine(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds double, ptr %7, i64 0
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %10, i64 1
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %13, i64 2
  %15 = load double, ptr %14, align 8, !tbaa !9
  call void @FillVect(ptr noundef @ProjectVectOntoLine.Temp, double noundef %9, double noundef %12, double noundef %15)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  call void @UnitVect(ptr noundef @ProjectVectOntoLine.u, ptr noundef %16)
  %17 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %18 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %19 = fmul double %17, %18
  %20 = load double, ptr @ProjectVectOntoLine.Temp, align 16, !tbaa !9
  %21 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %22 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %23 = fmul double %21, %22
  %24 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 1), align 8, !tbaa !9
  %25 = fmul double %23, %24
  %26 = call double @llvm.fmuladd.f64(double %19, double %20, double %25)
  %27 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %28 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %29 = fmul double %27, %28
  %30 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 2), align 16, !tbaa !9
  %31 = call double @llvm.fmuladd.f64(double %29, double %30, double %26)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 0
  store double %31, ptr %33, align 8, !tbaa !9
  %34 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %35 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %36 = fmul double %34, %35
  %37 = load double, ptr @ProjectVectOntoLine.Temp, align 16, !tbaa !9
  %38 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %39 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %40 = fmul double %38, %39
  %41 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 1), align 8, !tbaa !9
  %42 = fmul double %40, %41
  %43 = call double @llvm.fmuladd.f64(double %36, double %37, double %42)
  %44 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %45 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %46 = fmul double %44, %45
  %47 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 2), align 16, !tbaa !9
  %48 = call double @llvm.fmuladd.f64(double %46, double %47, double %43)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds double, ptr %49, i64 1
  store double %48, ptr %50, align 8, !tbaa !9
  %51 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %52 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !9
  %53 = fmul double %51, %52
  %54 = load double, ptr @ProjectVectOntoLine.Temp, align 16, !tbaa !9
  %55 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %56 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 1), align 8, !tbaa !9
  %57 = fmul double %55, %56
  %58 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 1), align 8, !tbaa !9
  %59 = fmul double %57, %58
  %60 = call double @llvm.fmuladd.f64(double %53, double %54, double %59)
  %61 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %62 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.u, i64 0, i64 2), align 16, !tbaa !9
  %63 = fmul double %61, %62
  %64 = load double, ptr getelementptr inbounds ([3 x double], ptr @ProjectVectOntoLine.Temp, i64 0, i64 2), align 16, !tbaa !9
  %65 = call double @llvm.fmuladd.f64(double %63, double %64, double %60)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds double, ptr %66, i64 2
  store double %65, ptr %67, align 8, !tbaa !9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@ProjectVectOntoLine.Temp = external hidden global [3 x double], align 16
@ProjectVectOntoLine.u = external hidden global [3 x double], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @FillVect(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @UnitVect(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ProjectVectOntoLine(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = load double, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load double, ptr %7, align 8, !tbaa !5
  tail call void @FillVect(ptr noundef nonnull @ProjectVectOntoLine.Temp, double noundef %4, double noundef %6, double noundef %8)
  tail call void @UnitVect(ptr noundef nonnull @ProjectVectOntoLine.u, ptr noundef %2)
  %9 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !5
  %10 = fmul double %9, %9
  %11 = load double, ptr @ProjectVectOntoLine.Temp, align 16, !tbaa !5
  %12 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 8), align 8, !tbaa !5
  %13 = fmul double %9, %12
  %14 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 8), align 8, !tbaa !5
  %15 = fmul double %13, %14
  %16 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %15)
  %17 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 16), align 16, !tbaa !5
  %18 = fmul double %9, %17
  %19 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 16), align 16, !tbaa !5
  %20 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %16)
  store double %20, ptr %0, align 8, !tbaa !5
  %21 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 8), align 8, !tbaa !5
  %22 = load double, ptr @ProjectVectOntoLine.u, align 16, !tbaa !5
  %23 = fmul double %21, %22
  %24 = load double, ptr @ProjectVectOntoLine.Temp, align 16, !tbaa !5
  %25 = fmul double %21, %21
  %26 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 8), align 8, !tbaa !5
  %27 = fmul double %25, %26
  %28 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %27)
  %29 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 16), align 16, !tbaa !5
  %30 = fmul double %21, %29
  %31 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 16), align 16, !tbaa !5
  %32 = tail call double @llvm.fmuladd.f64(double %30, double %31, double %28)
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store double %32, ptr %33, align 8, !tbaa !5
  %34 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 16), align 16, !tbaa !5
  %35 = fmul double %22, %34
  %36 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.u, i64 8), align 8, !tbaa !5
  %37 = fmul double %34, %36
  %38 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 8), align 8, !tbaa !5
  %39 = fmul double %37, %38
  %40 = tail call double @llvm.fmuladd.f64(double %35, double %24, double %39)
  %41 = fmul double %34, %34
  %42 = load double, ptr getelementptr inbounds (i8, ptr @ProjectVectOntoLine.Temp, i64 16), align 16, !tbaa !5
  %43 = tail call double @llvm.fmuladd.f64(double %41, double %42, double %40)
  %44 = getelementptr inbounds i8, ptr %0, i64 16
  store double %43, ptr %44, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass