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

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

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

8:                                                ; preds = %42, %3
  %9 = load i32, ptr %7, align 4, !tbaa !9
  %10 = add i32 %9, 1
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i32 @qnsearch_step(ptr noundef %11)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.qnsearch_s, ptr %13, i32 0, i32 13
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.qnsearch_s, ptr %16, i32 0, i32 15
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.qnsearch_s, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.qnsearch_s, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = call float %15(ptr noundef %18, ptr noundef %21, i32 noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.qnsearch_s, ptr %26, i32 0, i32 14
  store float %25, ptr %27, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %8
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.qnsearch_s, ptr %29, i32 0, i32 14
  %31 = load float, ptr %30, align 8, !tbaa !18
  %32 = load float, ptr %6, align 4, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.qnsearch_s, ptr %33, i32 0, i32 16
  %35 = load i32, ptr %34, align 8, !tbaa !19
  %36 = call i32 @optim_threshold_switch(float noundef %31, float noundef %32, i32 noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %28
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp ult i32 %39, %40
  br label %42

42:                                               ; preds = %38, %28
  %43 = phi i1 [ false, %28 ], [ %41, %38 ]
  br i1 %43, label %8, label %44, !llvm.loop !20

44:                                               ; preds = %42
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.qnsearch_s, ptr %45, i32 0, i32 14
  %47 = load float, ptr %46, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret float %47
}

declare i32 @optim_threshold_switch(float noundef, float noundef, i32 noundef) #2

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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 88}
!14 = !{!"qnsearch_s", !6, i64 0, !10, 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, !10, i64 112}
!15 = !{!14, !6, i64 104}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !10, i64 8}
!18 = !{!14, !12, i64 96}
!19 = !{!14, !10, i64 112}
!20 = distinct !{!20, !21}
!21 = !{!"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 i32 @qnsearch_step(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @qnsearch_execute(ptr noundef %0, i32 noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 88
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  br label %9

9:                                                ; preds = %9, %3
  %.0 = phi i32 [ 0, %3 ], [ %10, %9 ]
  %10 = add nuw i32 %.0, 1
  %11 = tail call i32 @qnsearch_step(ptr noundef %0)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !12
  %14 = load ptr, ptr %0, align 8, !tbaa !13
  %15 = load i32, ptr %6, align 8, !tbaa !14
  %16 = tail call float %12(ptr noundef %13, ptr noundef %14, i32 noundef %15) #2
  store float %16, ptr %7, align 8, !tbaa !15
  %17 = load i32, ptr %8, align 8, !tbaa !16
  %18 = tail call i32 @optim_threshold_switch(float noundef %16, float noundef %2, i32 noundef %17) #2
  %19 = icmp ne i32 %18, 0
  %20 = icmp ult i32 %10, %1
  %21 = select i1 %19, i1 %20, i1 false
  br i1 %21, label %9, label %22, !llvm.loop !17

22:                                               ; preds = %9
  %23 = load float, ptr %7, align 8, !tbaa !15
  ret float %23
}

declare i32 @optim_threshold_switch(float noundef, float noundef, i32 noundef) local_unnamed_addr #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 = { "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, !7, i64 88}
!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, !7, i64 104}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !11, i64 96}
!16 = !{!6, !10, i64 112}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,SROAPass,SimplifyCFGPass,TailCallElimPass