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

; 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] }
%struct.MPRegion = type { ptr, i32, ptr, i32, %class.RNArray.1, %class.RNArray.6, %class.RNArray.4, %class.RNArray.8, %class.R3Point, double, %class.R3Box, ptr }
%class.RNArray.1 = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.RNArray.6 = type { %class.RNVArray }
%class.RNArray.4 = type { %class.RNVArray }
%class.RNArray.8 = type { %class.RNVArray }
%struct.MPSurface = type { ptr, i32, ptr, i32, %class.RNArray.5, %class.R3Point, %class.R3Vector, %class.R3Box, ptr }
%class.RNArray.5 = type { %class.RNVArray }
%class.R3Vector = type { [3 x double] }

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZN5R3BoxaSERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8MPRegion13RecomputeBBoxEi(ptr noundef nonnull align 8 dereferenceable(192) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 10
  %10 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56) %9, i32 noundef 1)
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R3PointixEi(ptr noundef nonnull align 8 dereferenceable(24) %10, i32 noundef 2)
  %12 = load double, ptr %11, align 8, !tbaa !11
  store double %12, ptr %5, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 10
  %14 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZN5R3BoxaSERKS_(ptr noundef nonnull align 8 dereferenceable(56) %13, 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 = %28, %2
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 5
  %18 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %17)
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %22 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call noundef ptr @_ZNK7RNArrayIP9MPSurfaceE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %22, i32 noundef %23)
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 10
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.MPSurface, ptr %26, i32 0, i32 7
  call void @_ZN5R3Box5UnionERKS_(ptr noundef nonnull align 8 dereferenceable(56) %25, ptr noundef nonnull align 8 dereferenceable(56) %27)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %28

28:                                               ; preds = %21
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %15, !llvm.loop !13

31:                                               ; preds = %20
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load double, ptr %5, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.MPRegion, ptr %8, i32 0, i32 10
  %37 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56) %36, i32 noundef 1)
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R3PointixEi(ptr noundef nonnull align 8 dereferenceable(24) %37, i32 noundef 2)
  store double %35, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %34, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

declare void @_ZN5R3Box5UnionERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { "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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZN5R3BoxaSERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8MPRegion13RecomputeBBoxEi(ptr noundef nonnull align 8 dereferenceable(192) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 128
  %4 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56) %3, i32 noundef 1)
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R3PointixEi(ptr noundef nonnull align 8 dereferenceable(24) %4, i32 noundef 2)
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZN5R3BoxaSERKS_(ptr noundef nonnull align 8 dereferenceable(56) %3, ptr noundef nonnull align 8 dereferenceable(56) @R3null_box)
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %19, label %16

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.06 = phi i32 [ %13, %.lr.ph ], [ 0, %2 ]
  %11 = tail call noundef ptr @_ZNK7RNArrayIP9MPSurfaceE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %.06)
  %12 = getelementptr inbounds i8, ptr %11, i64 96
  tail call void @_ZN5R3Box5UnionERKS_(ptr noundef nonnull align 8 dereferenceable(56) %3, ptr noundef nonnull align 8 dereferenceable(56) %12)
  %13 = add nuw nsw i32 %.06, 1
  %14 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

16:                                               ; preds = %._crit_edge
  %17 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56) %3, i32 noundef 1)
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R3PointixEi(ptr noundef nonnull align 8 dereferenceable(24) %17, i32 noundef 2)
  store double %6, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %16, %._crit_edge
  ret void
}

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

declare void @_ZN5R3Box5UnionERKS_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN5R3BoxixEi(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) local_unnamed_addr #0 align 2

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

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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