; LLVM IR from suxiaojack/sapDecoder :: src/hrtf.ll (ZN4HRTF18InitNeighborSearchEv)

; 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.HRTFDataT = type { %"class.std::__cxx11::basic_string", i32, i32, i32, ptr, float, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%class.HRTF = type { ptr, i32, i32, ptr, i32, i8, float, float, i32, %"class.std::vector", %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<std::vector<float>, std::vector<float>>, std::allocator<std::pair<std::vector<float>, std::vector<float>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<std::vector<float>, std::vector<float>>, std::allocator<std::pair<std::vector<float>, std::vector<float>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<std::vector<float>, std::vector<float>>, std::allocator<std::pair<std::vector<float>, std::vector<float>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<std::vector<float>, std::vector<float>>, std::allocator<std::pair<std::vector<float>, std::vector<float>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZL12kHRTFDataSet = external hidden global %struct.HRTFDataT, align 8

; 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: mustprogress uwtable
define dso_local void @_ZN4HRTF18InitNeighborSearchEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %32, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = load i32, ptr getelementptr inbounds (%struct.HRTFDataT, ptr @_ZL12kHRTFDataSet, i32 0, i32 1), align 8, !tbaa !11
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %35

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %13 = load ptr, ptr getelementptr inbounds (%struct.HRTFDataT, ptr @_ZL12kHRTFDataSet, i32 0, i32 4), align 8, !tbaa !17
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2 x i32], ptr %13, i64 %15
  %17 = getelementptr inbounds [2 x i32], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sitofp i32 %18 to float
  store float %19, ptr %4, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %20 = load ptr, ptr getelementptr inbounds (%struct.HRTFDataT, ptr @_ZL12kHRTFDataSet, i32 0, i32 4), align 8, !tbaa !17
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x i32], ptr %20, i64 %22
  %24 = getelementptr inbounds [2 x i32], ptr %23, i64 0, i64 1
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = sitofp i32 %25 to float
  store float %26, ptr %5, align 4, !tbaa !18
  %27 = getelementptr inbounds %class.HRTF, ptr %6, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = load float, ptr %4, align 4, !tbaa !18
  %30 = load float, ptr %5, align 4, !tbaa !18
  %31 = load i32, ptr %3, align 4, !tbaa !9
  call void @_ZN19FLANNNeighborSearch16AddHRTFDirectionEffi(ptr noundef nonnull align 8 dereferenceable(104) %28, float noundef %29, float noundef %30, i32 noundef %31)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %32

32:                                               ; preds = %12
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !26

35:                                               ; preds = %11
  %36 = getelementptr inbounds %class.HRTF, ptr %6, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  call void @_ZN19FLANNNeighborSearch10BuildIndexEv(ptr noundef nonnull align 8 dereferenceable(104) %37)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN19FLANNNeighborSearch16AddHRTFDirectionEffi(ptr noundef nonnull align 8 dereferenceable(104), float noundef, float noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN19FLANNNeighborSearch10BuildIndexEv(ptr noundef nonnull align 8 dereferenceable(104)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_ZTS9HRTFDataT", !13, i64 0, !10, i64 32, !10, i64 36, !10, i64 40, !6, i64 48, !16, i64 56, !6, i64 64}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!12, !6, i64 48}
!18 = !{!16, !16, i64 0}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTS4HRTF", !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !21, i64 28, !16, i64 32, !16, i64 36, !10, i64 40, !22, i64 48, !22, i64 72}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTSSt6vectorISt4pairIS_IfSaIfEES2_ESaIS3_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"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"

%struct.HRTFDataT = type { %"class.std::__cxx11::basic_string", i32, i32, i32, ptr, float, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_ZL12kHRTFDataSet = external hidden local_unnamed_addr global %struct.HRTFDataT, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4HRTF18InitNeighborSearchEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL12kHRTFDataSet, i64 32), align 8, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  br label %7

._crit_edge:                                      ; preds = %7, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !15
  tail call void @_ZN19FLANNNeighborSearch10BuildIndexEv(ptr noundef nonnull align 8 dereferenceable(104) %6)
  ret void

7:                                                ; preds = %.lr.ph, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZL12kHRTFDataSet, i64 48), align 8, !tbaa !22
  %9 = getelementptr inbounds [2 x i32], ptr %8, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !23
  %11 = sitofp i32 %10 to float
  %12 = getelementptr inbounds i8, ptr %9, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !23
  %14 = sitofp i32 %13 to float
  %15 = load ptr, ptr %4, align 8, !tbaa !15
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN19FLANNNeighborSearch16AddHRTFDirectionEffi(ptr noundef nonnull align 8 dereferenceable(104) %15, float noundef %11, float noundef %14, i32 noundef %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL12kHRTFDataSet, i64 32), align 8, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %7, label %._crit_edge, !llvm.loop !24
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN19FLANNNeighborSearch16AddHRTFDirectionEffi(ptr noundef nonnull align 8 dereferenceable(104), float noundef, float noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN19FLANNNeighborSearch10BuildIndexEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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" }

!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, !13, i64 32}
!6 = !{!"_ZTS9HRTFDataT", !7, i64 0, !13, i64 32, !13, i64 36, !13, i64 40, !9, i64 48, !14, i64 56, !9, i64 64}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"float", !10, i64 0}
!15 = !{!16, !9, i64 16}
!16 = !{!"_ZTS4HRTF", !13, i64 8, !13, i64 12, !9, i64 16, !13, i64 24, !17, i64 28, !14, i64 32, !14, i64 36, !13, i64 40, !18, i64 48, !18, i64 72}
!17 = !{!"bool", !10, i64 0}
!18 = !{!"_ZTSSt6vectorISt4pairIS_IfSaIfEES2_ESaIS3_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseISt4pairISt6vectorIfSaIfEES3_ESaIS4_EE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!22 = !{!6, !9, i64 48}
!23 = !{!13, !13, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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