; LLVM IR from jgaeddert/liquid-dsp :: src/optim/src (qnsearch)

; 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.qnsearch_s = type { ptr, i32, float, float, float, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, float, ptr, i32 }

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

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

11:                                               ; preds = %41, %1
  %12 = load i32, ptr %3, align 4, !tbaa !14
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.qnsearch_s, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = icmp ult i32 %12, %15
  br i1 %16, label %17, label %44

17:                                               ; preds = %11
  store i32 0, ptr %4, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %37, %17
  %19 = load i32, ptr %4, align 4, !tbaa !14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.qnsearch_s, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = icmp ult i32 %19, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %18
  %25 = load i32, ptr %3, align 4, !tbaa !14
  %26 = load i32, ptr %4, align 4, !tbaa !14
  %27 = icmp eq i32 %25, %26
  %28 = zext i1 %27 to i64
  %29 = select i1 %27, float 1.000000e+00, float 0.000000e+00
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.qnsearch_s, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %5, align 4, !tbaa !14
  %34 = add i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !14
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds float, ptr %32, i64 %35
  store float %29, ptr %36, align 4, !tbaa !17
  br label %37

37:                                               ; preds = %24
  %38 = load i32, ptr %4, align 4, !tbaa !14
  %39 = add i32 %38, 1
  store i32 %39, ptr %4, align 4, !tbaa !14
  br label %18, !llvm.loop !18

40:                                               ; preds = %18
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !14
  %43 = add i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !14
  br label %11, !llvm.loop !20

44:                                               ; preds = %11
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.qnsearch_s, ptr %45, i32 0, i32 13
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.qnsearch_s, ptr %48, i32 0, i32 15
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.qnsearch_s, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !23
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.qnsearch_s, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !15
  %57 = call float %47(ptr noundef %50, ptr noundef %53, i32 noundef %56)
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.qnsearch_s, ptr %58, i32 0, i32 14
  store float %57, ptr %59, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 0
}

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

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, !12, i64 12}
!10 = !{!"qnsearch_s", !6, i64 0, !11, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !6, i64 104, !11, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !12, i64 24}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 48}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!10, !6, i64 88}
!22 = !{!10, !6, i64 104}
!23 = !{!10, !6, i64 0}
!24 = !{!10, !12, i64 96}


; 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 @qnsearch_reset(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load float, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  store float %3, ptr %4, align 8, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !13
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %min.iters.check = icmp ult i32 %6, 8
  %9 = sub i32 0, %6
  %n.vec = and i32 %6, -8
  %cmp.n = icmp eq i32 %6, %n.vec
  %xtraiter = and i32 %6, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %.022 = phi i32 [ 0, %.preheader.lr.ph ], [ %.lcssa, %.loopexit ]
  %.01721 = phi i32 [ 0, %.preheader.lr.ph ], [ %38, %.loopexit ]
  %10 = icmp ugt i32 %.022, %9
  %or.cond = select i1 %min.iters.check, i1 true, i1 %10
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %ind.end = add i32 %.022, %n.vec
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %.01721, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = add i32 %.022, %index
  %11 = icmp eq <4 x i32> %broadcast.splat, %vec.ind
  %12 = icmp eq <4 x i32> %broadcast.splat, %step.add
  %13 = select <4 x i1> %11, <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float> zeroinitializer
  %14 = select <4 x i1> %12, <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float> zeroinitializer
  %15 = zext i32 %offset.idx to i64
  %16 = getelementptr inbounds float, ptr %8, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  store <4 x float> %13, ptr %16, align 4, !tbaa !15
  store <4 x float> %14, ptr %17, align 4, !tbaa !15
  %index.next = add nuw i32 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %18 = icmp eq i32 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader
  %.120.ph = phi i32 [ %.022, %.preheader ], [ %ind.end, %middle.block ]
  %.01619.ph = phi i32 [ 0, %.preheader ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i32 %.01619.ph, 1
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %19 = icmp eq i32 %.01721, %.01619.ph
  %20 = select i1 %19, float 1.000000e+00, float 0.000000e+00
  %21 = add i32 %.120.ph, 1
  %22 = zext i32 %.120.ph to i64
  %23 = getelementptr inbounds float, ptr %8, i64 %22
  store float %20, ptr %23, align 4, !tbaa !15
  %24 = or disjoint i32 %.01619.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.lcssa27.unr = phi i32 [ poison, %scalar.ph.preheader ], [ %21, %scalar.ph.prol ]
  %.120.unr = phi i32 [ %.120.ph, %scalar.ph.preheader ], [ %21, %scalar.ph.prol ]
  %.01619.unr = phi i32 [ %.01619.ph, %scalar.ph.preheader ], [ %24, %scalar.ph.prol ]
  %25 = icmp eq i32 %6, %.neg
  br i1 %25, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.120 = phi i32 [ %34, %scalar.ph ], [ %.120.unr, %scalar.ph.prol.loopexit ]
  %.01619 = phi i32 [ %37, %scalar.ph ], [ %.01619.unr, %scalar.ph.prol.loopexit ]
  %26 = icmp eq i32 %.01721, %.01619
  %27 = select i1 %26, float 1.000000e+00, float 0.000000e+00
  %28 = add i32 %.120, 1
  %29 = zext i32 %.120 to i64
  %30 = getelementptr inbounds float, ptr %8, i64 %29
  store float %27, ptr %30, align 4, !tbaa !15
  %31 = add nuw i32 %.01619, 1
  %32 = icmp eq i32 %.01721, %31
  %33 = select i1 %32, float 1.000000e+00, float 0.000000e+00
  %34 = add i32 %.120, 2
  %35 = zext i32 %28 to i64
  %36 = getelementptr inbounds float, ptr %8, i64 %35
  store float %33, ptr %36, align 4, !tbaa !15
  %37 = add nuw i32 %.01619, 2
  %exitcond.not.1 = icmp eq i32 %37, %6
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !20

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %ind.end, %middle.block ], [ %.lcssa27.unr, %scalar.ph.prol.loopexit ], [ %34, %scalar.ph ]
  %38 = add nuw i32 %.01721, 1
  %exitcond23.not = icmp eq i32 %38, %6
  br i1 %exitcond23.not, label %._crit_edge, label %.preheader, !llvm.loop !21

._crit_edge:                                      ; preds = %.loopexit, %1
  %39 = getelementptr inbounds i8, ptr %0, i64 88
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = getelementptr inbounds i8, ptr %0, i64 104
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  %43 = load ptr, ptr %0, align 8, !tbaa !24
  %44 = tail call float %40(ptr noundef %42, ptr noundef %43, i32 noundef %6) #1
  %45 = getelementptr inbounds i8, ptr %0, i64 96
  store float %44, ptr %45, align 8, !tbaa !25
  ret i32 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 = { 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, !11, i64 12}
!6 = !{!"qnsearch_s", !7, i64 0, !10, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !11, i64 96, !7, i64 104, !10, i64 112}
!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, !11, i64 24}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 48}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !18}
!21 = distinct !{!21, !17}
!22 = !{!6, !7, i64 88}
!23 = !{!6, !7, i64 104}
!24 = !{!6, !7, i64 0}
!25 = !{!6, !11, i64 96}


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