; LLVM IR from jgaeddert/liquid-dsp :: src/equalization/src (equalizer_rrrf)

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

@.str = external hidden unnamed_addr constant [89 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @eqlms_rrrf_create(ptr noundef, i32 noundef) #0

; 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

declare ptr @liquid_error_config_fl(ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @eqlms_rrrf_create_lowpass(i32 noundef %0, float noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str, i32 noundef 136, ptr noundef @.str.6, ptr noundef @.str.2)
  store ptr %13, ptr %3, align 8
  br label %55

14:                                               ; preds = %2
  %15 = load float, ptr %5, align 4, !tbaa !9
  %16 = fcmp ole float %15, 0.000000e+00
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load float, ptr %5, align 4, !tbaa !9
  %19 = fcmp ogt float %18, 5.000000e-01
  br i1 %19, label %20, label %22

20:                                               ; preds = %17, %14
  %21 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str, i32 noundef 138, ptr noundef @.str.7, ptr noundef @.str.2)
  store ptr %21, ptr %3, align 8
  br label %55

22:                                               ; preds = %17
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = call ptr @llvm.stacksave.p0()
  store ptr %25, ptr %6, align 8
  %26 = alloca float, i64 %24, align 16
  store i64 %24, ptr %7, align 8
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load float, ptr %5, align 4, !tbaa !9
  %29 = call i32 @liquid_firdes_kaiser(i32 noundef %27, float noundef %28, float noundef 4.000000e+01, float noundef 0.000000e+00, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = alloca float, i64 %31, align 16
  store i64 %31, ptr %9, align 8
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %48, %22
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %33
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %26, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !9
  %42 = fmul float %41, 2.000000e+00
  %43 = load float, ptr %5, align 4, !tbaa !9
  %44 = fmul float %42, %43
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %32, i64 %46
  store float %44, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %37
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = add i32 %49, 1
  store i32 %50, ptr %8, align 4, !tbaa !5
  br label %33, !llvm.loop !11

51:                                               ; preds = %33
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = call ptr @eqlms_rrrf_create(ptr noundef %32, i32 noundef %52)
  store ptr %53, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %54 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %54)
  br label %55

55:                                               ; preds = %51, %20, %12
  %56 = load ptr, ptr %3, align 8
  ret ptr %56
}

declare i32 @liquid_firdes_kaiser(i32 noundef, float noundef, float noundef, float noundef, ptr noundef) #2

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 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@.str = external hidden unnamed_addr constant [89 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @eqlms_rrrf_create(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @liquid_error_config_fl(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @eqlms_rrrf_create_lowpass(i32 noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str, i32 noundef 136, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.2) #3
  br label %32

6:                                                ; preds = %2
  %7 = fcmp ole float %1, 0.000000e+00
  %8 = fcmp ogt float %1, 5.000000e-01
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %9, label %11

9:                                                ; preds = %6
  %10 = tail call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str, i32 noundef 138, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2) #3
  br label %32

11:                                               ; preds = %6
  %12 = zext i32 %0 to i64
  %13 = tail call ptr @llvm.stacksave.p0()
  %14 = alloca float, i64 %12, align 16
  %15 = call i32 @liquid_firdes_kaiser(i32 noundef %0, float noundef %1, float noundef 4.000000e+01, float noundef 0.000000e+00, ptr noundef nonnull %14) #3
  %16 = alloca float, i64 %12, align 16
  %min.iters.check = icmp ult i32 %0, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %11
  %n.vec = and i64 %12, 4294967288
  %broadcast.splatinsert = insertelement <4 x float> poison, float %1, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = getelementptr inbounds float, ptr %14, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load = load <4 x float>, ptr %17, align 16, !tbaa !5
  %wide.load21 = load <4 x float>, ptr %18, align 16, !tbaa !5
  %19 = fmul <4 x float> %wide.load, <float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00>
  %20 = fmul <4 x float> %wide.load21, <float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+00>
  %21 = fmul <4 x float> %19, %broadcast.splat
  %22 = fmul <4 x float> %20, %broadcast.splat
  %23 = getelementptr inbounds float, ptr %16, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <4 x float> %21, ptr %23, align 16, !tbaa !5
  store <4 x float> %22, ptr %24, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %12
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %11
  %indvars.iv.ph = phi i64 [ 0, %11 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %26 = getelementptr inbounds float, ptr %14, i64 %indvars.iv
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = fmul float %27, 2.000000e+00
  %29 = fmul float %28, %1
  %30 = getelementptr inbounds float, ptr %16, i64 %indvars.iv
  store float %29, ptr %30, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %12
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !13

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %31 = call ptr @eqlms_rrrf_create(ptr noundef nonnull %16, i32 noundef %0)
  call void @llvm.stackrestore.p0(ptr %13)
  br label %32

32:                                               ; preds = %.loopexit, %9, %4
  %.0 = phi ptr [ %5, %4 ], [ %10, %9 ], [ %31, %.loopexit ]
  ret ptr %.0
}

declare i32 @liquid_firdes_kaiser(i32 noundef, float noundef, float noundef, float noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass