; LLVM IR from niessner/Matterport :: code/gaps/apps/mpview/mp.ll (ZN7MPLevelD2Ev)

; 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"

%struct.MPLevel = type { ptr, i32, %class.RNArray.7, %class.R3Point, %class.R3Box, ptr }
%class.RNArray.7 = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R3Point = type { [3 x double] }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MPLevel12RemoveRegionEP8MPRegion(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7MPLevelD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %0) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  br label %4

4:                                                ; preds = %13, %1
  %5 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 2
  %6 = invoke noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
          to label %7 unwind label %32

7:                                                ; preds = %4
  %8 = icmp sgt i32 %6, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %7
  %10 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 2
  %11 = invoke noundef ptr @_ZNK7RNArrayIP8MPRegionE4TailEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
          to label %12 unwind label %32

12:                                               ; preds = %9
  invoke void @_ZN7MPLevel12RemoveRegionEP8MPRegion(ptr noundef nonnull align 8 dereferenceable(120) %3, ptr noundef %11)
          to label %13 unwind label %32

13:                                               ; preds = %12
  br label %4, !llvm.loop !9

14:                                               ; preds = %7
  %15 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  %19 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  invoke void @_ZN7MPHouse11RemoveLevelEP7MPLevel(ptr noundef nonnull align 8 dereferenceable(376) %20, ptr noundef %3)
          to label %21 unwind label %32

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21, %14
  %23 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %22
  %27 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  call void @free(ptr noundef %28) #5
  br label %29

29:                                               ; preds = %26, %22
  %30 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 4
  call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %30) #5
  %31 = getelementptr inbounds %struct.MPLevel, ptr %3, i32 0, i32 2
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %31) #5
  ret void

32:                                               ; preds = %18, %12, %9, %4
  %33 = landingpad { ptr, i32 }
          catch ptr null
  %34 = extractvalue { ptr, i32 } %33, 0
  call void @__clang_call_terminate(ptr %34) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP8MPRegionE4TailEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MPHouse11RemoveLevelEP7MPLevel(ptr noundef nonnull align 8 dereferenceable(376), ptr noundef) #3 align 2

; Function Attrs: nounwind
declare void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

attributes #0 = { noinline noreturn nounwind uwtable "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 = { 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 #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 = { 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 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 }
attributes #6 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS7MPLevel", !6, i64 0, !13, i64 8, !14, i64 16, !16, i64 32, !17, i64 56, !6, i64 112}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS7RNArrayIP8MPRegionE", !15, i64 0}
!15 = !{!"_ZTS8RNVArray", !6, i64 0, !13, i64 8, !13, i64 12}
!16 = !{!"_ZTS7R3Point", !7, i64 0}
!17 = !{!"_ZTS5R3Box", !18, i64 0, !16, i64 8, !16, i64 32}
!18 = !{!"_ZTS7R3Solid", !19, i64 0}
!19 = !{!"_ZTS7R3Shape"}
!20 = !{!12, !6, i64 112}


; 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"

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MPLevel12RemoveRegionEP8MPRegion(ptr noundef nonnull align 8 dereferenceable(120), ptr noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7MPLevelD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %0) unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  br label %3

3:                                                ; preds = %8, %1
  %4 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = invoke noundef ptr @_ZNK7RNArrayIP8MPRegionE4TailEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
          to label %8 unwind label %.loopexit

8:                                                ; preds = %6
  invoke void @_ZN7MPLevel12RemoveRegionEP8MPRegion(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %7)
          to label %3 unwind label %.loopexit, !llvm.loop !5

9:                                                ; preds = %3
  %10 = load ptr, ptr %0, align 8, !tbaa !7
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %12, label %11

11:                                               ; preds = %9
  invoke void @_ZN7MPHouse11RemoveLevelEP7MPLevel(ptr noundef nonnull align 8 dereferenceable(376) %10, ptr noundef nonnull %0)
          to label %12 unwind label %.loopexit.split-lp

12:                                               ; preds = %11, %9
  %13 = getelementptr inbounds i8, ptr %0, i64 112
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %.not2 = icmp eq ptr %14, null
  br i1 %.not2, label %16, label %15

15:                                               ; preds = %12
  tail call void @free(ptr noundef nonnull %14) #6
  br label %16

16:                                               ; preds = %15, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %17) #6
  tail call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #6
  ret void

.loopexit:                                        ; preds = %6, %8
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %18

.loopexit.split-lp:                               ; preds = %11
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %18

18:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %19 = extractvalue { ptr, i32 } %lpad.phi, 0
  tail call void @__clang_call_terminate(ptr %19) #7
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP8MPRegionE4TailEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MPHouse11RemoveLevelEP7MPLevel(ptr noundef nonnull align 8 dereferenceable(376), ptr noundef) local_unnamed_addr #4 align 2

; Function Attrs: nounwind
declare void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

attributes #0 = { noinline noreturn nounwind uwtable "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { 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 #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 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"_ZTS7MPLevel", !9, i64 0, !12, i64 8, !13, i64 16, !15, i64 32, !16, i64 56, !9, i64 112}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS7RNArrayIP8MPRegionE", !14, i64 0}
!14 = !{!"_ZTS8RNVArray", !9, i64 0, !12, i64 8, !12, i64 12}
!15 = !{!"_ZTS7R3Point", !10, i64 0}
!16 = !{!"_ZTS5R3Box", !17, i64 0, !15, i64 8, !15, i64 32}
!17 = !{!"_ZTS7R3Solid", !18, i64 0}
!18 = !{!"_ZTS7R3Shape"}
!19 = !{!8, !9, i64 112}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass