; LLVM IR from bbenligiray/stag :: src/ED/LineSegment.ll (Z33ComputeMinDistanceBetweenTwoLinesP11LineSegmentS0_Pi)

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

%struct.LineSegment = type { double, double, i32, double, double, double, double, i32, i32, i32 }

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z33ComputeMinDistanceBetweenTwoLinesP11LineSegmentS0_Pi(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LineSegment, ptr %12, i32 0, i32 3
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LineSegment, ptr %15, i32 0, i32 3
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = fsub double %14, %17
  store double %18, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LineSegment, ptr %19, i32 0, i32 4
  %21 = load double, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LineSegment, ptr %22, i32 0, i32 4
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = fsub double %21, %24
  store double %25, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load double, ptr %7, align 8, !tbaa !13
  %27 = load double, ptr %7, align 8, !tbaa !13
  %28 = load double, ptr %8, align 8, !tbaa !13
  %29 = load double, ptr %8, align 8, !tbaa !13
  %30 = fmul double %28, %29
  %31 = call double @llvm.fmuladd.f64(double %26, double %27, double %30)
  %32 = call double @sqrt(double noundef %31) #4
  store double %32, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %33 = load double, ptr %9, align 8, !tbaa !13
  store double %33, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !15
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LineSegment, ptr %34, i32 0, i32 3
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LineSegment, ptr %37, i32 0, i32 5
  %39 = load double, ptr %38, align 8, !tbaa !16
  %40 = fsub double %36, %39
  store double %40, ptr %7, align 8, !tbaa !13
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LineSegment, ptr %41, i32 0, i32 4
  %43 = load double, ptr %42, align 8, !tbaa !14
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.LineSegment, ptr %44, i32 0, i32 6
  %46 = load double, ptr %45, align 8, !tbaa !17
  %47 = fsub double %43, %46
  store double %47, ptr %8, align 8, !tbaa !13
  %48 = load double, ptr %7, align 8, !tbaa !13
  %49 = load double, ptr %7, align 8, !tbaa !13
  %50 = load double, ptr %8, align 8, !tbaa !13
  %51 = load double, ptr %8, align 8, !tbaa !13
  %52 = fmul double %50, %51
  %53 = call double @llvm.fmuladd.f64(double %48, double %49, double %52)
  %54 = call double @sqrt(double noundef %53) #4
  store double %54, ptr %9, align 8, !tbaa !13
  %55 = load double, ptr %9, align 8, !tbaa !13
  %56 = load double, ptr %10, align 8, !tbaa !13
  %57 = fcmp olt double %55, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %3
  %59 = load double, ptr %9, align 8, !tbaa !13
  store double %59, ptr %10, align 8, !tbaa !13
  store i32 1, ptr %11, align 4, !tbaa !15
  br label %60

60:                                               ; preds = %58, %3
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LineSegment, ptr %61, i32 0, i32 5
  %63 = load double, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.LineSegment, ptr %64, i32 0, i32 3
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = fsub double %63, %66
  store double %67, ptr %7, align 8, !tbaa !13
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.LineSegment, ptr %68, i32 0, i32 6
  %70 = load double, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.LineSegment, ptr %71, i32 0, i32 4
  %73 = load double, ptr %72, align 8, !tbaa !14
  %74 = fsub double %70, %73
  store double %74, ptr %8, align 8, !tbaa !13
  %75 = load double, ptr %7, align 8, !tbaa !13
  %76 = load double, ptr %7, align 8, !tbaa !13
  %77 = load double, ptr %8, align 8, !tbaa !13
  %78 = load double, ptr %8, align 8, !tbaa !13
  %79 = fmul double %77, %78
  %80 = call double @llvm.fmuladd.f64(double %75, double %76, double %79)
  %81 = call double @sqrt(double noundef %80) #4
  store double %81, ptr %9, align 8, !tbaa !13
  %82 = load double, ptr %9, align 8, !tbaa !13
  %83 = load double, ptr %10, align 8, !tbaa !13
  %84 = fcmp olt double %82, %83
  br i1 %84, label %85, label %87

85:                                               ; preds = %60
  %86 = load double, ptr %9, align 8, !tbaa !13
  store double %86, ptr %10, align 8, !tbaa !13
  store i32 2, ptr %11, align 4, !tbaa !15
  br label %87

87:                                               ; preds = %85, %60
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LineSegment, ptr %88, i32 0, i32 5
  %90 = load double, ptr %89, align 8, !tbaa !16
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.LineSegment, ptr %91, i32 0, i32 5
  %93 = load double, ptr %92, align 8, !tbaa !16
  %94 = fsub double %90, %93
  store double %94, ptr %7, align 8, !tbaa !13
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.LineSegment, ptr %95, i32 0, i32 6
  %97 = load double, ptr %96, align 8, !tbaa !17
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.LineSegment, ptr %98, i32 0, i32 6
  %100 = load double, ptr %99, align 8, !tbaa !17
  %101 = fsub double %97, %100
  store double %101, ptr %8, align 8, !tbaa !13
  %102 = load double, ptr %7, align 8, !tbaa !13
  %103 = load double, ptr %7, align 8, !tbaa !13
  %104 = load double, ptr %8, align 8, !tbaa !13
  %105 = load double, ptr %8, align 8, !tbaa !13
  %106 = fmul double %104, %105
  %107 = call double @llvm.fmuladd.f64(double %102, double %103, double %106)
  %108 = call double @sqrt(double noundef %107) #4
  store double %108, ptr %9, align 8, !tbaa !13
  %109 = load double, ptr %9, align 8, !tbaa !13
  %110 = load double, ptr %10, align 8, !tbaa !13
  %111 = fcmp olt double %109, %110
  br i1 %111, label %112, label %114

112:                                              ; preds = %87
  %113 = load double, ptr %9, align 8, !tbaa !13
  store double %113, ptr %10, align 8, !tbaa !13
  store i32 3, ptr %11, align 4, !tbaa !15
  br label %114

114:                                              ; preds = %112, %87
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = icmp ne ptr %115, null
  br i1 %116, label %117, label %120

117:                                              ; preds = %114
  %118 = load i32, ptr %11, align 4, !tbaa !15
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %118, ptr %119, align 4, !tbaa !15
  br label %120

120:                                              ; preds = %117, %114
  %121 = load double, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %121
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"_ZTS11LineSegment", !11, i64 0, !11, i64 8, !12, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !12, i64 60, !12, i64 64}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 32}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !11, i64 40}
!17 = !{!10, !11, i64 48}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef double @_Z33ComputeMinDistanceBetweenTwoLinesP11LineSegmentS0_Pi(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load double, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 32
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %1, i64 40
  %13 = load double, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %1, i64 48
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = insertelement <2 x double> poison, double %5, i64 0
  %17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
  %18 = insertelement <2 x double> poison, double %13, i64 0
  %19 = insertelement <2 x double> %18, double %7, i64 1
  %20 = fsub <2 x double> %17, %19
  %21 = insertelement <2 x double> poison, double %9, i64 0
  %22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
  %23 = insertelement <2 x double> poison, double %15, i64 0
  %24 = insertelement <2 x double> %23, double %11, i64 1
  %25 = fsub <2 x double> %22, %24
  %26 = fmul <2 x double> %25, %25
  %27 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %20, <2 x double> %20, <2 x double> %26)
  %28 = tail call <2 x double> @llvm.sqrt.v2f64(<2 x double> %27)
  %29 = extractelement <2 x double> %28, i64 0
  %30 = extractelement <2 x double> %28, i64 1
  %31 = fcmp olt double %29, %30
  %.045 = select i1 %31, double %29, double %30
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  %33 = load double, ptr %32, align 8, !tbaa !12
  %34 = fsub double %33, %7
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  %36 = load double, ptr %35, align 8, !tbaa !13
  %37 = fsub double %36, %11
  %38 = fmul double %37, %37
  %39 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %38)
  %sqrt53 = tail call double @llvm.sqrt.f64(double %39)
  %40 = fcmp olt double %sqrt53, %.045
  %.146 = select i1 %40, double %sqrt53, double %.045
  %41 = fsub double %33, %13
  %42 = fsub double %36, %15
  %43 = fmul double %42, %42
  %44 = tail call double @llvm.fmuladd.f64(double %41, double %41, double %43)
  %sqrt = tail call double @llvm.sqrt.f64(double %44)
  %45 = fcmp olt double %sqrt, %.146
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %47, label %46

46:                                               ; preds = %3
  %.0 = zext i1 %31 to i32
  %.1 = select i1 %40, i32 2, i32 %.0
  %.2 = select i1 %45, i32 3, i32 %.1
  store i32 %.2, ptr %2, align 4, !tbaa !14
  br label %47

47:                                               ; preds = %46, %3
  %.247 = select i1 %45, double %sqrt, double %.146
  ret double %.247
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.sqrt.v2f64(<2 x double>) #2

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

!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, !7, i64 24}
!6 = !{!"_ZTS11LineSegment", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !7, i64 48}
!14 = !{!10, !10, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass