; LLVM IR from BigdogManLuo/DSPLibrary :: DSPTools/ButterWorth_Filter (filter)

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

%struct.ButterQueue = type { [3 x float], i32, float, float }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @InButterQueue(ptr noundef, float noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @ButterWorthFilter(ptr noundef %0, float noundef %1, ptr noundef %2, double noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load float, ptr %6, align 4, !tbaa !9
  call void @InButterQueue(ptr noundef %11, float noundef %12)
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %13, i64 3
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = fdiv double 1.000000e+00, %15
  store double %16, ptr %10, align 8, !tbaa !11
  %17 = load double, ptr %10, align 8, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %18, i64 0
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ButterQueue, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ButterQueue, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [3 x float], ptr %22, i64 0, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !9
  %29 = fpext float %28 to double
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 1
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ButterQueue, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ButterQueue, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = add nsw i32 %37, 2
  %39 = srem i32 %38, 3
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [3 x float], ptr %34, i64 0, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !9
  %43 = fpext float %42 to double
  %44 = fmul double %32, %43
  %45 = call double @llvm.fmuladd.f64(double %20, double %29, double %44)
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %46, i64 2
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ButterQueue, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ButterQueue, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = add nsw i32 %53, 1
  %55 = srem i32 %54, 3
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [3 x float], ptr %50, i64 0, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !9
  %59 = fpext float %58 to double
  %60 = call double @llvm.fmuladd.f64(double %48, double %59, double %45)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds double, ptr %61, i64 4
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ButterQueue, ptr %64, i32 0, i32 2
  %66 = load float, ptr %65, align 4, !tbaa !16
  %67 = fpext float %66 to double
  %68 = fneg double %63
  %69 = call double @llvm.fmuladd.f64(double %68, double %67, double %60)
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds double, ptr %70, i64 5
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ButterQueue, ptr %73, i32 0, i32 3
  %75 = load float, ptr %74, align 4, !tbaa !17
  %76 = fpext float %75 to double
  %77 = fneg double %72
  %78 = call double @llvm.fmuladd.f64(double %77, double %76, double %69)
  %79 = fmul double %17, %78
  store double %79, ptr %9, align 8, !tbaa !11
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ButterQueue, ptr %80, i32 0, i32 2
  %82 = load float, ptr %81, align 4, !tbaa !16
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ButterQueue, ptr %83, i32 0, i32 3
  store float %82, ptr %84, align 4, !tbaa !17
  %85 = load double, ptr %9, align 8, !tbaa !11
  %86 = fptrunc double %85 to float
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.ButterQueue, ptr %87, i32 0, i32 2
  store float %86, ptr %88, align 4, !tbaa !16
  %89 = load double, ptr %8, align 8, !tbaa !11
  %90 = load double, ptr %9, align 8, !tbaa !11
  %91 = fmul double %89, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret double %91
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !15, i64 12}
!14 = !{!"", !7, i64 0, !15, i64 12, !10, i64 16, !10, i64 20}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !10, i64 20}


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

; Function Attrs: nounwind uwtable
declare dso_local void @InButterQueue(ptr noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @ButterWorthFilter(ptr noundef %0, float noundef %1, ptr nocapture noundef readonly %2, double noundef %3) local_unnamed_addr #0 {
  tail call void @InButterQueue(ptr noundef %0, float noundef %1)
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fdiv double 1.000000e+00, %6
  %8 = load double, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [3 x float], ptr %0, i64 0, i64 %11
  %13 = load float, ptr %12, align 4, !tbaa !13
  %14 = fpext float %13 to double
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = add nsw i32 %10, 2
  %18 = srem i32 %17, 3
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [3 x float], ptr %0, i64 0, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !13
  %22 = fpext float %21 to double
  %23 = fmul double %16, %22
  %24 = tail call double @llvm.fmuladd.f64(double %8, double %14, double %23)
  %25 = getelementptr inbounds i8, ptr %2, i64 16
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = add nsw i32 %10, 1
  %28 = srem i32 %27, 3
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [3 x float], ptr %0, i64 0, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !13
  %32 = fpext float %31 to double
  %33 = tail call double @llvm.fmuladd.f64(double %26, double %32, double %24)
  %34 = getelementptr inbounds i8, ptr %2, i64 32
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %0, i64 16
  %37 = load float, ptr %36, align 4, !tbaa !14
  %38 = fpext float %37 to double
  %39 = fneg double %35
  %40 = tail call double @llvm.fmuladd.f64(double %39, double %38, double %33)
  %41 = getelementptr inbounds i8, ptr %2, i64 40
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %0, i64 20
  %44 = load float, ptr %43, align 4, !tbaa !15
  %45 = fpext float %44 to double
  %46 = fneg double %42
  %47 = tail call double @llvm.fmuladd.f64(double %46, double %45, double %40)
  %48 = fmul double %7, %47
  store float %37, ptr %43, align 4, !tbaa !15
  %49 = fptrunc double %48 to float
  store float %49, ptr %36, align 4, !tbaa !14
  %50 = fmul double %48, %3
  ret double %50
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 12}
!10 = !{!"", !7, i64 0, !11, i64 12, !12, i64 16, !12, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !12, i64 20}


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