; LLVM IR from GCY/wxECGAnalyzer :: embedded/stm32f407 - 360Hz/src/stm32f4/algorithm (adaptive_algorithm)

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

@mean = external hidden global float, align 4
@cv_count = external hidden global i32, align 4
@sd = external hidden global float, align 4
@cv = 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: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local float @CalculateCoefficientOfVariation(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 @cv_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 @mean, align 4, !tbaa !5
  %10 = fsub float %8, %9
  %11 = load float, ptr %2, align 4, !tbaa !5
  %12 = load float, ptr @mean, align 4, !tbaa !5
  %13 = fsub float %11, %12
  %14 = load float, ptr @sd, align 4, !tbaa !5
  %15 = call float @llvm.fmuladd.f32(float %10, float %13, float %14)
  store float %15, ptr @sd, align 4, !tbaa !5
  %16 = load i32, ptr @cv_count, align 4, !tbaa !9
  %17 = add i32 %16, 1
  store i32 %17, ptr @cv_count, align 4, !tbaa !9
  br label %28

18:                                               ; preds = %1
  %19 = load float, ptr @sd, align 4, !tbaa !5
  %20 = fdiv float %19, 3.590000e+02
  %21 = fpext float %20 to double
  %22 = call double @sqrt(double noundef %21) #3
  %23 = fptrunc double %22 to float
  store float %23, ptr @sd, align 4, !tbaa !5
  %24 = load float, ptr @sd, align 4, !tbaa !5
  %25 = load float, ptr @mean, align 4, !tbaa !5
  %26 = fdiv float %24, %25
  %27 = fmul float %26, 1.000000e+02
  store float %27, ptr @cv, align 4, !tbaa !5
  store i32 0, ptr @cv_count, align 4, !tbaa !9
  store float 0.000000e+00, ptr @sd, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %18, %7
  %29 = load float, ptr @cv, align 4, !tbaa !5
  ret float %29
}

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

!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/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"

@mean = external hidden local_unnamed_addr global float, align 4
@cv_count = external hidden local_unnamed_addr global i32, align 4
@sd = external hidden local_unnamed_addr global float, align 4
@cv = 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: mustprogress nofree nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: write) uwtable
define dso_local float @CalculateCoefficientOfVariation(float noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @cv_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 @mean, align 4, !tbaa !9
  %7 = fsub float %5, %6
  %8 = load float, ptr @sd, 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 @cv, align 4, !tbaa !9
  br label %17

11:                                               ; preds = %1
  %12 = load float, ptr @sd, align 4, !tbaa !9
  %13 = fdiv float %12, 3.590000e+02
  %sqrtf = tail call float @sqrtf(float noundef %13) #2
  %14 = load float, ptr @mean, align 4, !tbaa !9
  %15 = fdiv float %sqrtf, %14
  %16 = fmul float %15, 1.000000e+02
  store float %16, ptr @cv, align 4, !tbaa !9
  br label %17

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

declare float @sqrtf(float) local_unnamed_addr

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

!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/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