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

@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [45 x i8], align 1

declare ptr @liquid_error_config_fl(ptr noundef, i32 noundef, ptr 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @firfilt_crcf_create_firdespm(i32 noundef %0, float noundef %1, float noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = call ptr @llvm.stacksave.p0()
  store ptr %15, ptr %8, align 8
  %16 = alloca float, i64 %14, align 16
  store i64 %14, ptr %9, align 8
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load float, ptr %6, align 4, !tbaa !9
  %19 = load float, ptr %7, align 4, !tbaa !9
  %20 = call i32 @firdespm_lowpass(i32 noundef %17, float noundef %18, float noundef %19, float noundef 0.000000e+00, ptr noundef %16)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %3
  %23 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str.38, i32 noundef 166, ptr noundef @.str.42, ptr noundef @.str.2)
  store ptr %23, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %49

24:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = alloca float, i64 %26, align 16
  store i64 %26, ptr %12, align 8
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %43, %24
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %46

32:                                               ; preds = %28
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds float, ptr %16, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = fmul float %36, 5.000000e-01
  %38 = load float, ptr %6, align 4, !tbaa !9
  %39 = fdiv float %37, %38
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds float, ptr %27, i64 %41
  store float %39, ptr %42, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %32
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = add i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !5
  br label %28, !llvm.loop !11

46:                                               ; preds = %28
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = call ptr @firfilt_crcf_create(ptr noundef %27, i32 noundef %47)
  store ptr %48, ptr %4, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %49

49:                                               ; preds = %46, %22
  %50 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %50)
  %51 = load ptr, ptr %4, align 8
  ret ptr %51
}

declare i32 @firdespm_lowpass(i32 noundef, float noundef, float noundef, float noundef, ptr noundef) #0

attributes #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 willreturn }
attributes #3 = { 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 #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.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [45 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @firfilt_crcf_create_firdespm(i32 noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #1 {
  %4 = zext i32 %0 to i64
  %5 = alloca float, i64 %4, align 16
  %6 = call i32 @firdespm_lowpass(i32 noundef %0, float noundef %1, float noundef %2, float noundef 0.000000e+00, ptr noundef nonnull %5) #2
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %9, label %7

7:                                                ; preds = %3
  %8 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str.38, i32 noundef 166, ptr noundef nonnull @.str.42, ptr noundef nonnull @.str.2) #2
  br label %22

9:                                                ; preds = %3
  %10 = alloca float, i64 %4, align 16
  %.not16 = icmp eq i32 %0, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %min.iters.check = icmp ult i32 %0, 4
  br i1 %min.iters.check, label %.lr.ph.preheader18, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %4, 4294967292
  %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 ]
  %11 = getelementptr inbounds float, ptr %5, i64 %index
  %wide.load = load <4 x float>, ptr %11, align 16, !tbaa !5
  %12 = fmul <4 x float> %wide.load, <float 5.000000e-01, float 5.000000e-01, float 5.000000e-01, float 5.000000e-01>
  %13 = fdiv <4 x float> %12, %broadcast.splat
  %14 = getelementptr inbounds float, ptr %10, i64 %index
  store <4 x float> %13, ptr %14, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %4
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader18

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

.lr.ph:                                           ; preds = %.lr.ph.preheader18, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader18 ]
  %16 = getelementptr inbounds float, ptr %5, i64 %indvars.iv
  %17 = load float, ptr %16, align 4, !tbaa !5
  %18 = fmul float %17, 5.000000e-01
  %19 = fdiv float %18, %1
  %20 = getelementptr inbounds float, ptr %10, i64 %indvars.iv
  store float %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %9
  %21 = call ptr @firfilt_crcf_create(ptr noundef nonnull %10, i32 noundef %0)
  br label %22

22:                                               ; preds = %._crit_edge, %7
  %.0 = phi ptr [ %8, %7 ], [ %21, %._crit_edge ]
  ret ptr %.0
}

declare i32 @firdespm_lowpass(i32 noundef, float noundef, float noundef, float noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass