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

; 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.gasearch_s = type { ptr, i32, i32, float, i32, i32, ptr, ptr, ptr, float, ptr, 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 @gasearch_rank(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %110, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gasearch_s, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %13, label %113

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gasearch_s, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = sub i32 %16, 1
  store i32 %17, ptr %4, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %106, %13
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp ugt i32 %19, %20
  br i1 %21, label %22, label %109

22:                                               ; preds = %18
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gasearch_s, ptr %23, i32 0, i32 6
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %25, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !15
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gasearch_s, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sub i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds float, ptr %32, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !15
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gasearch_s, ptr %38, i32 0, i32 12
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = icmp ne i32 %40, 0
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i32
  %44 = call i32 @optim_threshold_switch(float noundef %29, float noundef %37, i32 noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %105

46:                                               ; preds = %22
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gasearch_s, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  store ptr %53, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gasearch_s, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sub i32 %57, 1
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %56, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.gasearch_s, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  store ptr %61, ptr %67, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.gasearch_s, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = sub i32 %72, 1
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds ptr, ptr %71, i64 %74
  store ptr %68, ptr %75, align 8, !tbaa !5
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.gasearch_s, ptr %76, i32 0, i32 6
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds float, ptr %78, i64 %80
  %82 = load float, ptr %81, align 4, !tbaa !15
  store float %82, ptr %5, align 4, !tbaa !15
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.gasearch_s, ptr %83, i32 0, i32 6
  %85 = load ptr, ptr %84, align 8, !tbaa !14
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = sub i32 %86, 1
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds float, ptr %85, i64 %88
  %90 = load float, ptr %89, align 4, !tbaa !15
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.gasearch_s, ptr %91, i32 0, i32 6
  %93 = load ptr, ptr %92, align 8, !tbaa !14
  %94 = load i32, ptr %4, align 4, !tbaa !9
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds float, ptr %93, i64 %95
  store float %90, ptr %96, align 4, !tbaa !15
  %97 = load float, ptr %5, align 4, !tbaa !15
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.gasearch_s, ptr %98, i32 0, i32 6
  %100 = load ptr, ptr %99, align 8, !tbaa !14
  %101 = load i32, ptr %4, align 4, !tbaa !9
  %102 = sub i32 %101, 1
  %103 = zext i32 %102 to i64
  %104 = getelementptr inbounds float, ptr %100, i64 %103
  store float %97, ptr %104, align 4, !tbaa !15
  br label %105

105:                                              ; preds = %46, %22
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %4, align 4, !tbaa !9
  %108 = add i32 %107, -1
  store i32 %108, ptr %4, align 4, !tbaa !9
  br label %18, !llvm.loop !18

109:                                              ; preds = %18
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %3, align 4, !tbaa !9
  %112 = add i32 %111, 1
  store i32 %112, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !20

113:                                              ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 0
}

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

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


; 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 @gasearch_rank(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not37 = icmp eq i32 %3, 0
  br i1 %.not37, label %._crit_edge36, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %6 = phi i32 [ %3, %.preheader.lr.ph ], [ %35, %._crit_edge ]
  %.035 = phi i32 [ 0, %.preheader.lr.ph ], [ %36, %._crit_edge ]
  %.02932 = add i32 %6, -1
  %7 = icmp ugt i32 %.02932, %.035
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %8 = zext i32 %.02932 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %32
  %indvars.iv = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next, %32 ]
  %.029.in33 = phi i32 [ %6, %.lr.ph.preheader ], [ %34, %32 ]
  %9 = load ptr, ptr %4, align 8, !tbaa !12
  %10 = getelementptr inbounds float, ptr %9, i64 %indvars.iv
  %11 = load float, ptr %10, align 4, !tbaa !13
  %12 = add i32 %.029.in33, -2
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds float, ptr %9, i64 %13
  %15 = load float, ptr %14, align 4, !tbaa !13
  %16 = load i32, ptr %5, align 8, !tbaa !14
  %.not = icmp eq i32 %16, 0
  %17 = zext i1 %.not to i32
  %18 = tail call i32 @optim_threshold_switch(float noundef %11, float noundef %15, i32 noundef %17) #2
  %.not31 = icmp eq i32 %18, 0
  br i1 %.not31, label %32, label %19

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr %0, align 8, !tbaa !15
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds ptr, ptr %20, i64 %13
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  store ptr %24, ptr %21, align 8, !tbaa !16
  %25 = load ptr, ptr %0, align 8, !tbaa !15
  %26 = getelementptr inbounds ptr, ptr %25, i64 %13
  store ptr %22, ptr %26, align 8, !tbaa !16
  %27 = load ptr, ptr %4, align 8, !tbaa !12
  %28 = getelementptr inbounds float, ptr %27, i64 %indvars.iv
  %29 = load float, ptr %28, align 4, !tbaa !13
  %30 = getelementptr inbounds float, ptr %27, i64 %13
  %31 = load float, ptr %30, align 4, !tbaa !13
  store float %31, ptr %28, align 4, !tbaa !13
  store float %29, ptr %30, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %.lr.ph, %19
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %indvars = trunc i64 %indvars.iv.next to i32
  %33 = icmp ult i32 %.035, %indvars
  %34 = trunc nuw i64 %indvars.iv to i32
  br i1 %33, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !17

._crit_edge.loopexit:                             ; preds = %32
  %.pre = load i32, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %35 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %36 = add nuw i32 %.035, 1
  %37 = icmp ult i32 %36, %35
  br i1 %37, label %.preheader, label %._crit_edge36, !llvm.loop !19

._crit_edge36:                                    ; preds = %._crit_edge, %1
  ret i32 0
}

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


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