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

; 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

declare noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(16)) #0

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12R2IntersectsRK6R2SpanS1_P7R2PointPdS4_(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(80) %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #4 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80) %16)
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = call noundef i32 @_Z12R2IntersectsRK6R2SpanRK5R2RayP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(80) %15, ptr noundef nonnull align 8 dereferenceable(56) %17, ptr noundef %18, ptr noundef %12, ptr noundef %13)
  switch i32 %19, label %56 [
    i32 0, label %20
    i32 4, label %21
    i32 1, label %35
  ]

20:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

21:                                               ; preds = %5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span5StartEv(ptr noundef nonnull align 8 dereferenceable(80) %23)
  %25 = call noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80) %22, ptr noundef nonnull align 8 dereferenceable(16) %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %33, label %27

27:                                               ; preds = %21
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80) %29)
  %31 = call noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80) %28, ptr noundef nonnull align 8 dereferenceable(16) %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %27, %21
  store i32 4, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

34:                                               ; preds = %27
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

35:                                               ; preds = %5
  %36 = load double, ptr %12, align 8, !tbaa !9
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %37)
  %39 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %40 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %36, double noundef %38, double noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

43:                                               ; preds = %35
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %49

46:                                               ; preds = %43
  %47 = load double, ptr %12, align 8, !tbaa !9
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  store double %47, ptr %48, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %46, %43
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %55

52:                                               ; preds = %49
  %53 = load double, ptr %13, align 8, !tbaa !9
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  store double %53, ptr %54, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %52, %49
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

56:                                               ; preds = %5
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str)
  br label %57

57:                                               ; preds = %56
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str.1)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %58

58:                                               ; preds = %57, %55, %42, %34, %33, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %59 = load i32, ptr %6, align 4
  ret i32 %59
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z12R2IntersectsRK6R2SpanRK5R2RayP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(56), ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span5StartEv(ptr noundef nonnull align 8 dereferenceable(80)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80)) #2 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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

declare noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(16)) 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

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

; 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 #2 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 5) i32 @_Z12R2IntersectsRK6R2SpanS1_P7R2PointPdS4_(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(80) %1, ptr noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #4 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %8 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK6R2Span3RayEv(ptr noundef nonnull align 8 dereferenceable(80) %1)
  %9 = call noundef i32 @_Z12R2IntersectsRK6R2SpanRK5R2RayP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(56) %8, ptr noundef %2, ptr noundef nonnull %6, ptr noundef nonnull %7)
  switch i32 %9, label %27 [
    i32 0, label %28
    i32 4, label %10
    i32 1, label %16
  ]

10:                                               ; preds = %5
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span5StartEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %12 = call noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80) %1, ptr noundef nonnull align 8 dereferenceable(16) %11)
  %.not16 = icmp eq i32 %12, 0
  br i1 %.not16, label %13, label %28

13:                                               ; preds = %10
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %15 = call noundef i32 @_Z10R2ContainsRK6R2SpanRK7R2Point(ptr noundef nonnull align 8 dereferenceable(80) %1, ptr noundef nonnull align 8 dereferenceable(16) %14)
  %.not17 = icmp eq i32 %15, 0
  %spec.select = select i1 %.not17, i32 0, i32 4
  br label %28

16:                                               ; preds = %5
  %17 = load double, ptr %6, align 8, !tbaa !5
  %18 = call noundef double @_ZNK6R2Span6LengthEv(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %19 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %20 = call noundef i32 @_Z11RNIsGreaterddd(double noundef %17, double noundef %18, double noundef %19)
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %28

21:                                               ; preds = %16
  %.not14 = icmp eq ptr %3, null
  br i1 %.not14, label %24, label %22

22:                                               ; preds = %21
  %23 = load double, ptr %6, align 8, !tbaa !5
  store double %23, ptr %3, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %22, %21
  %.not15 = icmp eq ptr %4, null
  br i1 %.not15, label %28, label %25

25:                                               ; preds = %24
  %26 = load double, ptr %7, align 8, !tbaa !5
  store double %26, ptr %4, align 8, !tbaa !5
  br label %28

27:                                               ; preds = %5
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str)
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str.1)
  br label %28

28:                                               ; preds = %13, %24, %25, %16, %10, %5, %27
  %.0 = phi i32 [ 0, %27 ], [ %9, %5 ], [ 4, %10 ], [ 0, %16 ], [ 1, %25 ], [ 1, %24 ], [ %spec.select, %13 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z12R2IntersectsRK6R2SpanRK5R2RayP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(56), ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK6R2Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #2 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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