; 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_count = external hidden global i32, align 4
@mean_sum = external hidden global float, align 4
@mean = external hidden global float, align 4

; Function Attrs: nounwind uwtable
define dso_local float @CalculateMean(float noundef %0) #0 {
  %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 @mean_count, align 4, !tbaa !9
  %6 = icmp ult i32 %5, 360
  br i1 %6, label %7, label %13

7:                                                ; preds = %1
  %8 = load float, ptr %2, align 4, !tbaa !5
  %9 = load float, ptr @mean_sum, align 4, !tbaa !5
  %10 = fadd float %9, %8
  store float %10, ptr @mean_sum, align 4, !tbaa !5
  %11 = load i32, ptr @mean_count, align 4, !tbaa !9
  %12 = add i32 %11, 1
  store i32 %12, ptr @mean_count, align 4, !tbaa !9
  br label %16

13:                                               ; preds = %1
  %14 = load float, ptr @mean_sum, align 4, !tbaa !5
  %15 = fdiv float %14, 3.600000e+02
  store float %15, ptr @mean, align 4, !tbaa !5
  store i32 0, ptr @mean_count, align 4, !tbaa !9
  store float 0.000000e+00, ptr @mean_sum, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %7
  %17 = load float, ptr @mean, align 4, !tbaa !5
  %18 = fmul float %17, 1.000000e+03
  ret float %18
}

attributes #0 = { 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 = !{!"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_count = external hidden local_unnamed_addr global i32, align 4
@mean_sum = external hidden local_unnamed_addr global float, align 4
@mean = external hidden local_unnamed_addr global float, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local float @CalculateMean(float noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @mean_count, align 4, !tbaa !5
  %3 = icmp ult i32 %2, 360
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = fdiv float %0, 1.000000e+03
  %6 = load float, ptr @mean_sum, align 4, !tbaa !9
  %7 = fadd float %5, %6
  %8 = add nuw nsw i32 %2, 1
  %.pre = load float, ptr @mean, align 4, !tbaa !9
  br label %12

9:                                                ; preds = %1
  %10 = load float, ptr @mean_sum, align 4, !tbaa !9
  %11 = fdiv float %10, 3.600000e+02
  store float %11, ptr @mean, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %9, %4
  %13 = phi float [ %.pre, %4 ], [ %11, %9 ]
  %.sink2 = phi float [ %7, %4 ], [ 0.000000e+00, %9 ]
  %.sink = phi i32 [ %8, %4 ], [ 0, %9 ]
  store float %.sink2, ptr @mean_sum, align 4
  store i32 %.sink, ptr @mean_count, align 4
  %14 = fmul float %13, 1.000000e+03
  ret float %14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass