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

; 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: mustprogress nounwind uwtable
declare dso_local void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14R3MeshProperty9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(1096) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = call noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096) %7)
  store double %8, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = call noundef double @_ZNK14R3MeshProperty17StandardDeviationEv(ptr noundef nonnull align 8 dereferenceable(1096) %7)
  store double %9, ptr %4, align 8, !tbaa !9
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fcmp oeq double %10, 0.000000e+00
  br i1 %11, label %12, label %38

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %34, %12
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %37

19:                                               ; preds = %13
  %20 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load i32, ptr %5, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fcmp oeq double %25, -1.000000e+00
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  br label %34

28:                                               ; preds = %19
  %29 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load i32, ptr %5, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  store double 0.000000e+00, ptr %33, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %28, %27
  %35 = load i32, ptr %5, align 4, !tbaa !11
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !11
  br label %13, !llvm.loop !16

37:                                               ; preds = %18
  br label %74

38:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %70, %38
  %40 = load i32, ptr %6, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = icmp slt i32 %40, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %73

45:                                               ; preds = %39
  %46 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load i32, ptr %6, align 4, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fcmp oeq double %51, -1.000000e+00
  br i1 %52, label %53, label %54

53:                                               ; preds = %45
  br label %70

54:                                               ; preds = %45
  %55 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load i32, ptr %6, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load double, ptr %3, align 8, !tbaa !9
  %62 = fsub double %60, %61
  %63 = load double, ptr %4, align 8, !tbaa !9
  %64 = fdiv double %62, %63
  %65 = getelementptr inbounds %struct.R3MeshProperty, ptr %7, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load i32, ptr %6, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds double, ptr %66, i64 %68
  store double %64, ptr %69, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %54, %53
  %71 = load i32, ptr %6, align 4, !tbaa !11
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !11
  br label %39, !llvm.loop !18

73:                                               ; preds = %44
  br label %74

74:                                               ; preds = %73, %37
  call void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096) %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 }

!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 1032}
!14 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !12, i64 1032, !6, i64 1040, !10, i64 1048, !10, i64 1056, !10, i64 1064, !10, i64 1072, !10, i64 1080, !10, i64 1088}
!15 = !{!14, !6, i64 1040}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 nounwind uwtable
declare dso_local void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14R3MeshProperty9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(1096) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef double @_ZNK14R3MeshProperty4MeanEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  %3 = tail call noundef double @_ZNK14R3MeshProperty17StandardDeviationEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  %4 = fcmp oeq double %3, 0.000000e+00
  %5 = getelementptr inbounds i8, ptr %0, i64 1032
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %4, label %.preheader, label %.preheader15

.preheader15:                                     ; preds = %1
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader15
  %8 = getelementptr inbounds i8, ptr %0, i64 1040
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %wide.trip.count = zext nneg i32 %6 to i64
  %min.iters.check = icmp eq i32 %6, 1
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483646
  br label %vector.body

vector.body:                                      ; preds = %pred.store.continue30, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue30 ]
  %10 = getelementptr inbounds double, ptr %9, i64 %index
  %wide.load = load <2 x double>, ptr %10, align 8, !tbaa !13
  %11 = fcmp une <2 x double> %wide.load, <double -1.000000e+00, double -1.000000e+00>
  %12 = extractelement <2 x i1> %11, i64 0
  br i1 %12, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %13 = extractelement <2 x double> %wide.load, i64 0
  %14 = fsub double %13, %2
  %15 = getelementptr inbounds double, ptr %9, i64 %index
  %16 = fdiv double %14, %3
  store double %16, ptr %15, align 8, !tbaa !13
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %17 = extractelement <2 x i1> %11, i64 1
  br i1 %17, label %pred.store.if29, label %pred.store.continue30

pred.store.if29:                                  ; preds = %pred.store.continue
  %18 = or disjoint i64 %index, 1
  %19 = extractelement <2 x double> %wide.load, i64 1
  %20 = fsub double %19, %2
  %21 = getelementptr inbounds double, ptr %9, i64 %18
  %22 = fdiv double %20, %3
  store double %22, ptr %21, align 8, !tbaa !13
  br label %pred.store.continue30

pred.store.continue30:                            ; preds = %pred.store.if29, %pred.store.continue
  %index.next = add nuw i64 %index, 2
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %pred.store.continue30
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

.preheader:                                       ; preds = %1
  br i1 %7, label %.lr.ph19, label %.loopexit

.lr.ph19:                                         ; preds = %.preheader
  %24 = getelementptr inbounds i8, ptr %0, i64 1040
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %wide.trip.count25 = zext nneg i32 %6 to i64
  %min.iters.check33 = icmp ult i32 %6, 4
  br i1 %min.iters.check33, label %scalar.ph32.preheader, label %vector.ph34

vector.ph34:                                      ; preds = %.lr.ph19
  %n.vec36 = and i64 %wide.trip.count25, 2147483644
  br label %vector.body38

vector.body38:                                    ; preds = %pred.store.continue49, %vector.ph34
  %index39 = phi i64 [ 0, %vector.ph34 ], [ %index.next50, %pred.store.continue49 ]
  %26 = or disjoint i64 %index39, 2
  %27 = getelementptr inbounds double, ptr %25, i64 %index39
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load40 = load <2 x double>, ptr %27, align 8, !tbaa !13
  %wide.load41 = load <2 x double>, ptr %28, align 8, !tbaa !13
  %29 = fcmp une <2 x double> %wide.load40, <double -1.000000e+00, double -1.000000e+00>
  %30 = fcmp une <2 x double> %wide.load41, <double -1.000000e+00, double -1.000000e+00>
  %31 = extractelement <2 x i1> %29, i64 0
  br i1 %31, label %pred.store.if42, label %pred.store.continue43

pred.store.if42:                                  ; preds = %vector.body38
  %32 = getelementptr inbounds double, ptr %25, i64 %index39
  store double 0.000000e+00, ptr %32, align 8, !tbaa !13
  br label %pred.store.continue43

pred.store.continue43:                            ; preds = %pred.store.if42, %vector.body38
  %33 = extractelement <2 x i1> %29, i64 1
  br i1 %33, label %pred.store.if44, label %pred.store.continue45

pred.store.if44:                                  ; preds = %pred.store.continue43
  %34 = or disjoint i64 %index39, 1
  %35 = getelementptr inbounds double, ptr %25, i64 %34
  store double 0.000000e+00, ptr %35, align 8, !tbaa !13
  br label %pred.store.continue45

pred.store.continue45:                            ; preds = %pred.store.if44, %pred.store.continue43
  %36 = extractelement <2 x i1> %30, i64 0
  br i1 %36, label %pred.store.if46, label %pred.store.continue47

pred.store.if46:                                  ; preds = %pred.store.continue45
  %37 = getelementptr inbounds double, ptr %25, i64 %26
  store double 0.000000e+00, ptr %37, align 8, !tbaa !13
  br label %pred.store.continue47

pred.store.continue47:                            ; preds = %pred.store.if46, %pred.store.continue45
  %38 = extractelement <2 x i1> %30, i64 1
  br i1 %38, label %pred.store.if48, label %pred.store.continue49

pred.store.if48:                                  ; preds = %pred.store.continue47
  %39 = or disjoint i64 %index39, 3
  %40 = getelementptr inbounds double, ptr %25, i64 %39
  store double 0.000000e+00, ptr %40, align 8, !tbaa !13
  br label %pred.store.continue49

pred.store.continue49:                            ; preds = %pred.store.if48, %pred.store.continue47
  %index.next50 = add nuw i64 %index39, 4
  %41 = icmp eq i64 %index.next50, %n.vec36
  br i1 %41, label %middle.block31, label %vector.body38, !llvm.loop !18

middle.block31:                                   ; preds = %pred.store.continue49
  %cmp.n51 = icmp eq i64 %n.vec36, %wide.trip.count25
  br i1 %cmp.n51, label %.loopexit, label %scalar.ph32.preheader

scalar.ph32.preheader:                            ; preds = %middle.block31, %.lr.ph19
  %indvars.iv22.ph = phi i64 [ 0, %.lr.ph19 ], [ %n.vec36, %middle.block31 ]
  br label %scalar.ph32

scalar.ph32:                                      ; preds = %scalar.ph32.preheader, %46
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %46 ], [ %indvars.iv22.ph, %scalar.ph32.preheader ]
  %42 = getelementptr inbounds double, ptr %25, i64 %indvars.iv22
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = fcmp oeq double %43, -1.000000e+00
  br i1 %44, label %46, label %45

45:                                               ; preds = %scalar.ph32
  store double 0.000000e+00, ptr %42, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %scalar.ph32, %45
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond26.not = icmp eq i64 %indvars.iv.next23, %wide.trip.count25
  br i1 %exitcond26.not, label %.loopexit, label %scalar.ph32, !llvm.loop !19

scalar.ph:                                        ; preds = %scalar.ph.preheader, %53
  %indvars.iv = phi i64 [ %indvars.iv.next, %53 ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %47 = getelementptr inbounds double, ptr %9, i64 %indvars.iv
  %48 = load double, ptr %47, align 8, !tbaa !13
  %49 = fcmp oeq double %48, -1.000000e+00
  br i1 %49, label %53, label %50

50:                                               ; preds = %scalar.ph
  %51 = fsub double %48, %2
  %52 = fdiv double %51, %3
  store double %52, ptr %47, align 8, !tbaa !13
  br label %53

53:                                               ; preds = %scalar.ph, %50
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !20

.loopexit:                                        ; preds = %53, %46, %middle.block, %middle.block31, %.preheader15, %.preheader
  tail call void @_ZN14R3MeshProperty15ResetStatisticsEv(ptr noundef nonnull align 8 dereferenceable(1096) %0)
  ret void
}

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

!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, !10, i64 1032}
!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, !7, i64 1040}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16, !17}
!19 = distinct !{!19, !15, !17, !16}
!20 = distinct !{!20, !15, !17, !16}


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