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

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

@LowPassFilter.y1 = external hidden global i32, align 4
@LowPassFilter.y2 = external hidden global i32, align 4
@LowPassFilter.x = external hidden global [26 x i32], align 16
@LowPassFilter.n = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @LowPassFilter(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %6 = add nsw i32 %5, 13
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %7
  store i32 %4, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %10
  store i32 %4, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr @LowPassFilter.y1, align 4, !tbaa !5
  %13 = shl i32 %12, 1
  %14 = load i32, ptr @LowPassFilter.y2, align 4, !tbaa !5
  %15 = sub nsw i32 %13, %14
  %16 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %15, %19
  %21 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %22 = add nsw i32 %21, 6
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = shl i32 %25, 1
  %27 = sub nsw i32 %20, %26
  %28 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %29 = add nsw i32 %28, 12
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %27, %32
  store i32 %33, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr @LowPassFilter.y1, align 4, !tbaa !5
  store i32 %34, ptr @LowPassFilter.y2, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %35, ptr @LowPassFilter.y1, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = ashr i32 %36, 5
  store i32 %37, ptr %3, align 4, !tbaa !5
  %38 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @LowPassFilter.n, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %1
  store i32 12, ptr @LowPassFilter.n, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %41, %1
  %43 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %43
}

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


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

@LowPassFilter.y1 = external hidden local_unnamed_addr global i32, align 4
@LowPassFilter.y2 = external hidden local_unnamed_addr global i32, align 4
@LowPassFilter.x = external hidden local_unnamed_addr global [26 x i32], align 16
@LowPassFilter.n = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 -67108864, 67108864) i32 @LowPassFilter(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @LowPassFilter.n, align 4, !tbaa !5
  %3 = add nsw i32 %2, 13
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %4
  store i32 %0, ptr %5, align 4, !tbaa !5
  %6 = sext i32 %2 to i64
  %7 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %6
  store i32 %0, ptr %7, align 4, !tbaa !5
  %8 = load i32, ptr @LowPassFilter.y1, align 4, !tbaa !5
  %9 = load i32, ptr @LowPassFilter.y2, align 4, !tbaa !5
  %10 = add nsw i32 %2, 6
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %2, 12
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [26 x i32], ptr @LowPassFilter.x, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %reass.add = sub i32 %8, %13
  %reass.mul = shl i32 %reass.add, 1
  %18 = sub i32 %0, %9
  %19 = add i32 %18, %17
  %20 = add i32 %19, %reass.mul
  store i32 %8, ptr @LowPassFilter.y2, align 4, !tbaa !5
  store i32 %20, ptr @LowPassFilter.y1, align 4, !tbaa !5
  %21 = ashr i32 %20, 5
  %22 = add nsw i32 %2, -1
  %23 = icmp slt i32 %2, 1
  %spec.store.select = select i1 %23, i32 12, i32 %22
  store i32 %spec.store.select, ptr @LowPassFilter.n, align 4
  ret i32 %21
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass