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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ClosestPointOfLines3D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %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 [3 x double], align 16
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca i8, align 1
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #3
  store i8 0, ptr %19, align 1, !tbaa !9
  %20 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  call void @VectDifference(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call double @ScalarProduct(ptr noundef %23, ptr noundef %24, i32 noundef 3)
  store double %25, ptr %14, align 8, !tbaa !11
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = call double @ScalarProduct(ptr noundef %26, ptr noundef %27, i32 noundef 3)
  store double %28, ptr %15, align 8, !tbaa !11
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = call double @ScalarProduct(ptr noundef %29, ptr noundef %30, i32 noundef 3)
  store double %31, ptr %16, align 8, !tbaa !11
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %34 = call double @ScalarProduct(ptr noundef %32, ptr noundef %33, i32 noundef 3)
  store double %34, ptr %17, align 8, !tbaa !11
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %37 = call double @ScalarProduct(ptr noundef %35, ptr noundef %36, i32 noundef 3)
  store double %37, ptr %18, align 8, !tbaa !11
  %38 = load double, ptr %14, align 8, !tbaa !11
  %39 = load double, ptr %16, align 8, !tbaa !11
  %40 = load double, ptr %15, align 8, !tbaa !11
  %41 = load double, ptr %15, align 8, !tbaa !11
  %42 = fmul double %40, %41
  %43 = fneg double %42
  %44 = call double @llvm.fmuladd.f64(double %38, double %39, double %43)
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  store double %44, ptr %45, align 8, !tbaa !11
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = fcmp oeq double %47, 0.000000e+00
  br i1 %48, label %49, label %54

49:                                               ; preds = %6
  %50 = load double, ptr %17, align 8, !tbaa !11
  %51 = load double, ptr %15, align 8, !tbaa !11
  %52 = fdiv double %50, %51
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  store double %52, ptr %53, align 8, !tbaa !11
  store i8 1, ptr %19, align 1, !tbaa !9
  br label %77

54:                                               ; preds = %6
  %55 = load double, ptr %14, align 8, !tbaa !11
  %56 = load double, ptr %18, align 8, !tbaa !11
  %57 = load double, ptr %15, align 8, !tbaa !11
  %58 = load double, ptr %17, align 8, !tbaa !11
  %59 = fmul double %57, %58
  %60 = fneg double %59
  %61 = call double @llvm.fmuladd.f64(double %55, double %56, double %60)
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = fdiv double %61, %63
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  store double %64, ptr %65, align 8, !tbaa !11
  %66 = load double, ptr %15, align 8, !tbaa !11
  %67 = load double, ptr %18, align 8, !tbaa !11
  %68 = load double, ptr %16, align 8, !tbaa !11
  %69 = load double, ptr %17, align 8, !tbaa !11
  %70 = fmul double %68, %69
  %71 = fneg double %70
  %72 = call double @llvm.fmuladd.f64(double %66, double %67, double %71)
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = fdiv double %72, %74
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  store double %75, ptr %76, align 8, !tbaa !11
  br label %77

77:                                               ; preds = %54, %49
  %78 = load i8, ptr %19, align 1, !tbaa !9, !range !13, !noundef !14
  %79 = trunc i8 %78 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  ret i1 %79
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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 double @ScalarProduct(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @ClosestPointOfLines3D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr nocapture noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #2 {
  %7 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @VectDifference(ptr noundef nonnull %7, ptr noundef %0, ptr noundef %2)
  %8 = call double @ScalarProduct(ptr noundef %1, ptr noundef %1, i32 noundef 3)
  %9 = call double @ScalarProduct(ptr noundef %1, ptr noundef %3, i32 noundef 3)
  %10 = call double @ScalarProduct(ptr noundef %3, ptr noundef %3, i32 noundef 3)
  %11 = call double @ScalarProduct(ptr noundef %1, ptr noundef nonnull %7, i32 noundef 3)
  %12 = call double @ScalarProduct(ptr noundef %3, ptr noundef nonnull %7, i32 noundef 3)
  %13 = fneg double %9
  %14 = fmul double %9, %13
  %15 = call double @llvm.fmuladd.f64(double %8, double %10, double %14)
  store double %15, ptr %4, align 8, !tbaa !5
  %16 = fcmp oeq double %15, 0.000000e+00
  br i1 %16, label %17, label %19

17:                                               ; preds = %6
  %18 = fdiv double %11, %9
  store double %18, ptr %5, align 8, !tbaa !5
  br label %28

19:                                               ; preds = %6
  %20 = fmul double %11, %13
  %21 = call double @llvm.fmuladd.f64(double %8, double %12, double %20)
  %22 = fdiv double %21, %15
  store double %22, ptr %5, align 8, !tbaa !5
  %23 = fneg double %10
  %24 = fmul double %11, %23
  %25 = call double @llvm.fmuladd.f64(double %9, double %12, double %24)
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = fdiv double %25, %26
  store double %27, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %19, %17
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  ret i1 %16
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass