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

; 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] }

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10R3ContainsRK8R3SphereRK13R3OrientedBox(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(128) %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 %class.R3Point, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128) %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

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

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

14:                                               ; preds = %27, %13
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 8
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %8, ptr noundef nonnull align 8 dereferenceable(128) %20, i32 noundef %21)
  %22 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %19, ptr noundef nonnull align 8 dereferenceable(24) %8)
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %30

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !11

30:                                               ; preds = %25, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %31 = load i32, ptr %7, align 4
  switch i32 %31, label %35 [
    i32 2, label %32
    i32 1, label %33
  ]

32:                                               ; preds = %30
  store i32 1, ptr %3, align 4
  br label %33

33:                                               ; preds = %32, %30, %12
  %34 = load i32, ptr %3, align 4
  ret i32 %34

35:                                               ; preds = %30
  unreachable
}

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 = { 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"}


; 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] }

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z10R3ContainsRK8R3SphereRK13R3OrientedBox(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(128) %1) local_unnamed_addr #2 {
  %3 = alloca %class.R3Point, align 8
  %4 = tail call noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128) %1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.preheader.preheader, label %13

.preheader.preheader:                             ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 0)
  %5 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9 = icmp eq i32 %5, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9, label %13, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 1)
  %6 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.1 = icmp eq i32 %6, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.1, label %13, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 2)
  %7 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.2 = icmp eq i32 %7, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.2, label %13, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 3)
  %8 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.3 = icmp eq i32 %8, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.3, label %13, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 4)
  %9 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.4 = icmp eq i32 %9, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.4, label %13, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 5)
  %10 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.5 = icmp eq i32 %10, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.5, label %13, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 6)
  %11 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.6 = icmp eq i32 %11, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br i1 %.not9.6, label %13, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef 7)
  %12 = call noundef i32 @_Z10R3ContainsRK8R3SphereRK7R3Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not9.7 = icmp ne i32 %12, 0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  %spec.select = zext i1 %.not9.7 to i32
  br label %13

13:                                               ; preds = %.preheader.7, %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %2
  %.1 = phi i32 [ 0, %2 ], [ 0, %.preheader.preheader ], [ 0, %.preheader.1 ], [ 0, %.preheader.2 ], [ 0, %.preheader.3 ], [ 0, %.preheader.4 ], [ 0, %.preheader.5 ], [ 0, %.preheader.6 ], [ %spec.select, %.preheader.7 ]
  ret i32 %.1
}

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 = { 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,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass