; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Align.ll (Z10R2CentroidRK7RNArrayIP7R2PointEPKd)

; 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.R2Point = type { [2 x double] }

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

12:                                               ; preds = %39, %3
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %42

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %27

21:                                               ; preds = %18
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !9
  br label %28

27:                                               ; preds = %18
  br label %28

28:                                               ; preds = %27, %21
  %29 = phi double [ %26, %21 ], [ 1.000000e+00, %27 ]
  store double %29, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = call noundef ptr @_ZNK7RNArrayIP7R2PointEixEi(ptr noundef nonnull align 8 dereferenceable(16) %30, i32 noundef %31)
  store ptr %32, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load double, ptr %9, align 8, !tbaa !9
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %11, ptr noundef nonnull align 8 dereferenceable(16) %33, double noundef %34)
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  %36 = load double, ptr %9, align 8, !tbaa !9
  %37 = load double, ptr %7, align 8, !tbaa !9
  %38 = fadd double %37, %36
  store double %38, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %39

39:                                               ; preds = %28
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !11
  br label %12, !llvm.loop !13

42:                                               ; preds = %17
  %43 = load double, ptr %7, align 8, !tbaa !9
  %44 = fcmp ogt double %43, 0.000000e+00
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load double, ptr %7, align 8, !tbaa !9
  %47 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointdVEd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef %46)
  br label %48

48:                                               ; preds = %45, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

declare void @_ZN7R2PointC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1

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

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

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

declare void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), double noundef) #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointdVEd(ptr noundef nonnull align 8 dereferenceable(16), double noundef) #1

attributes #0 = { 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 = { "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 = { 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 #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.R2Point = type { [2 x double] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10R2CentroidRK7RNArrayIP7R2PointEPKd(ptr dead_on_unwind noalias nonnull writable sret(%class.R2Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef readonly %2) local_unnamed_addr #0 {
  %4 = alloca %class.R2Point, align 8
  tail call void @_ZN7R2PointC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %5 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.016.us = phi double [ %9, %.lr.ph.split.us ], [ 0.000000e+00, %.lr.ph ]
  %.01315.us = phi i32 [ %10, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %7 = call noundef ptr @_ZNK7RNArrayIP7R2PointEixEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.01315.us)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %7, double noundef 1.000000e+00)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  %9 = fadd double %.016.us, 1.000000e+00
  %10 = add nuw nsw i32 %.01315.us, 1
  %11 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us
  %.0.lcssa = phi double [ %9, %.lr.ph.split.us ], [ %19, %.lr.ph.split ]
  %13 = fcmp ogt double %.0.lcssa, 0.000000e+00
  br i1 %13, label %23, label %._crit_edge.thread

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.split ], [ 0, %.lr.ph ]
  %.016 = phi double [ %19, %.lr.ph.split ], [ 0.000000e+00, %.lr.ph ]
  %14 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %15 = load double, ptr %14, align 8, !tbaa !7
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = call noundef ptr @_ZNK7RNArrayIP7R2PointEixEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %16)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @_ZmlRK7R2Pointd(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %17, double noundef %15)
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  %19 = fadd double %.016, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph.split, label %._crit_edge, !llvm.loop !5

23:                                               ; preds = %._crit_edge
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointdVEd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef %.0.lcssa)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %3, %23, %._crit_edge
  ret void
}

declare void @_ZN7R2PointC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1

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

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

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

declare void @_ZmlRK7R2Pointd(ptr dead_on_unwind writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(16), double noundef) local_unnamed_addr #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7R2PointdVEd(ptr noundef nonnull align 8 dereferenceable(16), double noundef) local_unnamed_addr #1

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


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass