; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Dist.ll (Z10R2DistanceRK5R2BoxS1_)

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

@RN_EPSILON = external global double, align 8

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z11RNIsGreaterddd(double noundef, double noundef, double noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z10R2DistanceRK5R2BoxS1_(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) #4 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %9)
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
  %13 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %14 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %10, double noundef %12, double noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %17)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %19)
  %21 = fsub double %18, %20
  store double %21, ptr %6, align 8, !tbaa !9
  br label %38

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %23)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %25)
  %27 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %28 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %24, double noundef %26, double noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %36

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %31)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %33)
  %35 = fsub double %32, %34
  store double %35, ptr %6, align 8, !tbaa !9
  br label %37

36:                                               ; preds = %22
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %36, %30
  br label %38

38:                                               ; preds = %37, %16
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %39)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %41)
  %43 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %44 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %40, double noundef %42, double noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %52

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %47)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %49)
  %51 = fsub double %48, %50
  store double %51, ptr %7, align 8, !tbaa !9
  br label %68

52:                                               ; preds = %38
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %55)
  %57 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %58 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %54, double noundef %56, double noundef %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %52
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %61)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %63)
  %65 = fsub double %62, %64
  store double %65, ptr %7, align 8, !tbaa !9
  br label %67

66:                                               ; preds = %52
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %66, %60
  br label %68

68:                                               ; preds = %67, %46
  %69 = load double, ptr %7, align 8, !tbaa !9
  %70 = fcmp oeq double %69, 0.000000e+00
  br i1 %70, label %71, label %73

71:                                               ; preds = %68
  %72 = load double, ptr %6, align 8, !tbaa !9
  store double %72, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %86

73:                                               ; preds = %68
  %74 = load double, ptr %6, align 8, !tbaa !9
  %75 = fcmp oeq double %74, 0.000000e+00
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = load double, ptr %7, align 8, !tbaa !9
  store double %77, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %86

78:                                               ; preds = %73
  %79 = load double, ptr %6, align 8, !tbaa !9
  %80 = load double, ptr %6, align 8, !tbaa !9
  %81 = load double, ptr %7, align 8, !tbaa !9
  %82 = load double, ptr %7, align 8, !tbaa !9
  %83 = fmul double %81, %82
  %84 = call double @llvm.fmuladd.f64(double %79, double %80, double %83)
  %85 = call double @sqrt(double noundef %84) #5
  store double %85, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %86

86:                                               ; preds = %78, %76, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %87 = load double, ptr %3, align 8
  ret double %87
}

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


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

@RN_EPSILON = external local_unnamed_addr global double, align 8

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z11RNIsGreaterddd(double noundef, double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z10R2DistanceRK5R2BoxS1_(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) local_unnamed_addr #2 {
  %3 = tail call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %4 = tail call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %5 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %6 = tail call noundef i32 @_Z11RNIsGreaterddd(double noundef %3, double noundef %4, double noundef %5)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.sink.split

7:                                                ; preds = %2
  %8 = tail call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %9 = tail call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %10 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %11 = tail call noundef i32 @_Z11RNIsGreaterddd(double noundef %8, double noundef %9, double noundef %10)
  %.not27 = icmp eq i32 %11, 0
  br i1 %.not27, label %15, label %.sink.split

.sink.split:                                      ; preds = %7, %2
  %.sink33 = phi ptr [ %0, %2 ], [ %1, %7 ]
  %.sink32 = phi ptr [ %1, %2 ], [ %0, %7 ]
  %12 = tail call noundef double @_ZNK5R2Box4XMinEv(ptr noundef nonnull align 8 dereferenceable(40) %.sink33)
  %13 = tail call noundef double @_ZNK5R2Box4XMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %.sink32)
  %14 = fsub double %12, %13
  br label %15

15:                                               ; preds = %.sink.split, %7
  %.025 = phi double [ 0.000000e+00, %7 ], [ %14, %.sink.split ]
  %16 = tail call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %17 = tail call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %18 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %19 = tail call noundef i32 @_Z11RNIsGreaterddd(double noundef %16, double noundef %17, double noundef %18)
  %.not28 = icmp eq i32 %19, 0
  br i1 %.not28, label %20, label %25

20:                                               ; preds = %15
  %21 = tail call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %22 = tail call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %23 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %24 = tail call noundef i32 @_Z11RNIsGreaterddd(double noundef %21, double noundef %22, double noundef %23)
  %.not29 = icmp eq i32 %24, 0
  br i1 %.not29, label %.thread, label %25

25:                                               ; preds = %20, %15
  %.sink36 = phi ptr [ %0, %15 ], [ %1, %20 ]
  %.sink35 = phi ptr [ %1, %15 ], [ %0, %20 ]
  %26 = tail call noundef double @_ZNK5R2Box4YMinEv(ptr noundef nonnull align 8 dereferenceable(40) %.sink36)
  %27 = tail call noundef double @_ZNK5R2Box4YMaxEv(ptr noundef nonnull align 8 dereferenceable(40) %.sink35)
  %28 = fsub double %26, %27
  %29 = fcmp oeq double %28, 0.000000e+00
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %25
  %31 = fcmp oeq double %.025, 0.000000e+00
  br i1 %31, label %.thread, label %32

32:                                               ; preds = %30
  %33 = fmul double %28, %28
  %34 = tail call double @llvm.fmuladd.f64(double %.025, double %.025, double %33)
  %sqrt = tail call double @llvm.sqrt.f64(double %34)
  br label %.thread

.thread:                                          ; preds = %20, %30, %25, %32
  %.026 = phi double [ %sqrt, %32 ], [ %.025, %25 ], [ %28, %30 ], [ %.025, %20 ]
  ret double %.026
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { inlinehint 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 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 = { 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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