; 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"

@PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.Temp = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef = external hidden global double, align 8
@PointsOnLineSegmentAtAGivenDistance3D.Temp2 = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.Temp3 = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine = external hidden global double, align 8
@PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm = external hidden global double, align 8

; Function Attrs: nounwind
declare double @sqrt(double noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @VectAbs(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @MultiplicateWithScalar(ptr noundef, ptr noundef, double noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local double @ScalarProduct(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PointsOnLineSegmentAtAGivenDistance3D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, double noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store double %5, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef %14, ptr noundef %15)
  call void @UnitVect(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine)
  %16 = load ptr, ptr %12, align 8, !tbaa !5
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp, ptr noundef %16, ptr noundef %17)
  %18 = call double @ScalarProduct(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp, i32 noundef 3)
  store double %18, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !9
  %19 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !9
  call void @MultiplicateWithScalar(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %19, i32 noundef 3)
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectSum(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef %20)
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp3, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef %21)
  %22 = call double @VectAbs(ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.Temp3)
  store double %22, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !9
  %23 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !9
  %24 = load double, ptr %13, align 8, !tbaa !9
  %25 = fcmp ogt double %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  br label %59

27:                                               ; preds = %6
  %28 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !9
  %29 = load double, ptr %13, align 8, !tbaa !9
  %30 = fcmp oeq double %28, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, align 16, !tbaa !9
  %34 = load double, ptr getelementptr inbounds ([3 x double], ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, i64 0, i64 1), align 8, !tbaa !9
  %35 = load double, ptr getelementptr inbounds ([3 x double], ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, i64 0, i64 2), align 16, !tbaa !9
  call void @FillVect(ptr noundef %32, double noundef %33, double noundef %34, double noundef %35)
  store i32 1, ptr %7, align 4
  br label %59

36:                                               ; preds = %27
  %37 = load double, ptr %13, align 8, !tbaa !9
  %38 = load double, ptr %13, align 8, !tbaa !9
  %39 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !9
  %40 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !9
  %41 = fmul double %39, %40
  %42 = fneg double %41
  %43 = call double @llvm.fmuladd.f64(double %37, double %38, double %42)
  %44 = call double @sqrt(double noundef %43) #3
  store double %44, ptr @PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm, align 8, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !9
  %47 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm, align 8, !tbaa !9
  %48 = fadd double %46, %47
  call void @MultiplicateWithScalar(ptr noundef %45, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %48, i32 noundef 3)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !9
  %51 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm, align 8, !tbaa !9
  %52 = fsub double %50, %51
  call void @MultiplicateWithScalar(ptr noundef %49, ptr noundef @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %52, i32 noundef 3)
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectSum(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectSum(ptr noundef %56, ptr noundef %57, ptr noundef %58)
  store i32 2, ptr %7, align 4
  br label %59

59:                                               ; preds = %36, %31, %26
  %60 = load i32, ptr %7, align 4
  ret i32 %60
}

attributes #0 = { nounwind "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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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" }
attributes #3 = { nounwind }

!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"

@PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.Temp = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef = external hidden local_unnamed_addr global double, align 8
@PointsOnLineSegmentAtAGivenDistance3D.Temp2 = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.Temp3 = external hidden global [3 x double], align 16
@PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine = external hidden local_unnamed_addr global double, align 8
@PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm = external hidden local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @VectAbs(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @MultiplicateWithScalar(ptr noundef, ptr noundef, double noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local double @ScalarProduct(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @PointsOnLineSegmentAtAGivenDistance3D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, double noundef %5) local_unnamed_addr #2 {
  tail call void @VectDifference(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef %3, ptr noundef %2)
  tail call void @UnitVect(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine)
  tail call void @VectDifference(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp, ptr noundef %4, ptr noundef %2)
  %7 = tail call double @ScalarProduct(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp, i32 noundef 3)
  store double %7, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !5
  tail call void @MultiplicateWithScalar(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %7, i32 noundef 3)
  tail call void @VectSum(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef %2)
  tail call void @VectDifference(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp3, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp2, ptr noundef %4)
  %8 = tail call double @VectAbs(ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.Temp3)
  store double %8, ptr @PointsOnLineSegmentAtAGivenDistance3D.DistanceFromLine, align 8, !tbaa !5
  %9 = fcmp ogt double %8, %5
  br i1 %9, label %26, label %10

10:                                               ; preds = %6
  %11 = fcmp oeq double %8, %5
  br i1 %11, label %12, label %16

12:                                               ; preds = %10
  %13 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, align 16, !tbaa !5
  %14 = load double, ptr getelementptr inbounds (i8, ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, i64 8), align 8, !tbaa !5
  %15 = load double, ptr getelementptr inbounds (i8, ptr @PointsOnLineSegmentAtAGivenDistance3D.Temp2, i64 16), align 16, !tbaa !5
  tail call void @FillVect(ptr noundef %0, double noundef %13, double noundef %14, double noundef %15)
  br label %26

16:                                               ; preds = %10
  %17 = fneg double %8
  %18 = fmul double %8, %17
  %19 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %18)
  %20 = tail call double @sqrt(double noundef %19) #3
  store double %20, ptr @PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm, align 8, !tbaa !5
  %21 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !5
  %22 = fadd double %20, %21
  tail call void @MultiplicateWithScalar(ptr noundef %0, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %22, i32 noundef 3)
  %23 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.ProjDistOfEndPointFromRef, align 8, !tbaa !5
  %24 = load double, ptr @PointsOnLineSegmentAtAGivenDistance3D.AdditiveTerm, align 8, !tbaa !5
  %25 = fsub double %23, %24
  tail call void @MultiplicateWithScalar(ptr noundef %1, ptr noundef nonnull @PointsOnLineSegmentAtAGivenDistance3D.DirectionOfLine, double noundef %25, i32 noundef 3)
  tail call void @VectSum(ptr noundef %0, ptr noundef %0, ptr noundef %2)
  tail call void @VectSum(ptr noundef %1, ptr noundef %1, ptr noundef %2)
  br label %26

26:                                               ; preds = %6, %16, %12
  %.0 = phi i32 [ 1, %12 ], [ 2, %16 ], [ 0, %6 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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" }
attributes #3 = { nounwind }

!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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass