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

; 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.firdespm_s = type { i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double, ptr, i32, ptr, 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 @firdespm_is_search_complete(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.firdespm_s, ptr %9, i32 0, i32 21
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0x3F50624DE0000000, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !13
  store i32 0, ptr %4, align 4, !tbaa !14
  br label %15

15:                                               ; preds = %55, %14
  %16 = load i32, ptr %4, align 4, !tbaa !14
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.firdespm_s, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = add i32 %19, 1
  %21 = icmp ult i32 %16, %20
  br i1 %21, label %22, label %58

22:                                               ; preds = %15
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.firdespm_s, ptr %23, i32 0, i32 15
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.firdespm_s, ptr %26, i32 0, i32 20
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load i32, ptr %4, align 4, !tbaa !14
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %25, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = call double @llvm.fabs.f64(double %35)
  store double %36, ptr %6, align 8, !tbaa !13
  %37 = load i32, ptr %4, align 4, !tbaa !14
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %43, label %39

39:                                               ; preds = %22
  %40 = load double, ptr %6, align 8, !tbaa !13
  %41 = load double, ptr %7, align 8, !tbaa !13
  %42 = fcmp olt double %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %39, %22
  %44 = load double, ptr %6, align 8, !tbaa !13
  store double %44, ptr %7, align 8, !tbaa !13
  br label %45

45:                                               ; preds = %43, %39
  %46 = load i32, ptr %4, align 4, !tbaa !14
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %52, label %48

48:                                               ; preds = %45
  %49 = load double, ptr %6, align 8, !tbaa !13
  %50 = load double, ptr %8, align 8, !tbaa !13
  %51 = fcmp ogt double %49, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %48, %45
  %53 = load double, ptr %6, align 8, !tbaa !13
  store double %53, ptr %8, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %52, %48
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %4, align 4, !tbaa !14
  %57 = add i32 %56, 1
  store i32 %57, ptr %4, align 4, !tbaa !14
  br label %15, !llvm.loop !18

58:                                               ; preds = %15
  %59 = load double, ptr %8, align 8, !tbaa !13
  %60 = load double, ptr %7, align 8, !tbaa !13
  %61 = fsub double %59, %60
  %62 = load double, ptr %8, align 8, !tbaa !13
  %63 = fdiv double %61, %62
  %64 = load double, ptr %5, align 8, !tbaa !13
  %65 = fcmp olt double %63, %64
  %66 = zext i1 %65 to i64
  %67 = select i1 %65, i32 1, i32 0
  store i32 %67, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %68

68:                                               ; preds = %58, %13
  %69 = load i32, ptr %2, align 4
  ret i32 %69
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(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, !11, i64 136}
!10 = !{!"firdespm_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !12, i64 120, !6, i64 128, !11, i64 136, !6, i64 144, !6, i64 152}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 12}
!16 = !{!10, !6, i64 88}
!17 = !{!10, !6, i64 128}
!18 = distinct !{!18, !19}
!19 = !{!"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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @firdespm_is_search_complete(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 136
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %46, label %.preheader

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = add i32 %6, 1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds double, ptr %9, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !16
  %16 = tail call double @llvm.fabs.f64(double %15)
  %exitcond.peel.not = icmp eq i32 %6, 0
  br i1 %exitcond.peel.not, label %._crit_edge, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %.lr.ph
  %wide.trip.count = zext i32 %7 to i64
  %17 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %17, 1
  %18 = icmp eq i32 %7, 2
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.peel.next.preheader.new

.peel.next.preheader.new:                         ; preds = %.peel.next.preheader
  %unroll_iter = and i64 %17, -2
  %invariant.gep = getelementptr inbounds i8, ptr %11, i64 4
  br label %.peel.next

.peel.next:                                       ; preds = %.peel.next, %.peel.next.preheader.new
  %indvars.iv = phi i64 [ 1, %.peel.next.preheader.new ], [ %indvars.iv.next.1, %.peel.next ]
  %.026 = phi double [ %16, %.peel.next.preheader.new ], [ %.1.1, %.peel.next ]
  %.01925 = phi double [ %16, %.peel.next.preheader.new ], [ %.120.1, %.peel.next ]
  %niter = phi i64 [ 0, %.peel.next.preheader.new ], [ %niter.next.1, %.peel.next ]
  %19 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %9, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !16
  %24 = tail call double @llvm.fabs.f64(double %23)
  %25 = fcmp olt double %24, %.01925
  %.120 = select i1 %25, double %24, double %.01925
  %26 = fcmp ogt double %24, %.026
  %.1 = select i1 %26, double %24, double %.026
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv
  %27 = load i32, ptr %gep, align 4, !tbaa !15
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %9, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = tail call double @llvm.fabs.f64(double %30)
  %32 = fcmp olt double %31, %.120
  %.120.1 = select i1 %32, double %31, double %.120
  %33 = fcmp ogt double %31, %.1
  %.1.1 = select i1 %33, double %31, double %.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.peel.next, !llvm.loop !17

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.peel.next, %.peel.next.preheader
  %.120.lcssa.ph = phi double [ poison, %.peel.next.preheader ], [ %.120.1, %.peel.next ]
  %.1.lcssa.ph = phi double [ poison, %.peel.next.preheader ], [ %.1.1, %.peel.next ]
  %indvars.iv.unr = phi i64 [ 1, %.peel.next.preheader ], [ %indvars.iv.next.1, %.peel.next ]
  %.026.unr = phi double [ %16, %.peel.next.preheader ], [ %.1.1, %.peel.next ]
  %.01925.unr = phi double [ %16, %.peel.next.preheader ], [ %.120.1, %.peel.next ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.peel.next.epil

.peel.next.epil:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %34 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv.unr
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %9, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !16
  %39 = tail call double @llvm.fabs.f64(double %38)
  %40 = fcmp olt double %39, %.01925.unr
  %.120.epil = select i1 %40, double %39, double %.01925.unr
  %41 = fcmp ogt double %39, %.026.unr
  %.1.epil = select i1 %41, double %39, double %.026.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.peel.next.epil, %._crit_edge.loopexit.unr-lcssa, %.lr.ph, %.preheader
  %.019.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %16, %.lr.ph ], [ %.120.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.120.epil, %.peel.next.epil ]
  %.0.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %16, %.lr.ph ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %.peel.next.epil ]
  %42 = fsub double %.0.lcssa, %.019.lcssa
  %43 = fdiv double %42, %.0.lcssa
  %44 = fcmp olt double %43, 0x3F50624DE0000000
  %45 = zext i1 %44 to i32
  br label %46

46:                                               ; preds = %1, %._crit_edge
  %.021 = phi i32 [ %45, %._crit_edge ], [ 1, %1 ]
  ret i32 %.021
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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, !7, i64 136}
!6 = !{!"firdespm_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !11, i64 120, !10, i64 128, !7, i64 136, !10, i64 144, !10, i64 152}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !10, i64 88}
!14 = !{!6, !10, i64 128}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18, !19}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.peeled.count", i32 1}


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