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

; 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.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Point = type { [3 x double] }

@R3null_box = external global %class.R3Box, 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

declare i32 @__gxx_personality_v0(...)

declare void @_ZN5R3BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #1

declare void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK13R3OrientedBox4BBoxEv(ptr dead_on_unwind noalias writable sret(%class.R3Box) align 8 %0, ptr noundef nonnull align 8 dereferenceable(128) %1) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca %class.R3Point, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  %11 = call noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128) %10)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  call void @_ZN5R3BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(56) @R3null_box)
  br label %34

14:                                               ; preds = %2
  store i1 false, ptr %5, align 1
  call void @_ZN5R3BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(56) @R3null_box)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %15

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

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %30

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  invoke void @_ZNK13R3OrientedBox6CornerEi(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %7, ptr noundef nonnull align 8 dereferenceable(128) %10, i32 noundef %20)
          to label %21 unwind label %26

21:                                               ; preds = %19
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %7)
          to label %22 unwind label %26

22:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %15, !llvm.loop !11

26:                                               ; preds = %21, %19
  %27 = landingpad { ptr, i32 }
          cleanup
  %28 = extractvalue { ptr, i32 } %27, 0
  store ptr %28, ptr %8, align 8
  %29 = extractvalue { ptr, i32 } %27, 1
  store i32 %29, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #5
  br label %35

30:                                               ; preds = %18
  store i1 true, ptr %5, align 1
  %31 = load i1, ptr %5, align 1
  br i1 %31, label %33, label %32

32:                                               ; preds = %30
  call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #5
  br label %33

33:                                               ; preds = %32, %30
  br label %34

34:                                               ; preds = %33, %13
  ret void

35:                                               ; preds = %26
  %36 = load ptr, ptr %8, align 8
  %37 = load i32, ptr %9, align 4
  %38 = insertvalue { ptr, i32 } poison, ptr %36, 0
  %39 = insertvalue { ptr, i32 } %38, i32 %37, 1
  resume { ptr, i32 } %39
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind "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 = !{!"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.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Point = type { [3 x double] }

@R3null_box = external global %class.R3Box, align 8

; 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

declare i32 @__gxx_personality_v0(...)

declare void @_ZN5R3BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #1

declare void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK13R3OrientedBox7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK13R3OrientedBox4BBoxEv(ptr dead_on_unwind noalias writable sret(%class.R3Box) align 8 %0, ptr noundef nonnull align 8 dereferenceable(128) %1) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %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
  tail call void @_ZN5R3BoxC1ERKS_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(56) @R3null_box)
  br i1 %.not, label %5, label %.loopexit

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %6 unwind label %21

6:                                                ; preds = %5
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %7 unwind label %21

7:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %8 unwind label %21

8:                                                ; preds = %7
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %9 unwind label %21

9:                                                ; preds = %8
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %10 unwind label %21

10:                                               ; preds = %9
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %11 unwind label %21

11:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %12 unwind label %21

12:                                               ; preds = %11
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %13 unwind label %21

13:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %14 unwind label %21

14:                                               ; preds = %13
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %15 unwind label %21

15:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %16 unwind label %21

16:                                               ; preds = %15
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %17 unwind label %21

17:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %18 unwind label %21

18:                                               ; preds = %17
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %19 unwind label %21

19:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke 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)
          to label %20 unwind label %21

20:                                               ; preds = %19
  invoke void @_ZN5R3Box5UnionERK7R3Point(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %.loopexit.loopexit unwind label %21

.loopexit.loopexit:                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  br label %.loopexit

21:                                               ; preds = %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
  %22 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #5
  resume { ptr, i32 } %22

.loopexit:                                        ; preds = %2, %.loopexit.loopexit
  ret void
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass