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

; 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::Queue" = type <{ %"class.SoLoud::AudioSource", i32, i32, i32, [4 x i8], [32 x ptr], ptr, i32, [4 x i8] }>
%"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::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] }>

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

5:                                                ; preds = %36, %1
  %6 = getelementptr inbounds %"class.SoLoud::Queue", ptr %4, i32 0, i32 7
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %16

9:                                                ; preds = %5
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %4, i32 0, i32 12
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds %"class.SoLoud::Soloud", ptr %12, i32 0, i32 8
  %14 = load i32, ptr %13, align 4, !tbaa !17
  %15 = icmp slt i32 %10, %14
  br label %16

16:                                               ; preds = %9, %5
  %17 = phi i1 [ false, %5 ], [ %15, %9 ]
  br i1 %17, label %18, label %39

18:                                               ; preds = %16
  %19 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %4, i32 0, i32 12
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds %"class.SoLoud::Soloud", ptr %20, i32 0, i32 16
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1024 x ptr], ptr %21, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.SoLoud::Queue", ptr %4, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !22
  %28 = icmp eq ptr %25, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %18
  %30 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %4, i32 0, i32 12
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = call noundef i32 @_ZNK6SoLoud6Soloud27getHandleFromVoice_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %31, i32 noundef %32)
  %34 = getelementptr inbounds %"class.SoLoud::Queue", ptr %4, i32 0, i32 7
  store i32 %33, ptr %34, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %29, %18
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !23

39:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

declare noundef i32 @_ZNK6SoLoud6Soloud27getHandleFromVoice_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) #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, !10, i64 432}
!12 = !{!"_ZTSN6SoLoud5QueueE", !13, i64 0, !10, i64 152, !10, i64 156, !10, i64 160, !7, i64 168, !6, i64 424, !10, i64 432}
!13 = !{!"_ZTSN6SoLoud11AudioSourceE", !10, i64 8, !14, i64 12, !14, i64 16, !10, i64 20, !10, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !10, i64 40, !14, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !15, i64 144}
!14 = !{!"float", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!13, !6, i64 112}
!17 = !{!18, !10, i64 52}
!18 = !{!"_ZTSN6SoLoud6SoloudE", !6, i64 0, !6, i64 8, !19, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !20, i64 56, !10, i64 80, !20, i64 88, !6, i64 112, !20, i64 120, !6, i64 144, !7, i64 152, !10, i64 8344, !10, i64 8348, !10, i64 8352, !10, i64 8356, !6, i64 8360, !10, i64 8368, !10, i64 8372, !14, i64 8376, !14, i64 8380, !10, i64 8384, !10, i64 8388, !21, i64 8392, !15, i64 8440, !15, i64 8448, !7, i64 8456, !7, i64 8520, !7, i64 8584, !7, i64 8616, !7, i64 9640, !7, i64 10664, !7, i64 11688, !7, i64 11700, !7, i64 11712, !7, i64 11724, !14, i64 11736, !7, i64 11740, !7, i64 11840, !6, i64 134720, !10, i64 134728, !7, i64 134732, !10, i64 138828, !19, i64 138832}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSN6SoLoud18AlignedFloatBufferE", !6, i64 0, !6, i64 8, !10, i64 16}
!21 = !{!"_ZTSN6SoLoud5FaderE", !14, i64 0, !14, i64 4, !14, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !14, i64 40, !10, i64 44}
!22 = !{!12, !6, i64 424}
!23 = distinct !{!23, !24}
!24 = !{!"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 uwtable
define dso_local void @_ZN6SoLoud5Queue15findQueueHandleEv(ptr nocapture noundef nonnull align 8 dereferenceable(436) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = getelementptr inbounds i8, ptr %0, i64 432
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %.lr.ph, label %.critedge

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

7:                                                ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %8 = load ptr, ptr %2, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %8, i64 52
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv, %11
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %8, i64 152
  %15 = getelementptr inbounds [1024 x ptr], ptr %14, i64 0, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = load ptr, ptr %6, align 8, !tbaa !21
  %18 = icmp eq ptr %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %13
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = tail call noundef i32 @_ZNK6SoLoud6Soloud27getHandleFromVoice_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %8, i32 noundef %20)
  store i32 %21, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %13, %19
  %23 = phi i32 [ 0, %13 ], [ %21, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %7, label %.critedge, !llvm.loop !22

.critedge:                                        ; preds = %7, %22, %1
  ret void
}

declare noundef i32 @_ZNK6SoLoud6Soloud27getHandleFromVoice_internalEj(ptr noundef nonnull align 8 dereferenceable(138833), i32 noundef) local_unnamed_addr #1

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

!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, !8, i64 432}
!6 = !{!"_ZTSN6SoLoud5QueueE", !7, i64 0, !8, i64 152, !8, i64 156, !8, i64 160, !9, i64 168, !12, i64 424, !8, i64 432}
!7 = !{!"_ZTSN6SoLoud11AudioSourceE", !8, i64 8, !11, i64 12, !11, i64 16, !8, i64 20, !8, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !11, i64 44, !9, i64 48, !12, i64 112, !12, i64 120, !12, i64 128, !8, i64 136, !13, i64 144}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{!7, !12, i64 112}
!15 = !{!16, !8, i64 52}
!16 = !{!"_ZTSN6SoLoud6SoloudE", !12, i64 0, !12, i64 8, !17, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !8, i64 48, !8, i64 52, !18, i64 56, !8, i64 80, !18, i64 88, !12, i64 112, !18, i64 120, !12, i64 144, !9, i64 152, !8, i64 8344, !8, i64 8348, !8, i64 8352, !8, i64 8356, !12, i64 8360, !8, i64 8368, !8, i64 8372, !11, i64 8376, !11, i64 8380, !8, i64 8384, !8, i64 8388, !19, i64 8392, !13, i64 8440, !13, i64 8448, !9, i64 8456, !9, i64 8520, !9, i64 8584, !9, i64 8616, !9, i64 9640, !9, i64 10664, !9, i64 11688, !9, i64 11700, !9, i64 11712, !9, i64 11724, !11, i64 11736, !9, i64 11740, !9, i64 11840, !12, i64 134720, !8, i64 134728, !9, i64 134732, !8, i64 138828, !17, i64 138832}
!17 = !{!"bool", !9, i64 0}
!18 = !{!"_ZTSN6SoLoud18AlignedFloatBufferE", !12, i64 0, !12, i64 8, !8, i64 16}
!19 = !{!"_ZTSN6SoLoud5FaderE", !11, i64 0, !11, i64 4, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !8, i64 44}
!20 = !{!12, !12, i64 0}
!21 = !{!6, !12, i64 424}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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