; LLVM IR from jgaeddert/liquid-dsp :: src/filter/src (filter_crcf)

; 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.firfarrow_crcf_s = type { ptr, i32, float, float, i32, float, ptr, float, ptr }

; 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
define dso_local i32 @firfarrow_crcf_freqresponse(ptr noundef %0, float noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca { float, float }, align 4
  %9 = alloca { float, float }, align 4
  %10 = alloca { float, float }, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %12 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  store float 0.000000e+00, ptr %11, align 4
  store float 0.000000e+00, ptr %12, align 4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %55, %3
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.firfarrow_crcf_s, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %19, label %58

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.firfarrow_crcf_s, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !9
  %27 = load float, ptr %5, align 4, !tbaa !9
  %28 = fpext float %27 to double
  %29 = fmul double 0.000000e+00, %28
  %30 = fmul double 0x401921FB54442D18, %28
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = uitofp i32 %31 to double
  %33 = fmul double %29, %32
  %34 = fmul double %30, %32
  %35 = fptrunc double %33 to float
  %36 = fptrunc double %34 to float
  %37 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 0
  %38 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 1
  store float %35, ptr %37, align 4
  store float %36, ptr %38, align 4
  %39 = load <2 x float>, ptr %9, align 4
  %40 = call <2 x float> @cexpf(<2 x float> noundef %39) #3
  store <2 x float> %40, ptr %10, align 4
  %41 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %42 = load float, ptr %41, align 4
  %43 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  %44 = load float, ptr %43, align 4
  %45 = fmul float %26, %42
  %46 = fmul float %26, %44
  %47 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %48 = load float, ptr %47, align 4
  %49 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  %50 = load float, ptr %49, align 4
  %51 = fadd float %48, %45
  %52 = fadd float %50, %46
  %53 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %54 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  store float %51, ptr %53, align 4
  store float %52, ptr %54, align 4
  br label %55

55:                                               ; preds = %19
  %56 = load i32, ptr %7, align 4, !tbaa !11
  %57 = add i32 %56, 1
  store i32 %57, ptr %7, align 4, !tbaa !11
  br label %13, !llvm.loop !16

58:                                               ; preds = %13
  %59 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %60 = load float, ptr %59, align 4
  %61 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  %62 = load float, ptr %61, align 4
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds { float, float }, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds { float, float }, ptr %63, i32 0, i32 1
  store float %60, ptr %64, align 4
  store float %62, ptr %65, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

; Function Attrs: nounwind
declare <2 x float> @cexpf(<2 x float> noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { nounwind "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 #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 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"firfarrow_crcf_s", !6, i64 0, !12, i64 8, !10, i64 12, !10, i64 16, !12, i64 20, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local noundef i32 @firfarrow_crcf_freqresponse(ptr nocapture noundef readonly %0, float noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = fpext float %1 to double
  %7 = insertelement <2 x double> poison, double %6, i64 0
  %8 = shufflevector <2 x double> %7, <2 x double> poison, <2 x i32> zeroinitializer
  %9 = fmul <2 x double> %8, <double 0.000000e+00, double 0x401921FB54442D18>
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %11 = phi <2 x float> [ zeroinitializer, %.lr.ph ], [ %25, %10 ]
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  %13 = getelementptr inbounds float, ptr %12, i64 %indvars.iv
  %14 = load float, ptr %13, align 4, !tbaa !13
  %15 = trunc nuw i64 %indvars.iv to i32
  %16 = uitofp i32 %15 to double
  %17 = insertelement <2 x double> poison, double %16, i64 0
  %18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
  %19 = fmul <2 x double> %9, %18
  %20 = fptrunc <2 x double> %19 to <2 x float>
  %21 = tail call <2 x float> @cexpf(<2 x float> noundef %20) #2
  %22 = insertelement <2 x float> poison, float %14, i64 0
  %23 = shufflevector <2 x float> %22, <2 x float> poison, <2 x i32> zeroinitializer
  %24 = fmul <2 x float> %23, %21
  %25 = fadd <2 x float> %11, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %4, align 8, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = icmp ult i64 %indvars.iv.next, %27
  br i1 %28, label %10, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %10, %3
  %29 = phi <2 x float> [ zeroinitializer, %3 ], [ %25, %10 ]
  store <2 x float> %29, ptr %2, align 4
  ret i32 0
}

; Function Attrs: nounwind
declare <2 x float> @cexpf(<2 x float> noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { nounwind "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 = { 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, !10, i64 8}
!6 = !{!"firfarrow_crcf_s", !7, i64 0, !10, i64 8, !11, i64 12, !11, i64 16, !10, i64 20, !11, i64 24, !7, i64 32, !11, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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