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

; 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
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80)) #1 align 2

; Function Attrs: inlinehint mustprogress 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 @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80)) #1 align 2

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12R2IntersectsRK6R2SpanRK5R2BoxP7R2PointPd(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(40) %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
  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
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80) %13)
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = call noundef i32 @_Z12R2IntersectsRK5R2BoxRK5R2RayP7R2PointP8R2VectorPd(ptr noundef nonnull align 8 dereferenceable(40) %12, ptr noundef nonnull align 8 dereferenceable(56) %14, ptr noundef %15, ptr noundef null, ptr noundef %10)
  switch i32 %16, label %42 [
    i32 0, label %17
    i32 4, label %18
    i32 1, label %27
  ]

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

18:                                               ; preds = %4
  %19 = load double, ptr %10, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %20)
  %22 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %23 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %19, double noundef %21, double noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

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

26:                                               ; preds = %18
  store i32 4, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %44

27:                                               ; preds = %4
  %28 = load double, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %29)
  %31 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %32 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %28, double noundef %30, double noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

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

35:                                               ; preds = %27
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load double, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  store double %39, ptr %40, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %38, %35
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %44

42:                                               ; preds = %4
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str)
  br label %43

43:                                               ; preds = %42
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str.1)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %44

44:                                               ; preds = %43, %41, %34, %26, %25, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %45 = load i32, ptr %5, align 4
  ret i32 %45
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

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

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

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 5) i32 @_Z12R2IntersectsRK6R2SpanRK5R2BoxP7R2PointPd(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #4 {
  %5 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %6 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %7 = call noundef i32 @_Z12R2IntersectsRK5R2BoxRK5R2RayP7R2PointP8R2VectorPd(ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(56) %6, ptr noundef %2, ptr noundef null, ptr noundef nonnull %5)
  switch i32 %7, label %21 [
    i32 0, label %22
    i32 4, label %8
    i32 1, label %13
  ]

8:                                                ; preds = %4
  %9 = load double, ptr %5, align 8, !tbaa !5
  %10 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %11 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %12 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %9, double noundef %10, double noundef %11)
  %.not9 = icmp eq i32 %12, 0
  %. = select i1 %.not9, i32 4, i32 0
  br label %22

13:                                               ; preds = %4
  %14 = load double, ptr %5, align 8, !tbaa !5
  %15 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %16 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %17 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %14, double noundef %15, double noundef %16)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %22

18:                                               ; preds = %13
  %.not8 = icmp eq ptr %3, null
  br i1 %.not8, label %22, label %19

19:                                               ; preds = %18
  %20 = load double, ptr %5, align 8, !tbaa !5
  store double %20, ptr %3, align 8, !tbaa !5
  br label %22

21:                                               ; preds = %4
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str)
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str.1)
  br label %22

22:                                               ; preds = %18, %19, %13, %8, %4, %21
  %.0 = phi i32 [ 0, %21 ], [ %7, %4 ], [ %., %8 ], [ 0, %13 ], [ 1, %19 ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z12R2IntersectsRK5R2BoxRK5R2RayP7R2PointP8R2VectorPd(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(56), ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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