; LLVM IR from GCY/wxECGAnalyzer :: src/MAC/adaptive_algorithm.ll (Z31CalculateCoefficientOfVariationf)

; 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"

@_ZL4mean = external hidden global float, align 4
@_ZL8cv_count = external hidden global i32, align 4
@_ZL2sd = external hidden global float, align 4
@_ZL2cv = external hidden global float, align 4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z31CalculateCoefficientOfVariationf(float noundef %0) #2 {
  %2 = alloca float, align 4
  store float %0, ptr %2, align 4, !tbaa !5
  %3 = load float, ptr %2, align 4, !tbaa !5
  %4 = fdiv float %3, 1.000000e+03
  store float %4, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @_ZL8cv_count, align 4, !tbaa !9
  %6 = icmp ult i32 %5, 360
  br i1 %6, label %7, label %18

7:                                                ; preds = %1
  %8 = load float, ptr %2, align 4, !tbaa !5
  %9 = load float, ptr @_ZL4mean, align 4, !tbaa !5
  %10 = fsub float %8, %9
  %11 = load float, ptr %2, align 4, !tbaa !5
  %12 = load float, ptr @_ZL4mean, align 4, !tbaa !5
  %13 = fsub float %11, %12
  %14 = load float, ptr @_ZL2sd, align 4, !tbaa !5
  %15 = call float @llvm.fmuladd.f32(float %10, float %13, float %14)
  store float %15, ptr @_ZL2sd, align 4, !tbaa !5
  %16 = load i32, ptr @_ZL8cv_count, align 4, !tbaa !9
  %17 = add i32 %16, 1
  store i32 %17, ptr @_ZL8cv_count, align 4, !tbaa !9
  br label %26

18:                                               ; preds = %1
  %19 = load float, ptr @_ZL2sd, align 4, !tbaa !5
  %20 = fdiv float %19, 3.590000e+02
  %21 = call noundef float @_ZSt4sqrtf(float noundef %20)
  store float %21, ptr @_ZL2sd, align 4, !tbaa !5
  %22 = load float, ptr @_ZL2sd, align 4, !tbaa !5
  %23 = load float, ptr @_ZL4mean, align 4, !tbaa !5
  %24 = fdiv float %22, %23
  %25 = fmul float %24, 1.000000e+02
  store float %25, ptr @_ZL2cv, align 4, !tbaa !5
  store i32 0, ptr @_ZL8cv_count, align 4, !tbaa !9
  store float 0.000000e+00, ptr @_ZL2sd, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %18, %7
  %27 = load float, ptr @_ZL2cv, align 4, !tbaa !5
  ret float %27
}

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

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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"

@_ZL4mean = external hidden local_unnamed_addr global float, align 4
@_ZL8cv_count = external hidden local_unnamed_addr global i32, align 4
@_ZL2sd = external hidden local_unnamed_addr global float, align 4
@_ZL2cv = external hidden local_unnamed_addr global float, align 4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z31CalculateCoefficientOfVariationf(float noundef %0) local_unnamed_addr #2 {
  %2 = load i32, ptr @_ZL8cv_count, align 4, !tbaa !5
  %3 = icmp ult i32 %2, 360
  br i1 %3, label %4, label %11

4:                                                ; preds = %1
  %5 = fdiv float %0, 1.000000e+03
  %6 = load float, ptr @_ZL4mean, align 4, !tbaa !9
  %7 = fsub float %5, %6
  %8 = load float, ptr @_ZL2sd, align 4, !tbaa !9
  %9 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %8)
  %10 = add nuw nsw i32 %2, 1
  %.pre = load float, ptr @_ZL2cv, align 4, !tbaa !9
  br label %18

11:                                               ; preds = %1
  %12 = load float, ptr @_ZL2sd, align 4, !tbaa !9
  %13 = fdiv float %12, 3.590000e+02
  %14 = tail call noundef float @_ZSt4sqrtf(float noundef %13)
  %15 = load float, ptr @_ZL4mean, align 4, !tbaa !9
  %16 = fdiv float %14, %15
  %17 = fmul float %16, 1.000000e+02
  store float %17, ptr @_ZL2cv, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %11, %4
  %19 = phi float [ %.pre, %4 ], [ %17, %11 ]
  %.sink3 = phi float [ %9, %4 ], [ 0.000000e+00, %11 ]
  %.sink = phi i32 [ %10, %4 ], [ 0, %11 ]
  store float %.sink3, ptr @_ZL2sd, align 4
  store i32 %.sink, ptr @_ZL8cv_count, align 4
  ret float %19
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass