; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RGBD/RGBDConfiguration.ll (ZNK17RGBDConfiguration13WorldCentroidEv)

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

@R3null_point = external global %class.R3Point, align 8
@RN_EPSILON = external global double, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK17RGBDConfiguration13WorldCentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(128) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca %class.R3Point, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %class.R3Point, align 8
  %10 = alloca %class.R3Point, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %29, %2
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = call noundef i32 @_ZNK17RGBDConfiguration9NSurfacesEv(ptr noundef nonnull align 8 dereferenceable(128) %12)
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %32

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = call noundef ptr @_ZNK17RGBDConfiguration7SurfaceEi(ptr noundef nonnull align 8 dereferenceable(128) %12, i32 noundef %19)
  store ptr %20, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #4
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = call noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144) %21)
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZNK11RGBDSurface13WorldCentroidEv(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %10, ptr noundef nonnull align 8 dereferenceable(144) %23)
  call void @_ZmldRK7R3Point(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %9, double noundef %22, ptr noundef nonnull align 8 dereferenceable(24) %10)
  %24 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %9)
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = call noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144) %25)
  %27 = load double, ptr %5, align 8, !tbaa !9
  %28 = fadd double %27, %26
  store double %28, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %29

29:                                               ; preds = %18
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !11
  br label %13, !llvm.loop !13

32:                                               ; preds = %17
  %33 = load double, ptr %5, align 8, !tbaa !9
  %34 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %35 = call noundef i32 @_Z8RNIsZerodd(double noundef %33, double noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  store i32 1, ptr %11, align 4
  br label %40

38:                                               ; preds = %32
  %39 = load double, ptr %5, align 8, !tbaa !9
  call void @_ZdvRK7R3Pointd(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %6, double noundef %39)
  store i32 1, ptr %11, align 4
  br label %40

40:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

declare void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZmldRK7R3Point(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, double noundef, ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144)) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK11RGBDSurface13WorldCentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(144)) #0 align 2

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) #0

declare void @_ZdvRK7R3Pointd(ptr dead_on_unwind writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) #3

attributes #0 = { 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 #1 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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.R3Point = type { [3 x double] }

@R3null_point = external global %class.R3Point, align 8
@RN_EPSILON = external local_unnamed_addr global double, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK17RGBDConfiguration13WorldCentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(128) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %class.R3Point, align 8
  %4 = alloca %class.R3Point, align 8
  %5 = alloca %class.R3Point, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  %6 = call noundef i32 @_ZNK17RGBDConfiguration9NSurfacesEv(ptr noundef nonnull align 8 dereferenceable(128) %1)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.0.lcssa = phi double [ 0.000000e+00, %2 ], [ %14, %.lr.ph ]
  %8 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %9 = call noundef i32 @_Z8RNIsZerodd(double noundef %.0.lcssa, double noundef %8)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %19, label %18

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.011 = phi double [ %14, %.lr.ph ], [ 0.000000e+00, %2 ]
  %.0910 = phi i32 [ %15, %.lr.ph ], [ 0, %2 ]
  %10 = call noundef ptr @_ZNK17RGBDConfiguration7SurfaceEi(ptr noundef nonnull align 8 dereferenceable(128) %1, i32 noundef %.0910)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %11 = call noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144) %10)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @_ZNK11RGBDSurface13WorldCentroidEv(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %5, ptr noundef nonnull align 8 dereferenceable(144) %10)
  call void @_ZmldRK7R3Point(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %4, double noundef %11, ptr noundef nonnull align 8 dereferenceable(24) %5)
  %12 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  %13 = call noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144) %10)
  %14 = fadd double %.011, %13
  %15 = add nuw nsw i32 %.0910, 1
  %16 = call noundef i32 @_ZNK17RGBDConfiguration9NSurfacesEv(ptr noundef nonnull align 8 dereferenceable(128) %1)
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !9

18:                                               ; preds = %._crit_edge
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  br label %20

19:                                               ; preds = %._crit_edge
  call void @_ZdvRK7R3Pointd(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %3, double noundef %.0.lcssa)
  br label %20

20:                                               ; preds = %19, %18
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

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

declare void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZmldRK7R3Point(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, double noundef, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK11RGBDSurface9WorldAreaEv(ptr noundef nonnull align 8 dereferenceable(144)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK11RGBDSurface13WorldCentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(144)) local_unnamed_addr #0 align 2

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) local_unnamed_addr #0

declare void @_ZdvRK7R3Pointd(ptr dead_on_unwind writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(24), double noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { 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 = !{!"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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass