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

; 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 [78 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [40 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #0

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

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

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

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

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

16:                                               ; preds = %3
  %17 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 798, ptr noundef @.str.24)
  store i32 0, ptr %4, align 4
  br label %76

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %9, align 8
  %22 = alloca float, i64 %20, align 16
  store i64 %20, ptr %10, align 8
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %39, %18
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %27, label %42

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sub i32 %29, %30
  %32 = sub i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %28, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !11
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds float, ptr %22, i64 %37
  store float %35, ptr %38, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %27
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !9
  br label %23, !llvm.loop !13

42:                                               ; preds = %23
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sub i32 %43, 1
  %45 = zext i32 %44 to i64
  %46 = alloca { float, float }, i64 %45, align 16
  store i64 %45, ptr %11, align 8
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = call i32 @polyf_findroots(ptr noundef %22, i32 noundef %47, ptr noundef %46)
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %70, %42
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = sub i32 %51, 1
  %53 = icmp ult i32 %50, %52
  br i1 %53, label %54, label %73

54:                                               ; preds = %49
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds { float, float }, ptr %46, i64 %56
  %58 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 0
  %59 = load float, ptr %58, align 8
  %60 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 1
  %61 = load float, ptr %60, align 4
  %62 = getelementptr inbounds { float, float }, ptr %12, i32 0, i32 0
  %63 = getelementptr inbounds { float, float }, ptr %12, i32 0, i32 1
  store float %59, ptr %62, align 4
  store float %61, ptr %63, align 4
  %64 = load <2 x float>, ptr %12, align 4
  %65 = call float @cabsf(<2 x float> noundef %64) #5
  %66 = fpext float %65 to double
  %67 = fcmp ogt double %66, 1.000000e+00
  br i1 %67, label %68, label %69

68:                                               ; preds = %54
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %74

69:                                               ; preds = %54
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = add i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !9
  br label %49, !llvm.loop !15

73:                                               ; preds = %49
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %74

74:                                               ; preds = %73, %68
  %75 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %75)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %76

76:                                               ; preds = %74, %16
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

declare i32 @polyf_findroots(ptr noundef, i32 noundef, ptr noundef) #0

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

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 }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 [78 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @iirdes_isstable(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp ult i32 %2, 2
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 798, ptr noundef nonnull @.str.24) #4
  br label %73

7:                                                ; preds = %3
  %8 = zext i32 %2 to i64
  %9 = tail call ptr @llvm.stacksave.p0()
  %10 = alloca float, i64 %8, align 16
  %min.iters.check = icmp ult i32 %2, 16
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %7
  %11 = add nsw i64 %8, -1
  %12 = add i32 %2, -1
  %13 = trunc i64 %11 to i32
  %14 = icmp ult i32 %12, %13
  %15 = icmp ugt i64 %11, 4294967295
  %16 = or i1 %14, %15
  br i1 %16, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %8, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = trunc i64 %index to i32
  %18 = xor i32 %17, -1
  %19 = add i32 %18, %2
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds float, ptr %1, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 -12
  %23 = getelementptr inbounds i8, ptr %21, i64 -28
  %wide.load = load <4 x float>, ptr %22, align 4, !tbaa !5
  %reverse = shufflevector <4 x float> %wide.load, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load30 = load <4 x float>, ptr %23, align 4, !tbaa !5
  %reverse31 = shufflevector <4 x float> %wide.load30, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %24 = getelementptr inbounds float, ptr %10, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store <4 x float> %reverse, ptr %24, align 16, !tbaa !5
  store <4 x float> %reverse31, ptr %25, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !9

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %7
  %indvars.iv.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %7 ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %8, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %27 = trunc nuw i64 %indvars.iv.prol to i32
  %28 = xor i32 %27, -1
  %29 = add i32 %28, %2
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds float, ptr %1, i64 %30
  %32 = load float, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds float, ptr %10, i64 %indvars.iv.prol
  store float %32, ptr %33, align 4, !tbaa !5
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !13

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %34 = sub nsw i64 %indvars.iv.ph, %8
  %35 = icmp ugt i64 %34, -4
  br i1 %35, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %36 = trunc nuw i64 %indvars.iv to i32
  %37 = xor i32 %36, -1
  %38 = add i32 %37, %2
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %1, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds float, ptr %10, i64 %indvars.iv
  store float %41, ptr %42, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = trunc nuw i64 %indvars.iv.next to i32
  %44 = xor i32 %43, -1
  %45 = add i32 %44, %2
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %1, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !5
  %49 = getelementptr inbounds float, ptr %10, i64 %indvars.iv.next
  store float %48, ptr %49, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %50 = trunc nuw i64 %indvars.iv.next.1 to i32
  %51 = xor i32 %50, -1
  %52 = add i32 %51, %2
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %1, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !5
  %56 = getelementptr inbounds float, ptr %10, i64 %indvars.iv.next.1
  store float %55, ptr %56, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %57 = trunc nuw i64 %indvars.iv.next.2 to i32
  %58 = xor i32 %57, -1
  %59 = add i32 %58, %2
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds float, ptr %1, i64 %60
  %62 = load float, ptr %61, align 4, !tbaa !5
  %63 = getelementptr inbounds float, ptr %10, i64 %indvars.iv.next.2
  store float %62, ptr %63, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %8
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %64 = add i32 %2, -1
  %65 = zext i32 %64 to i64
  %66 = alloca { float, float }, i64 %65, align 16
  %67 = call i32 @polyf_findroots(ptr noundef nonnull %10, i32 noundef %2, ptr noundef nonnull %66) #4
  %.not = icmp eq i32 %64, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

68:                                               ; preds = %.lr.ph
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %65
  br i1 %exitcond29.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

.lr.ph:                                           ; preds = %.loopexit, %68
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %68 ], [ 0, %.loopexit ]
  %69 = getelementptr inbounds { float, float }, ptr %66, i64 %indvars.iv25
  %70 = load <2 x float>, ptr %69, align 8
  %71 = call float @cabsf(<2 x float> noundef %70) #4
  %72 = fcmp ogt float %71, 1.000000e+00
  br i1 %72, label %._crit_edge, label %68

._crit_edge:                                      ; preds = %.lr.ph, %68, %.loopexit
  %.0 = phi i32 [ 1, %.loopexit ], [ 1, %68 ], [ 0, %.lr.ph ]
  call void @llvm.stackrestore.p0(ptr %9)
  br label %73

73:                                               ; preds = %._crit_edge, %5
  %.1 = phi i32 [ 0, %5 ], [ %.0, %._crit_edge ]
  ret i32 %.1
}

declare i32 @polyf_findroots(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { 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 #3 = { 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 #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 = !{!"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, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !10, !11}
!16 = distinct !{!16, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass