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

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

@coefficients = external hidden constant [32 x float], align 16
@buffer = external hidden global [32 x float], align 16
@offset = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local float @FIR_filter(float noundef %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  store float %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr @coefficients, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr getelementptr inbounds (float, ptr @coefficients, i64 32), ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load i32, ptr @offset, align 4, !tbaa !11
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds float, ptr @buffer, i64 %8
  store ptr %9, ptr %5, align 8, !tbaa !9
  %10 = load float, ptr %2, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  store float %10, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store float 0.000000e+00, ptr %6, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %15, %1
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = icmp uge ptr %13, @buffer
  br i1 %14, label %15, label %24

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds float, ptr %16, i32 -1
  store ptr %17, ptr %5, align 8, !tbaa !9
  %18 = load float, ptr %16, align 4, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  %20 = getelementptr inbounds float, ptr %19, i32 1
  store ptr %20, ptr %3, align 8, !tbaa !9
  %21 = load float, ptr %19, align 4, !tbaa !5
  %22 = load float, ptr %6, align 4, !tbaa !5
  %23 = call float @llvm.fmuladd.f32(float %18, float %21, float %22)
  store float %23, ptr %6, align 4, !tbaa !5
  br label %12, !llvm.loop !13

24:                                               ; preds = %12
  store ptr getelementptr inbounds (float, ptr getelementptr inbounds (float, ptr @buffer, i64 32), i64 -1), ptr %5, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %29, %24
  %26 = load ptr, ptr %3, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = icmp ult ptr %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds float, ptr %30, i32 -1
  store ptr %31, ptr %5, align 8, !tbaa !9
  %32 = load float, ptr %30, align 4, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds float, ptr %33, i32 1
  store ptr %34, ptr %3, align 8, !tbaa !9
  %35 = load float, ptr %33, align 4, !tbaa !5
  %36 = load float, ptr %6, align 4, !tbaa !5
  %37 = call float @llvm.fmuladd.f32(float %32, float %35, float %36)
  store float %37, ptr %6, align 4, !tbaa !5
  br label %25, !llvm.loop !15

38:                                               ; preds = %25
  %39 = load i32, ptr @offset, align 4, !tbaa !11
  %40 = add i32 %39, 1
  store i32 %40, ptr @offset, align 4, !tbaa !11
  %41 = icmp uge i32 %40, 32
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  store i32 0, ptr @offset, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %42, %38
  %44 = load float, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret float %44
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@coefficients = external hidden local_unnamed_addr constant [32 x float], align 16
@buffer = external hidden global [32 x float], align 16
@offset = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local float @FIR_filter(float noundef %0) local_unnamed_addr #0 {
.lr.ph.preheader:
  %1 = load i32, ptr @offset, align 4, !tbaa !5
  %2 = zext i32 %1 to i64
  %3 = getelementptr inbounds float, ptr @buffer, i64 %2
  store float %0, ptr %3, align 4, !tbaa !9
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp ult i64 %.014.idx18, 124
  br i1 %4, label %.lr.ph25, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.020 = phi float [ %8, %.lr.ph ], [ 0.000000e+00, %.lr.ph.preheader ]
  %.01219 = phi ptr [ %5, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.014.idx18 = phi i64 [ %.014.add, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.014.ptr = getelementptr inbounds i8, ptr @coefficients, i64 %.014.idx18
  %5 = getelementptr inbounds i8, ptr %.01219, i64 -4
  %6 = load float, ptr %.01219, align 4, !tbaa !9
  %.014.add = add nuw nsw i64 %.014.idx18, 4
  %7 = load float, ptr %.014.ptr, align 4, !tbaa !9
  %8 = tail call float @llvm.fmuladd.f32(float %6, float %7, float %.020)
  %.not = icmp ult ptr %5, @buffer
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !11

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %.124 = phi float [ %12, %.lr.ph25 ], [ %8, %.preheader ]
  %.11323 = phi ptr [ %9, %.lr.ph25 ], [ getelementptr inbounds (i8, ptr @buffer, i64 124), %.preheader ]
  %.115.idx22 = phi i64 [ %.115.add, %.lr.ph25 ], [ %.014.add, %.preheader ]
  %.115.ptr = getelementptr inbounds i8, ptr @coefficients, i64 %.115.idx22
  %9 = getelementptr inbounds i8, ptr %.11323, i64 -4
  %10 = load float, ptr %.11323, align 4, !tbaa !9
  %.115.add = add nuw nsw i64 %.115.idx22, 4
  %11 = load float, ptr %.115.ptr, align 4, !tbaa !9
  %12 = tail call float @llvm.fmuladd.f32(float %10, float %11, float %.124)
  %13 = icmp ult i64 %.115.idx22, 124
  br i1 %13, label %.lr.ph25, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph25, %.preheader
  %.1.lcssa = phi float [ %8, %.preheader ], [ %12, %.lr.ph25 ]
  %14 = add i32 %1, 1
  %15 = icmp ugt i32 %14, 31
  %spec.store.select = select i1 %15, i32 0, i32 %14
  store i32 %spec.store.select, ptr @offset, align 4
  ret float %.1.lcssa
}

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

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

!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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass