; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Polyline.ll (ZNK10R3Polyline8CentroidEv)

; 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] }
%class.R3Polyline = type { %class.R3Curve, ptr, ptr, ptr, i32, %class.R3Box }
%class.R3Curve = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10R3Polyline8CentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(96) %1) unnamed_addr #3 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 double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = 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 %11

11:                                               ; preds = %51, %2
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = getelementptr inbounds %class.R3Polyline, ptr %10, i32 0, i32 4
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %54

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !11
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  %21 = load i32, ptr %7, align 4, !tbaa !11
  %22 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %10, i32 noundef %21)
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = sub nsw i32 %23, 1
  %25 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %10, i32 noundef %24)
  %26 = fsub double %22, %25
  %27 = load double, ptr %8, align 8, !tbaa !9
  %28 = fadd double %27, %26
  store double %28, ptr %8, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %20, %17
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = getelementptr inbounds %class.R3Polyline, ptr %10, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = sub nsw i32 %32, 1
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %29
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = add nsw i32 %36, 1
  %38 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %10, i32 noundef %37)
  %39 = load i32, ptr %7, align 4, !tbaa !11
  %40 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %10, i32 noundef %39)
  %41 = fsub double %38, %40
  %42 = load double, ptr %8, align 8, !tbaa !9
  %43 = fadd double %42, %41
  store double %43, ptr %8, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %35, %29
  %45 = getelementptr inbounds %class.R3Polyline, ptr %10, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %class.R3Point, ptr %46, i64 %48
  %50 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %49)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %51

51:                                               ; preds = %44
  %52 = load i32, ptr %7, align 4, !tbaa !11
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !11
  br label %11, !llvm.loop !21

54:                                               ; preds = %16
  %55 = load double, ptr %5, align 8, !tbaa !9
  %56 = fcmp oeq double %55, 0.000000e+00
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  store i32 1, ptr %9, align 4
  br label %60

58:                                               ; preds = %54
  %59 = 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 %59)
  store i32 1, ptr %9, align 4
  br label %60

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!14, !12, i64 32}
!14 = !{!"_ZTS10R3Polyline", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !17, i64 40}
!15 = !{!"_ZTS7R3Curve", !16, i64 0}
!16 = !{!"_ZTS7R3Shape"}
!17 = !{!"_ZTS5R3Box", !18, i64 0, !19, i64 8, !19, i64 32}
!18 = !{!"_ZTS7R3Solid", !16, i64 0}
!19 = !{!"_ZTS7R3Point", !7, i64 0}
!20 = !{!14, !6, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10R3Polyline8CentroidEv(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(96) %1) unnamed_addr #3 align 2 {
  %3 = 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)
  %4 = getelementptr inbounds i8, ptr %1, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %._crit_edge

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %.not = icmp eq i32 %5, 1
  br i1 %.not, label %12, label %9

9:                                                ; preds = %7
  %10 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 1)
  %11 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef 0)
  br label %12

12:                                               ; preds = %9, %7
  %13 = load ptr, ptr %8, align 8, !tbaa !16
  %14 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %13)
  %15 = load i32, ptr %4, align 8, !tbaa !5
  %16 = icmp sgt i32 %15, 1
  br i1 %16, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %12, %._crit_edge18
  %indvars.iv = phi i64 [ %25, %._crit_edge18 ], [ 1, %12 ]
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  %18 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef %17)
  %19 = trunc i64 %indvars.iv to i32
  %20 = add i32 %19, -1
  %21 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef %20)
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  %22 = add nsw i32 %.pre, -1
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv, %23
  %25 = add nuw nsw i64 %indvars.iv, 1
  br i1 %24, label %26, label %._crit_edge18

26:                                               ; preds = %.peel.next
  %27 = trunc nuw nsw i64 %25 to i32
  %28 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef %27)
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  %30 = call noundef double @_ZNK10R3Polyline15VertexParameterEi(ptr noundef nonnull align 8 dereferenceable(96) %1, i32 noundef %29)
  br label %._crit_edge18

._crit_edge18:                                    ; preds = %.peel.next, %26
  %31 = load ptr, ptr %8, align 8, !tbaa !16
  %32 = getelementptr inbounds %class.R3Point, ptr %31, i64 %indvars.iv
  %33 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointpLERKS_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %32)
  %34 = load i32, ptr %4, align 8, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %25, %35
  br i1 %36, label %.peel.next, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %._crit_edge18, %12, %2
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

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 #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !12, i64 32}
!6 = !{!"_ZTS10R3Polyline", !7, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !12, i64 32, !13, i64 40}
!7 = !{!"_ZTS7R3Curve", !8, i64 0}
!8 = !{!"_ZTS7R3Shape"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS5R3Box", !14, i64 0, !15, i64 8, !15, i64 32}
!14 = !{!"_ZTS7R3Solid", !8, i64 0}
!15 = !{!"_ZTS7R3Point", !10, i64 0}
!16 = !{!6, !9, i64 8}
!17 = distinct !{!17, !18, !19}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass