; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/core/soloud_bus.ll (ZN6SoLoud3Bus10annexSoundEj)

; 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"

%"class.SoLoud::AudioSource" = type { ptr, i32, float, float, i32, i32, float, float, float, i32, float, [8 x ptr], ptr, ptr, ptr, i32, double }
%"class.SoLoud::Bus" = type { %"class.SoLoud::AudioSource", ptr, i32, i32, [256 x float], [256 x float] }
%"class.SoLoud::Soloud" = type <{ ptr, ptr, i8, [7 x i8], ptr, ptr, ptr, i32, i32, %"class.SoLoud::AlignedFloatBuffer", i32, [4 x i8], %"class.SoLoud::AlignedFloatBuffer", ptr, %"class.SoLoud::AlignedFloatBuffer", ptr, [1024 x ptr], i32, i32, i32, i32, ptr, i32, i32, float, float, i32, i32, %"class.SoLoud::Fader", double, double, [8 x ptr], [8 x ptr], [8 x float], [256 x float], [256 x float], [256 x float], [3 x float], [3 x float], [3 x float], [3 x float], float, [24 x float], [4 x i8], [1024 x %"class.SoLoud::AudioSourceInstance3dData"], ptr, i32, [1024 x i32], i32, i8, [7 x i8] }>
%"class.SoLoud::AlignedFloatBuffer" = type <{ ptr, ptr, i32, [4 x i8] }>
%"class.SoLoud::Fader" = type { float, float, float, double, double, double, float, i32 }
%"class.SoLoud::AudioSourceInstance3dData" = type <{ [3 x float], [3 x float], float, float, float, i32, float, [4 x i8], ptr, ptr, i32, float, float, [8 x float], i32, i32, [4 x i8] }>
%"class.SoLoud::AudioSourceInstance" = type { ptr, i32, i32, i32, float, [8 x float], float, float, float, float, i32, float, float, double, double, %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", i32, [8 x float], i32, i32, [8 x ptr], [2 x ptr], i32, i32, i32, double }

; 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
declare dso_local void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6SoLoud3Bus10annexSoundEj(ptr noundef nonnull align 8 dereferenceable(2216) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [2 x i32], align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216) %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %9, ptr %6, align 4, !tbaa !9
  %10 = getelementptr inbounds i32, ptr %6, i64 1
  store i32 0, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 12
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  call void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %12)
  %13 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 12
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = call noundef ptr @_ZNK6SoLoud6Soloud32voiceGroupHandleToArray_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %14, i32 noundef %15)
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %21

19:                                               ; preds = %2
  %20 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  store ptr %20, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %19, %2
  br label %22

22:                                               ; preds = %45, %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %48

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %27 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 12
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = call noundef i32 @_ZNK6SoLoud6Soloud27getVoiceFromHandle_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %28, i32 noundef %30)
  store i32 %31, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp ne i32 %32, -1
  br i1 %33, label %34, label %45

34:                                               ; preds = %26
  %35 = getelementptr inbounds %"class.SoLoud::Bus", ptr %8, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 12
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %"class.SoLoud::Soloud", ptr %38, i32 0, i32 16
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1024 x ptr], ptr %39, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %43, i32 0, i32 23
  store i32 %36, ptr %44, align 8, !tbaa !17
  br label %45

45:                                               ; preds = %34, %26
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i32, ptr %46, i32 1
  store ptr %47, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %22, !llvm.loop !20

48:                                               ; preds = %22
  %49 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 12
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  call void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833)) #2

declare noundef ptr @_ZNK6SoLoud6Soloud32voiceGroupHandleToArray_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) #2

declare noundef i32 @_ZNK6SoLoud6Soloud27getVoiceFromHandle_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) #2

declare void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833)) #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 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 112}
!12 = !{!"_ZTSN6SoLoud11AudioSourceE", !10, i64 8, !13, i64 12, !13, i64 16, !10, i64 20, !10, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !10, i64 40, !13, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !14, i64 144}
!13 = !{!"float", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !10, i64 160}
!16 = !{!"_ZTSN6SoLoud3BusE", !12, i64 0, !6, i64 152, !10, i64 160, !10, i64 164, !7, i64 168, !7, i64 1192}
!17 = !{!18, !10, i64 384}
!18 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !7, i64 24, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !10, i64 72, !13, i64 76, !13, i64 80, !14, i64 88, !14, i64 96, !19, i64 104, !19, i64 152, !19, i64 200, !19, i64 248, !19, i64 296, !10, i64 344, !7, i64 348, !10, i64 380, !10, i64 384, !7, i64 392, !7, i64 456, !10, i64 472, !10, i64 476, !10, i64 480, !14, i64 488}
!19 = !{!"_ZTSN6SoLoud5FaderE", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !13, i64 40, !10, i64 44}
!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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6SoLoud3Bus10annexSoundEj(ptr noundef nonnull align 8 dereferenceable(2216) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca [2 x i32], align 4
  tail call void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  tail call void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %6)
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = tail call noundef ptr @_ZNK6SoLoud6Soloud32voiceGroupHandleToArray_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %7, i32 noundef %1)
  %9 = icmp eq ptr %8, null
  %spec.select = select i1 %9, ptr %3, ptr %8
  %10 = load i32, ptr %spec.select, align 4, !tbaa !5
  %.not12 = icmp eq i32 %10, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 160
  br label %12

12:                                               ; preds = %.lr.ph, %24
  %13 = phi i32 [ %10, %.lr.ph ], [ %26, %24 ]
  %.113 = phi ptr [ %spec.select, %.lr.ph ], [ %25, %24 ]
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = tail call noundef i32 @_ZNK6SoLoud6Soloud27getVoiceFromHandle_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %14, i32 noundef %13)
  %.not11 = icmp eq i32 %15, -1
  br i1 %.not11, label %24, label %16

16:                                               ; preds = %12
  %17 = load i32, ptr %11, align 8, !tbaa !14
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 152
  %20 = sext i32 %15 to i64
  %21 = getelementptr inbounds [1024 x ptr], ptr %19, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %22, i64 384
  store i32 %17, ptr %23, align 8, !tbaa !17
  br label %24

24:                                               ; preds = %16, %12
  %25 = getelementptr inbounds i8, ptr %.113, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %._crit_edge, label %12, !llvm.loop !20

._crit_edge:                                      ; preds = %24, %2
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  tail call void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %27)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void
}

declare void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833)) local_unnamed_addr #2

declare noundef ptr @_ZNK6SoLoud6Soloud32voiceGroupHandleToArray_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) local_unnamed_addr #2

declare noundef i32 @_ZNK6SoLoud6Soloud27getVoiceFromHandle_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) local_unnamed_addr #2

declare void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833)) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 112}
!10 = !{!"_ZTSN6SoLoud11AudioSourceE", !6, i64 8, !11, i64 12, !11, i64 16, !6, i64 20, !6, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 44, !7, i64 48, !12, i64 112, !12, i64 120, !12, i64 128, !6, i64 136, !13, i64 144}
!11 = !{!"float", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !6, i64 160}
!15 = !{!"_ZTSN6SoLoud3BusE", !10, i64 0, !12, i64 152, !6, i64 160, !6, i64 164, !7, i64 168, !7, i64 1192}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !6, i64 384}
!18 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 20, !7, i64 24, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !6, i64 72, !11, i64 76, !11, i64 80, !13, i64 88, !13, i64 96, !19, i64 104, !19, i64 152, !19, i64 200, !19, i64 248, !19, i64 296, !6, i64 344, !7, i64 348, !6, i64 380, !6, i64 384, !7, i64 392, !7, i64 456, !6, i64 472, !6, i64 476, !6, i64 480, !13, i64 488}
!19 = !{!"_ZTSN6SoLoud5FaderE", !11, i64 0, !11, i64 4, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !6, i64 44}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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