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

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

@_ZL9rms_count = external hidden global i32, align 4
@_ZL7rms_sum = external hidden global float, align 4
@_ZL3rms = external hidden global float, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z23CalculateRootMeanSquaref(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 @_ZL9rms_count, align 4, !tbaa !9
  %6 = icmp ult i32 %5, 360
  br i1 %6, label %7, label %14

7:                                                ; preds = %1
  %8 = load float, ptr %2, align 4, !tbaa !5
  %9 = load float, ptr %2, align 4, !tbaa !5
  %10 = load float, ptr @_ZL7rms_sum, align 4, !tbaa !5
  %11 = call float @llvm.fmuladd.f32(float %8, float %9, float %10)
  store float %11, ptr @_ZL7rms_sum, align 4, !tbaa !5
  %12 = load i32, ptr @_ZL9rms_count, align 4, !tbaa !9
  %13 = add i32 %12, 1
  store i32 %13, ptr @_ZL9rms_count, align 4, !tbaa !9
  br label %18

14:                                               ; preds = %1
  %15 = load float, ptr @_ZL7rms_sum, align 4, !tbaa !5
  %16 = fdiv float %15, 3.600000e+02
  %17 = call noundef float @_ZSt4sqrtf(float noundef %16)
  store float %17, ptr @_ZL3rms, align 4, !tbaa !5
  store i32 0, ptr @_ZL9rms_count, align 4, !tbaa !9
  store float 0.000000e+00, ptr @_ZL7rms_sum, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %14, %7
  %19 = load float, ptr @_ZL3rms, align 4, !tbaa !5
  %20 = fmul float %19, 1.000000e+03
  ret float %20
}

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

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

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

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

@_ZL9rms_count = external hidden local_unnamed_addr global i32, align 4
@_ZL7rms_sum = external hidden local_unnamed_addr global float, align 4
@_ZL3rms = external hidden local_unnamed_addr global float, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z23CalculateRootMeanSquaref(float noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @_ZL9rms_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 @_ZL7rms_sum, align 4, !tbaa !9
  %7 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %6)
  %8 = add nuw nsw i32 %2, 1
  %.pre = load float, ptr @_ZL3rms, align 4, !tbaa !9
  br label %13

9:                                                ; preds = %1
  %10 = load float, ptr @_ZL7rms_sum, align 4, !tbaa !9
  %11 = fdiv float %10, 3.600000e+02
  %12 = tail call noundef float @_ZSt4sqrtf(float noundef %11)
  store float %12, ptr @_ZL3rms, align 4, !tbaa !9
  br label %13

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

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

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

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

!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,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass