; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Dist.ll (Z16R3SignedDistanceRK7R3PlaneRK10R3Triangle)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z16R3SignedDistanceRK7R3PlaneRK10R3Triangle(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(132) %1) #1 {
  %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
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  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) #4
  store double 0xC7EFFFFFE0000000, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0x47EFFFFFE0000000, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %44, %2
  %12 = load i32, ptr %8, align 4, !tbaa !11
  %13 = icmp slt i32 %12, 3
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %9, align 4
  br label %47

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !11
  %19 = call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %17, i32 noundef %18)
  %20 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %19)
  %21 = call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull align 8 dereferenceable(24) %20)
  store double %21, ptr %10, align 8, !tbaa !9
  %22 = load double, ptr %10, align 8, !tbaa !9
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = fcmp olt double %22, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %15
  %26 = load double, ptr %10, align 8, !tbaa !9
  store double %26, ptr %7, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %25, %15
  %28 = load double, ptr %10, align 8, !tbaa !9
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = fcmp ogt double %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  %32 = load double, ptr %10, align 8, !tbaa !9
  store double %32, ptr %6, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %31, %27
  %34 = load double, ptr %7, align 8, !tbaa !9
  %35 = fcmp olt double %34, 0.000000e+00
  br i1 %35, label %36, label %40

36:                                               ; preds = %33
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fcmp ogt double %37, 0.000000e+00
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store double 0.000000e+00, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %41

40:                                               ; preds = %36, %33
  store i32 0, ptr %9, align 4
  br label %41

41:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %42 = load i32, ptr %9, align 4
  switch i32 %42, label %47 [
    i32 0, label %43
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !11
  br label %11, !llvm.loop !13

47:                                               ; preds = %41, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %48 = load i32, ptr %9, align 4
  switch i32 %48, label %60 [
    i32 2, label %49
  ]

49:                                               ; preds = %47
  %50 = load double, ptr %7, align 8, !tbaa !9
  %51 = fcmp ogt double %50, 0.000000e+00
  br i1 %51, label %52, label %54

52:                                               ; preds = %49
  %53 = load double, ptr %7, align 8, !tbaa !9
  store double %53, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %60

54:                                               ; preds = %49
  %55 = load double, ptr %6, align 8, !tbaa !9
  %56 = fcmp olt double %55, 0.000000e+00
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load double, ptr %6, align 8, !tbaa !9
  store double %58, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %60

59:                                               ; preds = %54
  store double 0.000000e+00, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %60

60:                                               ; preds = %59, %57, %52, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %61 = load double, ptr %3, align 8
  ret double %61
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100)) #3 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z16R3SignedDistanceRK7R3PlaneRK10R3Triangle(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(132) %1) local_unnamed_addr #0 {
  %3 = tail call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %1, i32 noundef 0)
  %4 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %3)
  %5 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = fcmp olt double %5, 0x47EFFFFFE0000000
  %.125 = select i1 %6, double %5, double 0x47EFFFFFE0000000
  %7 = fcmp ogt double %5, 0xC7EFFFFFE0000000
  %.128 = select i1 %7, double %5, double 0xC7EFFFFFE0000000
  %8 = fcmp uge double %.125, 0.000000e+00
  %9 = fcmp ule double %.128, 0.000000e+00
  %or.cond.not = or i1 %8, %9
  br i1 %or.cond.not, label %10, label %.loopexit

10:                                               ; preds = %2
  %11 = tail call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %1, i32 noundef 1)
  %12 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %11)
  %13 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = fcmp olt double %13, %.125
  %.125.1 = select i1 %14, double %13, double %.125
  %15 = fcmp ogt double %13, %.128
  %.128.1 = select i1 %15, double %13, double %.128
  %16 = fcmp uge double %.125.1, 0.000000e+00
  %17 = fcmp ule double %.128.1, 0.000000e+00
  %or.cond.not.1 = or i1 %16, %17
  br i1 %or.cond.not.1, label %18, label %.loopexit

18:                                               ; preds = %10
  %19 = tail call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %1, i32 noundef 2)
  %20 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %19)
  %21 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %20)
  %22 = fcmp olt double %21, %.125.1
  %.125.2 = select i1 %22, double %21, double %.125.1
  %23 = fcmp ogt double %21, %.128.1
  %.128.2 = select i1 %23, double %21, double %.128.1
  %24 = fcmp uge double %.125.2, 0.000000e+00
  %25 = fcmp ule double %.128.2, 0.000000e+00
  %or.cond.not.2 = or i1 %24, %25
  br i1 %or.cond.not.2, label %26, label %.loopexit

26:                                               ; preds = %18
  %27 = fcmp ogt double %.125.2, 0.000000e+00
  br i1 %27, label %.loopexit, label %28

28:                                               ; preds = %26
  %29 = fcmp olt double %.128.2, 0.000000e+00
  %.229. = select i1 %29, double %.128.2, double 0.000000e+00
  br label %.loopexit

.loopexit:                                        ; preds = %2, %10, %18, %28, %26
  %.3 = phi double [ %.125.2, %26 ], [ %.229., %28 ], [ 0.000000e+00, %18 ], [ 0.000000e+00, %10 ], [ 0.000000e+00, %2 ]
  ret double %.3
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100)) local_unnamed_addr #2 align 2

attributes #0 = { 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 #1 = { inlinehint 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 #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" }

!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: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass