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

; 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.R3Halfspace = type { %class.R3Plane }
%class.R3Plane = type { %class.R3Vector, double }
%class.R3Vector = type { [3 x double] }

; 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 uwtable
declare dso_local noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10R3ContainsRK13R3OrientedBoxRK7R3Point(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %class.R3Halfspace, align 8
  %10 = alloca %class.R3Plane, align 8
  %11 = alloca %class.R3Plane, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128) %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %50

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %44, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %7, align 4
  br label %47

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %38, %21
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 3
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 5, ptr %7, align 4
  br label %41

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #4
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind writable sret(%class.R3Plane) align 8 %11, ptr noundef nonnull align 8 dereferenceable(128) %27, i32 noundef %28, i32 noundef %29)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind writable sret(%class.R3Plane) align 8 %10, ptr noundef nonnull align 8 dereferenceable(32) %11)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(24) %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %26
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %35

34:                                               ; preds = %26
  store i32 0, ptr %7, align 4
  br label %35

35:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  %36 = load i32, ptr %7, align 4
  switch i32 %36, label %41 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !11

41:                                               ; preds = %35, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %42 = load i32, ptr %7, align 4
  switch i32 %42, label %47 [
    i32 5, label %43
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !13

47:                                               ; preds = %41, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %48 = load i32, ptr %7, align 4
  switch i32 %48, label %52 [
    i32 2, label %49
    i32 1, label %50
  ]

49:                                               ; preds = %47
  store i32 1, ptr %3, align 4
  br label %50

50:                                               ; preds = %49, %47, %15
  %51 = load i32, ptr %3, align 4
  ret i32 %51

52:                                               ; preds = %47
  unreachable
}

declare void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind writable sret(%class.R3Plane) align 8, ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, i32 noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK7R3PlanengEv(ptr dead_on_unwind noalias writable sret(%class.R3Plane) align 8, ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

declare void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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.R3Halfspace = type { %class.R3Plane }
%class.R3Plane = type { %class.R3Vector, double }
%class.R3Vector = type { [3 x double] }

; 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 uwtable
declare dso_local noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10R3ContainsRK13R3OrientedBoxRK7R3Point(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #2 {
  %3 = alloca %class.R3Halfspace, align 8
  %4 = alloca %class.R3Plane, align 8
  %5 = alloca %class.R3Plane, align 8
  %6 = tail call noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 0, i32 noundef 0)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %7 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not = icmp eq i32 %7, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not, label %.loopexit.loopexit, label %8

8:                                                ; preds = %.preheader.preheader
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 0, i32 noundef 1)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %9 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not.1 = icmp eq i32 %9, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not.1, label %.loopexit.loopexit, label %10

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 0, i32 noundef 2)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %11 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not.2 = icmp eq i32 %11, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not.2, label %.loopexit.loopexit, label %.preheader.1

.preheader.1:                                     ; preds = %10
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 1, i32 noundef 0)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %12 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not.128 = icmp eq i32 %12, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not.128, label %.loopexit.loopexit, label %13

13:                                               ; preds = %.preheader.1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 1, i32 noundef 1)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %14 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not.1.1 = icmp eq i32 %14, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not.1.1, label %.loopexit.loopexit, label %15

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %5, ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef 1, i32 noundef 2)
  call void @_ZNK7R3PlanengEv(ptr dead_on_unwind nonnull writable sret(%class.R3Plane) align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %16 = call noundef i32 @_Z10R3ContainsRK11R3HalfspaceRK7R3Point(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not18.not.2.1 = icmp eq i32 %16, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  br i1 %.not18.not.2.1, label %.loopexit.loopexit, label %.loopexit

.loopexit.loopexit:                               ; preds = %15, %13, %.preheader.1, %10, %8, %.preheader.preheader
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %15, %2
  %.5 = phi i32 [ 0, %2 ], [ 0, %.loopexit.loopexit ], [ 1, %15 ]
  ret i32 %.5
}

declare void @_ZNK13R3OrientedBox5PlaneEii(ptr dead_on_unwind writable sret(%class.R3Plane) align 8, ptr noundef nonnull align 8 dereferenceable(128), i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK7R3PlanengEv(ptr dead_on_unwind noalias writable sret(%class.R3Plane) align 8, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

declare void @_ZN11R3HalfspaceC1ERK7R3Planei(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #3

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


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass