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

; 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.firfilt_crcf_s = type { ptr, i32, ptr, ptr, 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 ptr @firfilt_crcf_recreate(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp ne i32 %8, %11
  br i1 %12, label %13, label %37

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %15, i32 0, i32 1
  store i32 %14, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = mul i64 %23, 4
  %25 = call ptr @realloc(ptr noundef %19, i64 noundef %24) #5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %26, i32 0, i32 0
  store ptr %25, ptr %27, align 8, !tbaa !14
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = call ptr @windowcf_recreate(ptr noundef %30, i32 noundef %33)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %35, i32 0, i32 2
  store ptr %34, ptr %36, align 8, !tbaa !15
  br label %37

37:                                               ; preds = %13, %3
  %38 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %57, %37
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = icmp ugt i32 %40, 0
  br i1 %41, label %42, label %60

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = sub i32 %44, %45
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %43, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !16
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = sub i32 %53, 1
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %52, i64 %55
  store float %49, ptr %56, align 4, !tbaa !16
  br label %57

57:                                               ; preds = %42
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add i32 %58, -1
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %39, !llvm.loop !17

60:                                               ; preds = %39
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !11
  %70 = call ptr @dotprod_crcf_recreate(ptr noundef %63, ptr noundef %66, i32 noundef %69)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.firfilt_crcf_s, ptr %71, i32 0, i32 3
  store ptr %70, ptr %72, align 8, !tbaa !19
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %73
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

declare ptr @windowcf_recreate(ptr noundef, i32 noundef) #3

declare ptr @dotprod_crcf_recreate(ptr noundef, ptr noundef, i32 noundef) #3

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 allocsize(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 #3 = { "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 }
attributes #5 = { nounwind allocsize(1) }

!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 8}
!12 = !{!"firfilt_crcf_s", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 16}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !6, i64 24}


; 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 ptr @firfilt_crcf_recreate(ptr noundef returned %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, %2
  br i1 %.not, label %15, label %6

6:                                                ; preds = %3
  store i32 %2, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %8 = zext i32 %2 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = tail call ptr @realloc(ptr noundef %7, i64 noundef %9) #3
  store ptr %10, ptr %0, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = load i32, ptr %4, align 8, !tbaa !5
  %14 = tail call ptr @windowcf_recreate(ptr noundef %12, i32 noundef %13) #4
  store ptr %14, ptr %11, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %6, %3
  %.not2324 = icmp eq i32 %2, 0
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %.not2324, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %16 = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %17 = shl nuw nsw i64 %16, 2
  %scevgep = getelementptr i8, ptr %.pre, i64 %17
  %scevgep27 = getelementptr i8, ptr %1, i64 %17
  %bound0 = icmp ult ptr %.pre, %scevgep27
  %bound1 = icmp ugt ptr %scevgep, %1
  %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 %16, 4294967288
  %ind.end = and i64 %16, 7
  %invariant.gep = getelementptr float, ptr %.pre, i64 %16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = getelementptr inbounds float, ptr %1, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %wide.load = load <4 x float>, ptr %18, align 4, !tbaa !14, !alias.scope !15
  %wide.load28 = load <4 x float>, ptr %19, align 4, !tbaa !14, !alias.scope !15
  %20 = xor i64 %index, -1
  %gep = getelementptr float, ptr %invariant.gep, i64 %20
  %21 = getelementptr inbounds i8, ptr %gep, i64 -12
  %22 = getelementptr inbounds i8, ptr %gep, i64 -28
  %reverse = shufflevector <4 x float> %wide.load, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x float> %reverse, ptr %21, align 4, !tbaa !14, !alias.scope !18, !noalias !15
  %reverse29 = shufflevector <4 x float> %wide.load28, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x float> %reverse29, ptr %22, align 4, !tbaa !14, !alias.scope !18, !noalias !15
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !20

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ %16, %vector.memcheck ], [ %16, %.lr.ph ], [ %ind.end, %middle.block ]
  %24 = add nsw i64 %indvars.iv.ph, -1
  %xtraiter = and i64 %indvars.iv.ph, 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 [ %28, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %25 = sub nuw nsw i64 %16, %indvars.iv.prol
  %26 = getelementptr inbounds float, ptr %1, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !14
  %28 = add nsw i64 %indvars.iv.prol, -1
  %29 = getelementptr inbounds float, ptr %.pre, i64 %28
  store float %27, ptr %29, align 4, !tbaa !14
  %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 !24

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %28, %scalar.ph.prol ]
  %30 = icmp ult i64 %24, 3
  br i1 %30, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %49, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %31 = sub nuw nsw i64 %16, %indvars.iv
  %32 = getelementptr inbounds float, ptr %1, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !14
  %34 = add nsw i64 %indvars.iv, -1
  %35 = getelementptr inbounds float, ptr %.pre, i64 %34
  store float %33, ptr %35, align 4, !tbaa !14
  %36 = sub nuw nsw i64 %16, %34
  %37 = getelementptr inbounds float, ptr %1, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !14
  %39 = add nsw i64 %indvars.iv, -2
  %40 = getelementptr inbounds float, ptr %.pre, i64 %39
  store float %38, ptr %40, align 4, !tbaa !14
  %41 = sub nuw nsw i64 %16, %39
  %42 = getelementptr inbounds float, ptr %1, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !14
  %44 = add nsw i64 %indvars.iv, -3
  %45 = getelementptr inbounds float, ptr %.pre, i64 %44
  store float %43, ptr %45, align 4, !tbaa !14
  %46 = sub nuw nsw i64 %16, %44
  %47 = getelementptr inbounds float, ptr %1, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !14
  %49 = add nsw i64 %indvars.iv, -4
  %50 = getelementptr inbounds float, ptr %.pre, i64 %49
  store float %48, ptr %50, align 4, !tbaa !14
  %.not23.wide.3 = icmp eq i64 %49, 0
  br i1 %.not23.wide.3, label %._crit_edge, label %scalar.ph, !llvm.loop !26

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %15
  %51 = getelementptr inbounds i8, ptr %0, i64 24
  %52 = load ptr, ptr %51, align 8, !tbaa !27
  %53 = load i32, ptr %4, align 8, !tbaa !5
  %54 = tail call ptr @dotprod_crcf_recreate(ptr noundef %52, ptr noundef %.pre, i32 noundef %53) #4
  store ptr %54, ptr %51, align 8, !tbaa !27
  ret ptr %0
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

declare ptr @windowcf_recreate(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @dotprod_crcf_recreate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 allocsize(1) }
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, !10, i64 8}
!6 = !{!"firfilt_crcf_s", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!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 0}
!13 = !{!6, !7, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !17}
!17 = distinct !{!17, !"LVerDomain"}
!18 = !{!19}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.unroll.disable"}
!26 = distinct !{!26, !21, !22}
!27 = !{!6, !7, i64 24}


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