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

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

%class.R3Point = type { [3 x double] }
%class.R3Vector = type { [3 x double] }

@RN_EPSILON = external global double, align 8

declare noundef i32 @_Z10R3ContainsRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare noundef double @_ZNK8R3Vector3DotERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #0

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

declare void @_ZplRK7R3PointRK8R3Vector(ptr dead_on_unwind writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #0

declare void @_ZmlRK8R3Vectord(ptr dead_on_unwind writable sret(%class.R3Vector) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #0

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12R3IntersectsRK5R3RayRK7R3PlaneP7R3PointPd(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca %class.R3Point, align 8
  %14 = alloca %class.R3Vector, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Plane6NormalEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray6VectorEv(ptr noundef nonnull align 8 dereferenceable(48) %17)
  %19 = call noundef double @_ZNK8R3Vector3DotERKS_(ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 8 dereferenceable(24) %18)
  store double %19, ptr %10, align 8, !tbaa !9
  %20 = load double, ptr %10, align 8, !tbaa !9
  %21 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %22 = call noundef i32 @_Z8RNIsZerodd(double noundef %20, double noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %32

24:                                               ; preds = %4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray5StartEv(ptr noundef nonnull align 8 dereferenceable(48) %26)
  %28 = call noundef i32 @_Z10R3ContainsRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %25, ptr noundef nonnull align 8 dereferenceable(24) %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i32 3, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %64

31:                                               ; preds = %24
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %64

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray5StartEv(ptr noundef nonnull align 8 dereferenceable(48) %34)
  %36 = call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %33, ptr noundef nonnull align 8 dereferenceable(24) %35)
  %37 = fneg double %36
  %38 = load double, ptr %10, align 8, !tbaa !9
  %39 = fdiv double %37, %38
  store double %39, ptr %12, align 8, !tbaa !9
  %40 = load double, ptr %12, align 8, !tbaa !9
  %41 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %42 = call noundef i32 @_Z12RNIsNegativedd(double noundef %40, double noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

45:                                               ; preds = %32
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %56

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray5StartEv(ptr noundef nonnull align 8 dereferenceable(48) %49)
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray6VectorEv(ptr noundef nonnull align 8 dereferenceable(48) %51)
  %53 = load double, ptr %12, align 8, !tbaa !9
  call void @_ZmlRK8R3Vectord(ptr dead_on_unwind writable sret(%class.R3Vector) align 8 %14, ptr noundef nonnull align 8 dereferenceable(24) %52, double noundef %53)
  call void @_ZplRK7R3PointRK8R3Vector(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %13, ptr noundef nonnull align 8 dereferenceable(24) %50, ptr noundef nonnull align 8 dereferenceable(24) %14)
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %54, ptr noundef nonnull align 8 dereferenceable(24) %13)
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #5
  br label %56

56:                                               ; preds = %48, %45
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %62

59:                                               ; preds = %56
  %60 = load double, ptr %12, align 8, !tbaa !9
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  store double %60, ptr %61, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %59, %56
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %64

64:                                               ; preds = %63, %31, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %65 = load i32, ptr %5, align 4
  ret i32 %65
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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"

%class.R3Point = type { [3 x double] }
%class.R3Vector = type { [3 x double] }

@RN_EPSILON = external local_unnamed_addr global double, align 8

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

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

declare void @_ZplRK7R3PointRK8R3Vector(ptr dead_on_unwind writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

declare void @_ZmlRK8R3Vectord(ptr dead_on_unwind writable sret(%class.R3Vector) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

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

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

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

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 #3

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_Z12R3IntersectsRK5R3RayRK7R3PlaneP7R3PointPd(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #4 {
  %5 = alloca %class.R3Point, align 8
  %6 = alloca %class.R3Vector, align 8
  %7 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK7R3Plane6NormalEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %8 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray6VectorEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %9 = tail call noundef double @_ZNK8R3Vector3DotERKS_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(24) %8)
  %10 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %11 = tail call noundef i32 @_Z8RNIsZerodd(double noundef %9, double noundef %10)
  %.not = icmp eq i32 %11, 0
  %12 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray5StartEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  br i1 %.not, label %15, label %13

13:                                               ; preds = %4
  %14 = tail call noundef i32 @_Z10R3ContainsRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %12)
  %.not22 = icmp eq i32 %14, 0
  %. = select i1 %.not22, i32 0, i32 3
  br label %28

15:                                               ; preds = %4
  %16 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %12)
  %17 = fneg double %16
  %18 = fdiv double %17, %9
  %19 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %20 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %18, double noundef %19)
  %.not19 = icmp eq i32 %20, 0
  br i1 %.not19, label %21, label %28

21:                                               ; preds = %15
  %.not20 = icmp eq ptr %2, null
  br i1 %.not20, label %26, label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  %23 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray5StartEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  %24 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5R3Ray6VectorEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  call void @_ZmlRK8R3Vectord(ptr dead_on_unwind nonnull writable sret(%class.R3Vector) align 8 %6, ptr noundef nonnull align 8 dereferenceable(24) %24, double noundef %18)
  call void @_ZplRK7R3PointRK8R3Vector(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %5, ptr noundef nonnull align 8 dereferenceable(24) %23, ptr noundef nonnull align 8 dereferenceable(24) %6)
  %25 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  br label %26

26:                                               ; preds = %22, %21
  %.not21 = icmp eq ptr %3, null
  br i1 %.not21, label %28, label %27

27:                                               ; preds = %26
  store double %18, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %15, %27, %26, %13
  %.1 = phi i32 [ %., %13 ], [ 0, %15 ], [ 1, %27 ], [ 1, %26 ]
  ret i32 %.1
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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