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

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

19:                                               ; preds = %5
  %20 = load double, ptr %9, align 8, !tbaa !5
  %21 = fcmp oeq double %20, 0.000000e+00
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load double, ptr %6, align 8, !tbaa !5
  store double %23, ptr %11, align 8, !tbaa !5
  %24 = load double, ptr %8, align 8, !tbaa !5
  store double %24, ptr %12, align 8, !tbaa !5
  br label %44

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %26 = load double, ptr %9, align 8, !tbaa !5
  %27 = fdiv double -1.000000e+00, %26
  store double %27, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = load double, ptr %13, align 8, !tbaa !5
  %30 = load double, ptr %6, align 8, !tbaa !5
  %31 = fneg double %29
  %32 = call double @llvm.fmuladd.f64(double %31, double %30, double %28)
  store double %32, ptr %14, align 8, !tbaa !5
  %33 = load double, ptr %8, align 8, !tbaa !5
  %34 = load double, ptr %14, align 8, !tbaa !5
  %35 = fsub double %33, %34
  %36 = load double, ptr %13, align 8, !tbaa !5
  %37 = load double, ptr %9, align 8, !tbaa !5
  %38 = fsub double %36, %37
  %39 = fdiv double %35, %38
  store double %39, ptr %11, align 8, !tbaa !5
  %40 = load double, ptr %8, align 8, !tbaa !5
  %41 = load double, ptr %9, align 8, !tbaa !5
  %42 = load double, ptr %11, align 8, !tbaa !5
  %43 = call double @llvm.fmuladd.f64(double %41, double %42, double %40)
  store double %43, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %44

44:                                               ; preds = %25, %22
  br label %71

45:                                               ; preds = %5
  %46 = load double, ptr %9, align 8, !tbaa !5
  %47 = fcmp oeq double %46, 0.000000e+00
  br i1 %47, label %48, label %51

48:                                               ; preds = %45
  %49 = load double, ptr %8, align 8, !tbaa !5
  store double %49, ptr %11, align 8, !tbaa !5
  %50 = load double, ptr %7, align 8, !tbaa !5
  store double %50, ptr %12, align 8, !tbaa !5
  br label %70

51:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %52 = load double, ptr %9, align 8, !tbaa !5
  %53 = fdiv double -1.000000e+00, %52
  store double %53, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %54 = load double, ptr %6, align 8, !tbaa !5
  %55 = load double, ptr %15, align 8, !tbaa !5
  %56 = load double, ptr %7, align 8, !tbaa !5
  %57 = fneg double %55
  %58 = call double @llvm.fmuladd.f64(double %57, double %56, double %54)
  store double %58, ptr %16, align 8, !tbaa !5
  %59 = load double, ptr %8, align 8, !tbaa !5
  %60 = load double, ptr %16, align 8, !tbaa !5
  %61 = fsub double %59, %60
  %62 = load double, ptr %15, align 8, !tbaa !5
  %63 = load double, ptr %9, align 8, !tbaa !5
  %64 = fsub double %62, %63
  %65 = fdiv double %61, %64
  store double %65, ptr %12, align 8, !tbaa !5
  %66 = load double, ptr %8, align 8, !tbaa !5
  %67 = load double, ptr %9, align 8, !tbaa !5
  %68 = load double, ptr %12, align 8, !tbaa !5
  %69 = call double @llvm.fmuladd.f64(double %67, double %68, double %66)
  store double %69, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %70

70:                                               ; preds = %51, %48
  br label %71

71:                                               ; preds = %70, %44
  %72 = load double, ptr %6, align 8, !tbaa !5
  %73 = load double, ptr %11, align 8, !tbaa !5
  %74 = fsub double %72, %73
  %75 = load double, ptr %6, align 8, !tbaa !5
  %76 = load double, ptr %11, align 8, !tbaa !5
  %77 = fsub double %75, %76
  %78 = load double, ptr %7, align 8, !tbaa !5
  %79 = load double, ptr %12, align 8, !tbaa !5
  %80 = fsub double %78, %79
  %81 = load double, ptr %7, align 8, !tbaa !5
  %82 = load double, ptr %12, align 8, !tbaa !5
  %83 = fsub double %81, %82
  %84 = fmul double %80, %83
  %85 = call double @llvm.fmuladd.f64(double %74, double %77, double %84)
  %86 = call double @sqrt(double noundef %85) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret double %86
}

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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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(none) uwtable
define dso_local noundef double @_Z18ComputeMinDistanceddddi(double noundef %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = icmp eq i32 %4, 0
  %7 = fcmp oeq double %3, 0.000000e+00
  br i1 %6, label %8, label %17

8:                                                ; preds = %5
  br i1 %7, label %26, label %9

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

17:                                               ; preds = %5
  br i1 %7, label %26, label %18

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

26:                                               ; preds = %17, %8, %18, %9
  %.036 = phi double [ %16, %9 ], [ %24, %18 ], [ %2, %8 ], [ %1, %17 ]
  %.0 = phi double [ %15, %9 ], [ %25, %18 ], [ %0, %8 ], [ %2, %17 ]
  %27 = fsub double %0, %.0
  %28 = fsub double %1, %.036
  %29 = fmul double %28, %28
  %30 = tail call double @llvm.fmuladd.f64(double %27, double %27, double %29)
  %sqrt = tail call double @llvm.sqrt.f64(double %30)
  ret double %sqrt
}

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

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


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