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

%struct.eqlms_rrrf_s = type { i32, float, ptr, ptr, ptr, i32, i32, ptr, ptr, float }

; 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: nounwind uwtable
declare dso_local i32 @eqlms_rrrf_reset(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @eqlms_rrrf_recreate(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = 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
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.eqlms_rrrf_s, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp ne i32 %11, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 @eqlms_rrrf_destroy(ptr noundef %15)
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = call ptr @eqlms_rrrf_create(ptr noundef %17, i32 noundef %18)
  store ptr %19, ptr %4, align 8
  br label %53

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %46, %20
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.eqlms_rrrf_s, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp ult i32 %22, %25
  br i1 %26, label %27, label %49

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.eqlms_rrrf_s, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sub i32 %31, %32
  %34 = sub i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds float, ptr %28, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !14
  %38 = fpext float %37 to double
  %39 = fptrunc double %38 to float
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.eqlms_rrrf_s, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %42, i64 %44
  store float %39, ptr %45, align 4, !tbaa !14
  br label %46

46:                                               ; preds = %27
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !16

49:                                               ; preds = %21
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 @eqlms_rrrf_reset(ptr noundef %50)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %52, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %53

53:                                               ; preds = %49, %14
  %54 = load ptr, ptr %4, align 8
  ret ptr %54
}

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

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 = { 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, !10, i64 0}
!12 = !{!"eqlms_rrrf_s", !10, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !13, i64 56}
!13 = !{!"float", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 8}
!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
declare dso_local ptr @eqlms_rrrf_create(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @eqlms_rrrf_recreate(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %4, %2
  br i1 %.not, label %.preheader, label %39

.preheader:                                       ; preds = %3
  %.not19 = icmp eq i32 %2, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %wide.trip.count = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 32
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 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 ]
  %7 = trunc nuw i64 %indvars.iv.prol to i32
  %8 = xor i32 %7, -1
  %9 = add i32 %8, %2
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds float, ptr %1, i64 %10
  %12 = load float, ptr %11, align 4, !tbaa !13
  %13 = getelementptr inbounds float, ptr %6, i64 %indvars.iv.prol
  store float %12, ptr %13, align 4, !tbaa !13
  %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 !14

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 ]
  %14 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %15 = icmp ugt i64 %14, -4
  br i1 %15, label %._crit_edge, label %scalar.ph

vector.scevcheck:                                 ; preds = %.lr.ph
  %16 = add nsw i64 %wide.trip.count, -1
  %17 = add i32 %2, -1
  %18 = trunc i64 %16 to i32
  %19 = icmp ult i32 %17, %18
  %20 = icmp ugt i64 %16, 4294967295
  %21 = or i1 %19, %20
  br i1 %21, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %22 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep = getelementptr i8, ptr %6, i64 %22
  %23 = add i32 %2, -1
  %24 = zext i32 %23 to i64
  %25 = shl nuw nsw i64 %24, 2
  %26 = add nuw nsw i64 %25, 4
  %27 = sub nsw i64 %26, %22
  %scevgep21 = getelementptr i8, ptr %1, i64 %27
  %28 = getelementptr i8, ptr %1, i64 %25
  %scevgep22 = getelementptr i8, ptr %28, i64 4
  %bound0 = icmp ult ptr %6, %scevgep22
  %bound1 = icmp ult ptr %scevgep21, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %29 = trunc i64 %index to i32
  %30 = xor i32 %29, -1
  %31 = add i32 %30, %2
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %1, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 -12
  %35 = getelementptr inbounds i8, ptr %33, i64 -28
  %wide.load = load <4 x float>, ptr %34, align 4, !tbaa !13, !alias.scope !16
  %reverse = shufflevector <4 x float> %wide.load, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load23 = load <4 x float>, ptr %35, align 4, !tbaa !13, !alias.scope !16
  %reverse24 = shufflevector <4 x float> %wide.load23, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %36 = getelementptr inbounds float, ptr %6, i64 %index
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store <4 x float> %reverse, ptr %36, align 4, !tbaa !13, !alias.scope !19, !noalias !16
  store <4 x float> %reverse24, ptr %37, align 4, !tbaa !13, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 8
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

39:                                               ; preds = %3
  %40 = tail call i32 @eqlms_rrrf_destroy(ptr noundef nonnull %0)
  %41 = tail call ptr @eqlms_rrrf_create(ptr noundef %1, i32 noundef %2)
  br label %71

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 ]
  %42 = trunc nuw i64 %indvars.iv to i32
  %43 = xor i32 %42, -1
  %44 = add i32 %43, %2
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %1, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !13
  %48 = getelementptr inbounds float, ptr %6, i64 %indvars.iv
  store float %47, ptr %48, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %49 = trunc nuw i64 %indvars.iv.next to i32
  %50 = xor i32 %49, -1
  %51 = add i32 %50, %2
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %1, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !13
  %55 = getelementptr inbounds float, ptr %6, i64 %indvars.iv.next
  store float %54, ptr %55, align 4, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %56 = trunc nuw i64 %indvars.iv.next.1 to i32
  %57 = xor i32 %56, -1
  %58 = add i32 %57, %2
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %1, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !13
  %62 = getelementptr inbounds float, ptr %6, i64 %indvars.iv.next.1
  store float %61, ptr %62, align 4, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %63 = trunc nuw i64 %indvars.iv.next.2 to i32
  %64 = xor i32 %63, -1
  %65 = add i32 %64, %2
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds float, ptr %1, i64 %66
  %68 = load float, ptr %67, align 4, !tbaa !13
  %69 = getelementptr inbounds float, ptr %6, i64 %indvars.iv.next.2
  store float %68, ptr %69, align 4, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !25

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader
  %70 = tail call i32 @eqlms_rrrf_reset(ptr noundef nonnull %0)
  br label %71

71:                                               ; preds = %._crit_edge, %39
  %.015 = phi ptr [ %41, %39 ], [ %0, %._crit_edge ]
  ret ptr %.015
}

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

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

!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 0}
!6 = !{!"eqlms_rrrf_s", !7, i64 0, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !7, i64 36, !11, i64 40, !11, i64 48, !10, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = !{!17}
!17 = distinct !{!17, !18}
!18 = distinct !{!18, !"LVerDomain"}
!19 = !{!20}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !22, !23, !24}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.isvectorized", i32 1}
!24 = !{!"llvm.loop.unroll.runtime.disable"}
!25 = distinct !{!25, !22, !23}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass