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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; 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 void @_Z19ComputeClosestPointddddiPdS_(double noundef %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  store double %0, ptr %8, align 8, !tbaa !5
  store double %1, ptr %9, align 8, !tbaa !5
  store double %2, ptr %10, align 8, !tbaa !5
  store double %3, ptr %11, align 8, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %49

23:                                               ; preds = %7
  %24 = load double, ptr %11, align 8, !tbaa !5
  %25 = fcmp oeq double %24, 0.000000e+00
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load double, ptr %8, align 8, !tbaa !5
  store double %27, ptr %15, align 8, !tbaa !5
  %28 = load double, ptr %10, align 8, !tbaa !5
  store double %28, ptr %16, align 8, !tbaa !5
  br label %48

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %30 = load double, ptr %11, align 8, !tbaa !5
  %31 = fdiv double -1.000000e+00, %30
  store double %31, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %32 = load double, ptr %9, align 8, !tbaa !5
  %33 = load double, ptr %17, align 8, !tbaa !5
  %34 = load double, ptr %8, align 8, !tbaa !5
  %35 = fneg double %33
  %36 = call double @llvm.fmuladd.f64(double %35, double %34, double %32)
  store double %36, ptr %18, align 8, !tbaa !5
  %37 = load double, ptr %10, align 8, !tbaa !5
  %38 = load double, ptr %18, align 8, !tbaa !5
  %39 = fsub double %37, %38
  %40 = load double, ptr %17, align 8, !tbaa !5
  %41 = load double, ptr %11, align 8, !tbaa !5
  %42 = fsub double %40, %41
  %43 = fdiv double %39, %42
  store double %43, ptr %15, align 8, !tbaa !5
  %44 = load double, ptr %10, align 8, !tbaa !5
  %45 = load double, ptr %11, align 8, !tbaa !5
  %46 = load double, ptr %15, align 8, !tbaa !5
  %47 = call double @llvm.fmuladd.f64(double %45, double %46, double %44)
  store double %47, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %48

48:                                               ; preds = %29, %26
  br label %75

49:                                               ; preds = %7
  %50 = load double, ptr %11, align 8, !tbaa !5
  %51 = fcmp oeq double %50, 0.000000e+00
  br i1 %51, label %52, label %55

52:                                               ; preds = %49
  %53 = load double, ptr %10, align 8, !tbaa !5
  store double %53, ptr %15, align 8, !tbaa !5
  %54 = load double, ptr %9, align 8, !tbaa !5
  store double %54, ptr %16, align 8, !tbaa !5
  br label %74

55:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %56 = load double, ptr %11, align 8, !tbaa !5
  %57 = fdiv double -1.000000e+00, %56
  store double %57, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %58 = load double, ptr %8, align 8, !tbaa !5
  %59 = load double, ptr %19, align 8, !tbaa !5
  %60 = load double, ptr %9, align 8, !tbaa !5
  %61 = fneg double %59
  %62 = call double @llvm.fmuladd.f64(double %61, double %60, double %58)
  store double %62, ptr %20, align 8, !tbaa !5
  %63 = load double, ptr %10, align 8, !tbaa !5
  %64 = load double, ptr %20, align 8, !tbaa !5
  %65 = fsub double %63, %64
  %66 = load double, ptr %19, align 8, !tbaa !5
  %67 = load double, ptr %11, align 8, !tbaa !5
  %68 = fsub double %66, %67
  %69 = fdiv double %65, %68
  store double %69, ptr %16, align 8, !tbaa !5
  %70 = load double, ptr %10, align 8, !tbaa !5
  %71 = load double, ptr %11, align 8, !tbaa !5
  %72 = load double, ptr %16, align 8, !tbaa !5
  %73 = call double @llvm.fmuladd.f64(double %71, double %72, double %70)
  store double %73, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %74

74:                                               ; preds = %55, %52
  br label %75

75:                                               ; preds = %74, %48
  %76 = load double, ptr %15, align 8, !tbaa !5
  %77 = load ptr, ptr %13, align 8, !tbaa !11
  store double %76, ptr %77, align 8, !tbaa !5
  %78 = load double, ptr %16, align 8, !tbaa !5
  %79 = load ptr, ptr %14, align 8, !tbaa !11
  store double %78, ptr %79, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

; 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: write) uwtable
define dso_local void @_Z19ComputeClosestPointddddiPdS_(double noundef %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4, ptr nocapture noundef writeonly %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #1 {
  %8 = icmp eq i32 %4, 0
  %9 = fcmp oeq double %3, 0.000000e+00
  br i1 %8, label %10, label %19

10:                                               ; preds = %7
  br i1 %9, label %28, label %11

11:                                               ; preds = %10
  %12 = fdiv double -1.000000e+00, %3
  %13 = fneg double %12
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %0, double %1)
  %15 = fsub double %2, %14
  %16 = fsub double %12, %3
  %17 = fdiv double %15, %16
  %18 = tail call double @llvm.fmuladd.f64(double %3, double %17, double %2)
  br label %28

19:                                               ; preds = %7
  br i1 %9, label %28, label %20

20:                                               ; preds = %19
  %21 = fdiv double -1.000000e+00, %3
  %22 = fneg double %21
  %23 = tail call double @llvm.fmuladd.f64(double %22, double %1, double %0)
  %24 = fsub double %2, %23
  %25 = fsub double %21, %3
  %26 = fdiv double %24, %25
  %27 = tail call double @llvm.fmuladd.f64(double %3, double %26, double %2)
  br label %28

28:                                               ; preds = %19, %10, %20, %11
  %.032 = phi double [ %18, %11 ], [ %26, %20 ], [ %2, %10 ], [ %1, %19 ]
  %.0 = phi double [ %17, %11 ], [ %27, %20 ], [ %0, %10 ], [ %2, %19 ]
  store double %.0, ptr %5, align 8, !tbaa !5
  store double %.032, ptr %6, align 8, !tbaa !5
  ret void
}

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass