; LLVM IR from jgaeddert/liquid-dsp :: src/filter/src (filter_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.iirfilt_rrrf_s = type { ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i32, float }

; 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

declare i32 @dotprod_rrrf_execute(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @iirfilt_rrrf_execute_norm(ptr noundef %0, float noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = sub i32 %11, 1
  store i32 %12, ptr %7, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %31, %3
  %14 = load i32, ptr %7, align 4, !tbaa !14
  %15 = icmp ugt i32 %14, 0
  br i1 %15, label %16, label %34

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = load i32, ptr %7, align 4, !tbaa !14
  %21 = sub i32 %20, 1
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %19, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %7, align 4, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  store float %24, ptr %30, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %16
  %32 = load i32, ptr %7, align 4, !tbaa !14
  %33 = add i32 %32, -1
  store i32 %33, ptr %7, align 4, !tbaa !14
  br label %13, !llvm.loop !16

34:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %35, i32 0, i32 8
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds float, ptr %40, i64 1
  %42 = call i32 @dotprod_rrrf_execute(ptr noundef %37, ptr noundef %41, ptr noundef %8)
  %43 = load float, ptr %5, align 4, !tbaa !9
  %44 = load float, ptr %8, align 4, !tbaa !9
  %45 = fsub float %43, %44
  store float %45, ptr %8, align 4, !tbaa !9
  %46 = load float, ptr %8, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds float, ptr %49, i64 0
  store float %46, ptr %50, align 4, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = call i32 @dotprod_rrrf_execute(ptr noundef %53, ptr noundef %56, ptr noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %59, i32 0, i32 11
  %61 = load float, ptr %60, align 4, !tbaa !20
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load float, ptr %62, align 4, !tbaa !9
  %64 = fmul float %63, %61
  store float %64, ptr %62, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 24}
!12 = !{!"iirfilt_rrrf_s", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !10, i64 68}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !6, i64 48}
!19 = !{!12, !6, i64 40}
!20 = !{!12, !10, i64 68}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare i32 @dotprod_rrrf_execute(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @iirfilt_rrrf_execute_norm(ptr nocapture noundef readonly %0, float noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca float, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.015 = add i32 %6, -1
  %.not16 = icmp eq i32 %.015, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 16
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !12
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = zext i32 %.015 to i64
  %min.iters.check = icmp ult i32 %.015, 44
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph
  %8 = add i32 %6, -2
  %9 = shl nuw nsw i64 %7, 2
  %scevgep = getelementptr i8, ptr %.pre, i64 %9
  %10 = zext i32 %8 to i64
  %mul20.neg = mul nsw i64 %10, -4
  %11 = getelementptr i8, ptr %scevgep, i64 %mul20.neg
  %12 = icmp ugt ptr %11, %scevgep
  %13 = zext i32 %8 to i64
  %14 = shl nuw nsw i64 %13, 2
  %scevgep23 = getelementptr i8, ptr %.pre, i64 %14
  %15 = zext i32 %8 to i64
  %mul24.neg = mul nsw i64 %15, -4
  %16 = getelementptr i8, ptr %scevgep23, i64 %mul24.neg
  %17 = icmp ugt ptr %16, %scevgep23
  %18 = or i1 %12, %17
  br i1 %18, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %19 = add i32 %6, -2
  %20 = zext i32 %19 to i64
  %21 = sub nsw i64 %20, %7
  %22 = and i64 %21, 4611686018427387896
  %diff.check = icmp eq i64 %22, 0
  br i1 %diff.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %7, 4294967288
  %ind.end = and i64 %7, 7
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end27 = sub i32 %6, %.cast
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %7, %index
  %.cast29 = trunc i64 %index to i32
  %offset.idx30 = sub i32 %6, %.cast29
  %23 = add i32 %offset.idx30, -2
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %.pre, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 -12
  %27 = getelementptr inbounds i8, ptr %25, i64 -28
  %wide.load = load <4 x float>, ptr %26, align 4, !tbaa !13
  %wide.load31 = load <4 x float>, ptr %27, align 4, !tbaa !13
  %28 = getelementptr inbounds float, ptr %.pre, i64 %offset.idx
  %29 = getelementptr inbounds i8, ptr %28, i64 -12
  %30 = getelementptr inbounds i8, ptr %28, i64 -28
  store <4 x float> %wide.load, ptr %29, align 4, !tbaa !13
  store <4 x float> %wide.load31, ptr %30, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !14

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ %7, %vector.memcheck ], [ %7, %vector.scevcheck ], [ %7, %.lr.ph ], [ %ind.end, %middle.block ]
  %.0.in17.ph = phi i32 [ %6, %vector.memcheck ], [ %6, %vector.scevcheck ], [ %6, %.lr.ph ], [ %ind.end27, %middle.block ]
  %32 = trunc nuw i64 %indvars.iv.ph to i32
  %33 = add i32 %32, -1
  %xtraiter = and i32 %32, 3
  %lcmp.mod.not = icmp eq i32 %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 ]
  %.0.in17.prol = phi i32 [ %39, %scalar.ph.prol ], [ %.0.in17.ph, %scalar.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %34 = add i32 %.0.in17.prol, -2
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds float, ptr %.pre, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !13
  %38 = getelementptr inbounds float, ptr %.pre, i64 %indvars.iv.prol
  store float %37, ptr %38, align 4, !tbaa !13
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %39 = trunc nuw i64 %indvars.iv.prol to i32
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !18

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 ]
  %.0.in17.unr = phi i32 [ %.0.in17.ph, %scalar.ph.preheader ], [ %39, %scalar.ph.prol ]
  %40 = icmp ult i32 %33, 3
  br i1 %40, label %._crit_edge, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %.pre, i64 -4
  %invariant.gep35 = getelementptr i8, ptr %.pre, i64 -8
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %scalar.ph.preheader.new ], [ %indvars.iv.next.3, %scalar.ph ]
  %.0.in17 = phi i32 [ %.0.in17.unr, %scalar.ph.preheader.new ], [ %60, %scalar.ph ]
  %41 = add i32 %.0.in17, -2
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %.pre, i64 %42
  %44 = load float, ptr %43, align 4, !tbaa !13
  %45 = getelementptr inbounds float, ptr %.pre, i64 %indvars.iv
  store float %44, ptr %45, align 4, !tbaa !13
  %46 = add i64 %indvars.iv, 4294967294
  %47 = and i64 %46, 4294967295
  %48 = getelementptr inbounds float, ptr %.pre, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !13
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  store float %49, ptr %gep, align 4, !tbaa !13
  %50 = add i64 %indvars.iv, 4294967293
  %51 = and i64 %50, 4294967295
  %52 = getelementptr inbounds float, ptr %.pre, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !13
  %gep36 = getelementptr float, ptr %invariant.gep35, i64 %indvars.iv
  store float %53, ptr %gep36, align 4, !tbaa !13
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %54 = add i64 %indvars.iv, 4294967292
  %55 = and i64 %54, 4294967295
  %56 = getelementptr inbounds float, ptr %.pre, i64 %55
  %57 = load float, ptr %56, align 4, !tbaa !13
  %58 = getelementptr inbounds float, ptr %.pre, i64 %indvars.iv.next.2
  store float %57, ptr %58, align 4, !tbaa !13
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %59 = and i64 %indvars.iv.next.3, 4294967295
  %.not.3 = icmp eq i64 %59, 0
  %60 = trunc nuw i64 %indvars.iv.next.2 to i32
  br i1 %.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %61 = getelementptr inbounds i8, ptr %0, i64 48
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = getelementptr inbounds i8, ptr %0, i64 16
  %64 = getelementptr inbounds i8, ptr %.pre, i64 4
  %65 = call i32 @dotprod_rrrf_execute(ptr noundef %62, ptr noundef nonnull %64, ptr noundef nonnull %4) #3
  %66 = load float, ptr %4, align 4, !tbaa !13
  %67 = fsub float %1, %66
  store float %67, ptr %4, align 4, !tbaa !13
  %68 = load ptr, ptr %63, align 8, !tbaa !12
  store float %67, ptr %68, align 4, !tbaa !13
  %69 = getelementptr inbounds i8, ptr %0, i64 40
  %70 = load ptr, ptr %69, align 8, !tbaa !22
  %71 = call i32 @dotprod_rrrf_execute(ptr noundef %70, ptr noundef nonnull %68, ptr noundef %2) #3
  %72 = getelementptr inbounds i8, ptr %0, i64 68
  %73 = load float, ptr %72, align 4, !tbaa !23
  %74 = load float, ptr %2, align 4, !tbaa !13
  %75 = fmul float %73, %74
  store float %75, ptr %2, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i32 0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 24}
!6 = !{!"iirfilt_rrrf_s", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64, !11, i64 68}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}
!21 = !{!6, !7, i64 48}
!22 = !{!6, !7, i64 40}
!23 = !{!6, !11, i64 68}


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