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

; 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.MPSurface = type { ptr, i32, ptr, i32, %class.RNArray.5, %class.R3Point, %class.R3Vector, %class.R3Box, ptr }
%class.RNArray.5 = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R3Point = type { [3 x double] }
%class.R3Vector = 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 nounwind uwtable
define dso_local void @_ZN9MPSurfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #3 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 = %15, %1
  %5 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 4
  %6 = invoke noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
          to label %7 unwind label %42

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

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

12:                                               ; preds = %9
  %13 = icmp eq ptr %11, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %12
  call void @_ZN8MPVertexD1Ev(ptr noundef nonnull align 8 dereferenceable(88) %11) #6
  call void @_ZdlPvm(ptr noundef %11, i64 noundef 88) #7
  br label %15

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

16:                                               ; preds = %7
  %17 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  invoke void @_ZN8MPRegion13RemoveSurfaceEP9MPSurface(ptr noundef nonnull align 8 dereferenceable(192) %22, ptr noundef %3)
          to label %23 unwind label %42

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23, %16
  %25 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !21
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %32

28:                                               ; preds = %24
  %29 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  invoke void @_ZN7MPHouse13RemoveSurfaceEP9MPSurface(ptr noundef nonnull align 8 dereferenceable(376) %30, ptr noundef %3)
          to label %31 unwind label %42

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31, %24
  %33 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  call void @free(ptr noundef %38) #6
  br label %39

39:                                               ; preds = %36, %32
  %40 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 7
  call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %40) #6
  %41 = getelementptr inbounds %struct.MPSurface, ptr %3, i32 0, i32 4
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %41) #6
  ret void

42:                                               ; preds = %28, %20, %9, %4
  %43 = landingpad { ptr, i32 }
          catch ptr null
  %44 = extractvalue { ptr, i32 } %43, 0
  call void @__clang_call_terminate(ptr %44) #8
  unreachable
}

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

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

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

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

declare void @_ZN8MPVertexD1Ev(ptr)

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 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 #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 = { nobuiltin 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 #6 = { nounwind }
attributes #7 = { builtin nounwind }
attributes #8 = { 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 16}
!12 = !{!"_ZTS9MPSurface", !6, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !14, i64 32, !16, i64 48, !17, i64 72, !18, i64 96, !6, i64 152}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS7RNArrayIP8MPVertexE", !15, i64 0}
!15 = !{!"_ZTS8RNVArray", !6, i64 0, !13, i64 8, !13, i64 12}
!16 = !{!"_ZTS7R3Point", !7, i64 0}
!17 = !{!"_ZTS8R3Vector", !7, i64 0}
!18 = !{!"_ZTS5R3Box", !19, i64 0, !16, i64 8, !16, i64 32}
!19 = !{!"_ZTS7R3Solid", !20, i64 0}
!20 = !{!"_ZTS7R3Shape"}
!21 = !{!12, !6, i64 0}
!22 = !{!12, !6, i64 152}


; 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 nounwind uwtable
define dso_local void @_ZN9MPSurfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %9
  %5 = invoke noundef ptr @_ZNK7RNArrayIP8MPVertexE4TailEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
          to label %6 unwind label %.loopexit

6:                                                ; preds = %.lr.ph
  %7 = icmp eq ptr %5, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %6
  tail call void @_ZN8MPVertexD1Ev(ptr noundef nonnull align 8 dereferenceable(88) %5) #7
  tail call void @_ZdlPvm(ptr noundef nonnull %5, i64 noundef 88) #8
  br label %9

9:                                                ; preds = %8, %6
  %10 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %9, %1
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !7
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %15, label %14

14:                                               ; preds = %._crit_edge
  invoke void @_ZN8MPRegion13RemoveSurfaceEP9MPSurface(ptr noundef nonnull align 8 dereferenceable(192) %13, ptr noundef nonnull %0)
          to label %15 unwind label %.loopexit.split-lp

15:                                               ; preds = %14, %._crit_edge
  %16 = load ptr, ptr %0, align 8, !tbaa !20
  %.not4 = icmp eq ptr %16, null
  br i1 %.not4, label %18, label %17

17:                                               ; preds = %15
  invoke void @_ZN7MPHouse13RemoveSurfaceEP9MPSurface(ptr noundef nonnull align 8 dereferenceable(376) %16, ptr noundef nonnull %0)
          to label %18 unwind label %.loopexit.split-lp

18:                                               ; preds = %17, %15
  %19 = getelementptr inbounds i8, ptr %0, i64 152
  %20 = load ptr, ptr %19, align 8, !tbaa !21
  %.not5 = icmp eq ptr %20, null
  br i1 %.not5, label %22, label %21

21:                                               ; preds = %18
  tail call void @free(ptr noundef nonnull %20) #7
  br label %22

22:                                               ; preds = %21, %18
  %23 = getelementptr inbounds i8, ptr %0, i64 96
  tail call void @_ZN7R3SolidD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %23) #7
  tail call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #7
  ret void

.loopexit:                                        ; preds = %.lr.ph
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %24

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

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8MPRegion13RemoveSurfaceEP9MPSurface(ptr noundef nonnull align 8 dereferenceable(192), ptr noundef) local_unnamed_addr #5 align 2

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

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

declare void @_ZN8MPVertexD1Ev(ptr) local_unnamed_addr

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 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 = { 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 #6 = { nobuiltin 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 #7 = { nounwind }
attributes #8 = { builtin nounwind }
attributes #9 = { 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 16}
!8 = !{!"_ZTS9MPSurface", !9, i64 0, !12, i64 8, !9, i64 16, !12, i64 24, !13, i64 32, !15, i64 48, !16, i64 72, !17, i64 96, !9, i64 152}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS7RNArrayIP8MPVertexE", !14, i64 0}
!14 = !{!"_ZTS8RNVArray", !9, i64 0, !12, i64 8, !12, i64 12}
!15 = !{!"_ZTS7R3Point", !10, i64 0}
!16 = !{!"_ZTS8R3Vector", !10, i64 0}
!17 = !{!"_ZTS5R3Box", !18, i64 0, !15, i64 8, !15, i64 32}
!18 = !{!"_ZTS7R3Solid", !19, i64 0}
!19 = !{!"_ZTS7R3Shape"}
!20 = !{!8, !9, i64 0}
!21 = !{!8, !9, i64 152}


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