; LLVM IR from ShahjalalShohag/code-library :: Geometry/Geometry 3D.ll (Z33distance_from_triangle_to_segment2p3S_S_S_S_)

; 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.p3 = type { double, double, double }

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

; 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
declare dso_local void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3miERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3plERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3mlEd(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z33distance_from_triangle_to_segment2p3S_S_S_S_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca %struct.p3, align 8
  %19 = alloca %struct.p3, align 8
  %20 = alloca %struct.p3, align 8
  %21 = alloca %struct.p3, align 8
  %22 = alloca %struct.p3, align 8
  %23 = alloca %struct.p3, align 8
  %24 = alloca double, align 8
  %25 = alloca %struct.p3, align 8
  %26 = alloca %struct.p3, align 8
  %27 = alloca %struct.p3, align 8
  %28 = alloca %struct.p3, align 8
  %29 = alloca %struct.p3, align 8
  %30 = alloca %struct.p3, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store double 0.000000e+00, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 1.000000e+00, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 100, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store double 1.000000e+100, ptr %14, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %61, %5
  %32 = load i32, ptr %13, align 4, !tbaa !11
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %13, align 4, !tbaa !11
  %34 = icmp ne i32 %32, 0
  br i1 %34, label %35, label %62

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %36 = load double, ptr %11, align 8, !tbaa !9
  %37 = load double, ptr %12, align 8, !tbaa !9
  %38 = load double, ptr %11, align 8, !tbaa !9
  %39 = fsub double %37, %38
  %40 = fdiv double %39, 3.000000e+00
  %41 = fadd double %36, %40
  store double %41, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %42 = load double, ptr %12, align 8, !tbaa !9
  %43 = load double, ptr %12, align 8, !tbaa !9
  %44 = load double, ptr %11, align 8, !tbaa !9
  %45 = fsub double %43, %44
  %46 = fdiv double %45, 3.000000e+00
  %47 = fsub double %42, %46
  store double %47, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %18, ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %19, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %20, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %23) #3
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind writable sret(%struct.p3) align 8 %23, ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %48 = load double, ptr %15, align 8, !tbaa !9
  call void @_ZNK2p3mlEd(ptr dead_on_unwind writable sret(%struct.p3) align 8 %22, ptr noundef nonnull align 8 dereferenceable(24) %23, double noundef %48)
  call void @_ZNK2p3plERKS_(ptr dead_on_unwind writable sret(%struct.p3) align 8 %21, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %22)
  %49 = call noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef %18, ptr noundef %19, ptr noundef %20, ptr noundef %21)
  call void @llvm.lifetime.end.p0(i64 24, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %22) #3
  store double %49, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %26, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %27, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr %29) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %30) #3
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind writable sret(%struct.p3) align 8 %30, ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %50 = load double, ptr %16, align 8, !tbaa !9
  call void @_ZNK2p3mlEd(ptr dead_on_unwind writable sret(%struct.p3) align 8 %29, ptr noundef nonnull align 8 dereferenceable(24) %30, double noundef %50)
  call void @_ZNK2p3plERKS_(ptr dead_on_unwind writable sret(%struct.p3) align 8 %28, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %29)
  %51 = call noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef %25, ptr noundef %26, ptr noundef %27, ptr noundef %28)
  call void @llvm.lifetime.end.p0(i64 24, ptr %30) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %29) #3
  store double %51, ptr %24, align 8, !tbaa !9
  %52 = load double, ptr %17, align 8, !tbaa !9
  %53 = load double, ptr %24, align 8, !tbaa !9
  %54 = fcmp olt double %52, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %35
  %56 = load double, ptr %16, align 8, !tbaa !9
  store double %56, ptr %12, align 8, !tbaa !9
  %57 = load double, ptr %17, align 8, !tbaa !9
  store double %57, ptr %14, align 8, !tbaa !9
  br label %61

58:                                               ; preds = %35
  %59 = load double, ptr %24, align 8, !tbaa !9
  store double %59, ptr %14, align 8, !tbaa !9
  %60 = load double, ptr %15, align 8, !tbaa !9
  store double %60, ptr %11, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %58, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #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
  br label %31, !llvm.loop !13

62:                                               ; preds = %31
  %63 = load double, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret double %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%struct.p3 = type { double, double, double }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3miERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3plERKS_(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK2p3mlEd(ptr dead_on_unwind noalias writable sret(%struct.p3) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z33distance_from_triangle_to_segment2p3S_S_S_S_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.p3, align 8
  %7 = alloca %struct.p3, align 8
  %8 = alloca %struct.p3, align 8
  %9 = alloca %struct.p3, align 8
  %10 = alloca %struct.p3, align 8
  %11 = alloca %struct.p3, align 8
  %12 = alloca %struct.p3, align 8
  %13 = alloca %struct.p3, align 8
  %14 = alloca %struct.p3, align 8
  %15 = alloca %struct.p3, align 8
  %16 = alloca %struct.p3, align 8
  %17 = alloca %struct.p3, align 8
  br label %18

18:                                               ; preds = %5, %18
  %.024 = phi double [ 0.000000e+00, %5 ], [ %.0., %18 ]
  %.01523 = phi double [ 1.000000e+00, %5 ], [ %..015, %18 ]
  %.01722 = phi i32 [ 100, %5 ], [ %19, %18 ]
  %19 = add nsw i32 %.01722, -1
  %20 = fsub double %.01523, %.024
  %21 = fdiv double %20, 3.000000e+00
  %22 = fadd double %.024, %21
  %23 = fsub double %.01523, %21
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %11) #3
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %11, ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %3)
  call void @_ZNK2p3mlEd(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %10, ptr noundef nonnull align 8 dereferenceable(24) %11, double noundef %22)
  call void @_ZNK2p3plERKS_(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %9, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %10)
  %24 = call noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %16) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %17) #3
  call void @_ZNK2p3miERKS_(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %17, ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %3)
  call void @_ZNK2p3mlEd(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %16, ptr noundef nonnull align 8 dereferenceable(24) %17, double noundef %23)
  call void @_ZNK2p3plERKS_(ptr dead_on_unwind nonnull writable sret(%struct.p3) align 8 %15, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %16)
  %25 = call noundef double @_Z31distance_from_triangle_to_point2p3S_S_S_(ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef nonnull %14, ptr noundef nonnull %15)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %17) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %16) #3
  %26 = fcmp olt double %24, %25
  %..015 = select i1 %26, double %23, double %.01523
  %.0. = select i1 %26, double %.024, double %22
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %27, label %18, !llvm.loop !5

27:                                               ; preds = %18
  %..le = select i1 %26, double %24, double %25
  ret double %..le
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass