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

; 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.R3MeshProperty = type { ptr, [1024 x i8], i32, ptr, double, double, double, double, double, double }

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK14R3MeshProperty17StandardDeviationEv(ptr noundef nonnull align 8 dereferenceable(1096) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  %10 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 5
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fcmp oeq double %11, -1.000000e+00
  br i1 %12, label %13, label %67

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr %9, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.R3MeshProperty, ptr %14, i32 0, i32 5
  store double 0.000000e+00, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %66

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store double 0.000000e+00, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %20 = call noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096) %9)
  store double %20, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %51, %19
  %22 = load i32, ptr %7, align 4, !tbaa !14
  %23 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %21
  %28 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = load i32, ptr %7, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = fcmp oeq double %33, -1.000000e+00
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  br label %51

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %37 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load i32, ptr %7, align 4, !tbaa !14
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !15
  %43 = load double, ptr %6, align 8, !tbaa !15
  %44 = fsub double %42, %43
  store double %44, ptr %8, align 8, !tbaa !15
  %45 = load double, ptr %8, align 8, !tbaa !15
  %46 = load double, ptr %8, align 8, !tbaa !15
  %47 = load double, ptr %5, align 8, !tbaa !15
  %48 = call double @llvm.fmuladd.f64(double %45, double %46, double %47)
  store double %48, ptr %5, align 8, !tbaa !15
  %49 = load i32, ptr %4, align 4, !tbaa !14
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %51

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

54:                                               ; preds = %26
  %55 = load i32, ptr %4, align 4, !tbaa !14
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %65

57:                                               ; preds = %54
  %58 = load double, ptr %5, align 8, !tbaa !15
  %59 = load i32, ptr %4, align 4, !tbaa !14
  %60 = sitofp i32 %59 to double
  %61 = fdiv double %58, %60
  %62 = call double @sqrt(double noundef %61) #4
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.R3MeshProperty, ptr %63, i32 0, i32 5
  store double %62, ptr %64, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %66

66:                                               ; preds = %65, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %67

67:                                               ; preds = %66, %1
  %68 = getelementptr inbounds %struct.R3MeshProperty, ptr %9, i32 0, i32 5
  %69 = load double, ptr %68, align 8, !tbaa !9
  ret double %69
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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, !12, i64 1056}
!10 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !11, i64 1032, !6, i64 1040, !12, i64 1048, !12, i64 1056, !12, i64 1064, !12, i64 1072, !12, i64 1080, !12, i64 1088}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !11, i64 1032}
!14 = !{!11, !11, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 1040}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK14R3MeshProperty17StandardDeviationEv(ptr noundef nonnull align 8 dereferenceable(1096) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 1056
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = fcmp oeq double %3, -1.000000e+00
  br i1 %4, label %5, label %39

5:                                                ; preds = %1
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 1032
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %39

9:                                                ; preds = %5
  %10 = tail call noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  %11 = load i32, ptr %6, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge._crit_edge

.lr.ph:                                           ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 1040
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %15 = icmp eq i32 %11, 1
  br i1 %15, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %22

._crit_edge.unr-lcssa:                            ; preds = %22, %.lr.ph
  %.116.lcssa.ph = phi double [ poison, %.lr.ph ], [ %.116.1, %22 ]
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %.1.1, %22 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %22 ]
  %.020.unr = phi i32 [ 0, %.lr.ph ], [ %.1.1, %22 ]
  %.01518.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %.116.1, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %16 = getelementptr inbounds double, ptr %14, i64 %indvars.iv.unr
  %17 = load double, ptr %16, align 8, !tbaa !14
  %18 = fcmp une double %17, -1.000000e+00
  %19 = fsub double %17, %10
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %.01518.unr)
  %.116.epil = select i1 %18, double %20, double %.01518.unr
  %21 = zext i1 %18 to i32
  %.1.epil = add nuw nsw i32 %.020.unr, %21
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.116.lcssa = phi double [ %.116.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.116.epil, %._crit_edge.epilog-lcssa ]
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.1.epil, %._crit_edge.epilog-lcssa ]
  %.not = icmp eq i32 %.1.lcssa, 0
  br i1 %.not, label %._crit_edge._crit_edge, label %35

._crit_edge._crit_edge:                           ; preds = %9, %._crit_edge
  %.pre = load double, ptr %2, align 8, !tbaa !5
  br label %39

22:                                               ; preds = %22, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %22 ]
  %.020 = phi i32 [ 0, %.lr.ph.new ], [ %.1.1, %22 ]
  %.01518 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %.116.1, %22 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %22 ]
  %23 = getelementptr inbounds double, ptr %14, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = fcmp une double %24, -1.000000e+00
  %26 = fsub double %24, %10
  %27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %.01518)
  %.116 = select i1 %25, double %27, double %.01518
  %28 = zext i1 %25 to i32
  %.1 = add nuw nsw i32 %.020, %28
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = getelementptr inbounds double, ptr %14, i64 %indvars.iv.next
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = fcmp une double %30, -1.000000e+00
  %32 = fsub double %30, %10
  %33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %.116)
  %.116.1 = select i1 %31, double %33, double %.116
  %34 = zext i1 %31 to i32
  %.1.1 = add nuw nsw i32 %.1, %34
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %22, !llvm.loop !15

35:                                               ; preds = %._crit_edge
  %36 = uitofp nneg i32 %.1.lcssa to double
  %37 = fdiv double %.116.lcssa, %36
  %38 = tail call double @sqrt(double noundef %37) #3
  store double %38, ptr %2, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %._crit_edge._crit_edge, %5, %35, %1
  %40 = phi double [ %.pre, %._crit_edge._crit_edge ], [ 0.000000e+00, %5 ], [ %38, %35 ], [ %3, %1 ]
  ret double %40
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(write) "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 }

!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, !11, i64 1056}
!6 = !{!"_ZTS14R3MeshProperty", !7, i64 0, !8, i64 8, !10, i64 1032, !7, i64 1040, !11, i64 1048, !11, i64 1056, !11, i64 1064, !11, i64 1072, !11, i64 1080, !11, i64 1088}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 1032}
!13 = !{!6, !7, i64 1040}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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