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

; 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

declare noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8R3SplitsRK7R3PlaneRK10R3Triangle(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(132) %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %51, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 3
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %54

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %15, i32 noundef %16)
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %17)
  %19 = call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %14, ptr noundef nonnull align 8 dereferenceable(24) %18)
  store double %19, ptr %8, align 8, !tbaa !11
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = and i32 %20, 1
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %31, label %23

23:                                               ; preds = %13
  %24 = load double, ptr %8, align 8, !tbaa !11
  %25 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %26 = call noundef i32 @_Z12RNIsNegativedd(double noundef %24, double noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = or i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %28, %23, %13
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = and i32 %32, 2
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %43, label %35

35:                                               ; preds = %31
  %36 = load double, ptr %8, align 8, !tbaa !11
  %37 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %38 = call noundef i32 @_Z12RNIsPositivedd(double noundef %36, double noundef %37)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = or i32 %41, 2
  store i32 %42, ptr %5, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %35, %31
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 3
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i32 2, ptr %7, align 4
  br label %48

47:                                               ; preds = %43
  store i32 0, ptr %7, align 4
  br label %48

48:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %49 = load i32, ptr %7, align 4
  switch i32 %49, label %54 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !13

54:                                               ; preds = %48, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %56
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) #4 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)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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" }
attributes #3 = { 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 #4 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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"

@RN_EPSILON = external local_unnamed_addr global double, align 8

declare noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_Z8R3SplitsRK7R3PlaneRK10R3Triangle(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(132) %1) local_unnamed_addr #2 {
  %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 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %7 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %5, double noundef %6)
  %.not15 = icmp ne i32 %7, 0
  %8 = zext i1 %.not15 to i32
  %9 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %10 = tail call noundef i32 @_Z12RNIsPositivedd(double noundef %5, double noundef %9)
  %.not17 = icmp eq i32 %10, 0
  %11 = or disjoint i32 %8, 2
  %spec.select19 = select i1 %.not17, i32 %8, i32 %11
  %.not18 = icmp eq i32 %spec.select19, 3
  br i1 %.not18, label %43, label %12

12:                                               ; preds = %2
  %13 = tail call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %1, i32 noundef 1)
  %14 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %13)
  %15 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %14)
  %16 = and i32 %spec.select19, 1
  %.not.1 = icmp eq i32 %16, 0
  br i1 %.not.1, label %17, label %21

17:                                               ; preds = %12
  %18 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %19 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %15, double noundef %18)
  %.not15.1 = icmp ne i32 %19, 0
  %20 = zext i1 %.not15.1 to i32
  %spec.select.1 = or disjoint i32 %spec.select19, %20
  br label %21

21:                                               ; preds = %17, %12
  %.1.1 = phi i32 [ %spec.select19, %12 ], [ %spec.select.1, %17 ]
  %22 = and i32 %.1.1, 2
  %.not16.1 = icmp eq i32 %22, 0
  br i1 %.not16.1, label %23, label %27

23:                                               ; preds = %21
  %24 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %25 = tail call noundef i32 @_Z12RNIsPositivedd(double noundef %15, double noundef %24)
  %.not17.1 = icmp eq i32 %25, 0
  %26 = or disjoint i32 %.1.1, 2
  %spec.select19.1 = select i1 %.not17.1, i32 %.1.1, i32 %26
  br label %27

27:                                               ; preds = %23, %21
  %.2.1 = phi i32 [ %.1.1, %21 ], [ %spec.select19.1, %23 ]
  %.not18.1 = icmp eq i32 %.2.1, 3
  br i1 %.not18.1, label %43, label %28

28:                                               ; preds = %27
  %29 = tail call noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132) %1, i32 noundef 2)
  %30 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK16R3TriangleVertex8PositionEv(ptr noundef nonnull align 8 dereferenceable(100) %29)
  %31 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %30)
  %32 = and i32 %.2.1, 1
  %.not.2 = icmp eq i32 %32, 0
  br i1 %.not.2, label %33, label %37

33:                                               ; preds = %28
  %34 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %35 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %31, double noundef %34)
  %.not15.2 = icmp ne i32 %35, 0
  %36 = zext i1 %.not15.2 to i32
  %spec.select.2 = or disjoint i32 %.2.1, %36
  br label %37

37:                                               ; preds = %33, %28
  %.1.2 = phi i32 [ %.2.1, %28 ], [ %spec.select.2, %33 ]
  %38 = and i32 %.1.2, 2
  %.not16.2 = icmp eq i32 %38, 0
  br i1 %.not16.2, label %39, label %43

39:                                               ; preds = %37
  %40 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %41 = tail call noundef i32 @_Z12RNIsPositivedd(double noundef %31, double noundef %40)
  %.not17.2 = icmp eq i32 %41, 0
  %42 = or disjoint i32 %.1.2, 2
  %spec.select19.2 = select i1 %.not17.2, i32 %.1.2, i32 %42
  br label %43

43:                                               ; preds = %37, %39, %27, %2
  %.3 = phi i32 [ 3, %2 ], [ 3, %27 ], [ %.1.2, %37 ], [ %spec.select19.2, %39 ]
  ret i32 %.3
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK10R3Triangle6VertexEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) local_unnamed_addr #3 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 #1 align 2

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

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