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

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8R3SplitsRK7R3PlaneRK6R3Span(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = 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 8, ptr %6) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span5StartEv(ptr noundef nonnull align 8 dereferenceable(80) %9)
  %11 = call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(24) %10)
  store double %11, ptr %6, align 8, !tbaa !11
  %12 = load double, ptr %6, align 8, !tbaa !11
  %13 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %14 = call noundef i32 @_Z12RNIsNegativedd(double noundef %12, double noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %2
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = or i32 %17, 1
  store i32 %18, ptr %5, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %16, %2
  %20 = load double, ptr %6, align 8, !tbaa !11
  %21 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %22 = call noundef i32 @_Z12RNIsPositivedd(double noundef %20, double noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = or i32 %25, 2
  store i32 %26, ptr %5, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %24, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80) %29)
  %31 = call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %28, ptr noundef nonnull align 8 dereferenceable(24) %30)
  store double %31, ptr %7, align 8, !tbaa !11
  %32 = load double, ptr %7, align 8, !tbaa !11
  %33 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %34 = call noundef i32 @_Z12RNIsNegativedd(double noundef %32, double noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %27
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = or i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %36, %27
  %40 = load double, ptr %7, align 8, !tbaa !11
  %41 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %42 = call noundef i32 @_Z12RNIsPositivedd(double noundef %40, double noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %39
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = or i32 %45, 2
  store i32 %46, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %44, %39
  %48 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %48
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80)) #4 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 = { "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 = { 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 #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}


; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_Z8R3SplitsRK7R3PlaneRK6R3Span(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(80) %1) local_unnamed_addr #0 {
  %3 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span5StartEv(ptr noundef nonnull align 8 dereferenceable(80) %1)
  %4 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %5 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %6 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %4, double noundef %5)
  %.not = icmp ne i32 %6, 0
  %spec.select = zext i1 %.not to i32
  %7 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %8 = tail call noundef i32 @_Z12RNIsPositivedd(double noundef %4, double noundef %7)
  %.not12 = icmp eq i32 %8, 0
  %9 = or disjoint i32 %spec.select, 2
  %.1 = select i1 %.not12, i32 %spec.select, i32 %9
  %10 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80) %1)
  %11 = tail call noundef double @_Z16R3SignedDistanceRK7R3PlaneRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %10)
  %12 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %13 = tail call noundef i32 @_Z12RNIsNegativedd(double noundef %11, double noundef %12)
  %.not13 = icmp ne i32 %13, 0
  %14 = zext i1 %.not13 to i32
  %.2 = or i32 %.1, %14
  %15 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %16 = tail call noundef i32 @_Z12RNIsPositivedd(double noundef %11, double noundef %15)
  %.not14 = icmp eq i32 %16, 0
  %17 = or i32 %.2, 2
  %.3 = select i1 %.not14, i32 %.2, i32 %17
  ret i32 %.3
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK6R3Span3EndEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 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 = { "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" }

!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass