; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @iirfilt_rrrf_reset(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %4, i32 0, i32 6
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %28

8:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %9

9:                                                ; preds = %24, %8
  %10 = load i32, ptr %3, align 4, !tbaa !13
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %11, i32 0, i32 10
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %15, label %27

15:                                               ; preds = %9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %16, i32 0, i32 9
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i32 @iirfiltsos_rrrf_reset(ptr noundef %22)
  br label %24

24:                                               ; preds = %15
  %25 = load i32, ptr %3, align 4, !tbaa !13
  %26 = add i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !13
  br label %9, !llvm.loop !16

27:                                               ; preds = %9
  br label %46

28:                                               ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %42, %28
  %30 = load i32, ptr %3, align 4, !tbaa !13
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !18
  %34 = icmp ult i32 %30, %33
  br i1 %34, label %35, label %45

35:                                               ; preds = %29
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.iirfilt_rrrf_s, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = load i32, ptr %3, align 4, !tbaa !13
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  store float 0.000000e+00, ptr %41, align 4, !tbaa !20
  br label %42

42:                                               ; preds = %35
  %43 = load i32, ptr %3, align 4, !tbaa !13
  %44 = add i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !13
  br label %29, !llvm.loop !21

45:                                               ; preds = %29
  br label %46

46:                                               ; preds = %45, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 0
}

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

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 = { 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 36}
!10 = !{!"iirfilt_rrrf_s", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !12, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 64}
!15 = !{!10, !6, i64 56}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 24}
!19 = !{!10, !6, i64 16}
!20 = !{!12, !12, i64 0}
!21 = distinct !{!21, !17}


; 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
define dso_local noundef i32 @iirfilt_rrrf_reset(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.preheader, label %.preheader10

.preheader10:                                     ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader10
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = zext i32 %6 to i64
  %10 = shl nuw nsw i64 %9, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %8, i8 0, i64 %10, i1 false), !tbaa !14
  br label %.loopexit

.preheader:                                       ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %.not15 = icmp eq i32 %12, 0
  br i1 %.not15, label %.loopexit, label %.lr.ph14

.lr.ph14:                                         ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  br label %14

14:                                               ; preds = %.lr.ph14, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph14 ], [ %indvars.iv.next, %14 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !16
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = tail call i32 @iirfiltsos_rrrf_reset(ptr noundef %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr %11, align 8, !tbaa !15
  %20 = zext i32 %19 to i64
  %21 = icmp ult i64 %indvars.iv.next, %20
  br i1 %21, label %14, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %14, %.lr.ph, %.preheader10, %.preheader
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 nounwind willreturn memory(argmem: write) }

!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 36}
!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, !10, i64 24}
!13 = !{!6, !7, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!6, !10, i64 64}
!16 = !{!6, !7, i64 56}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass