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

; 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::Bus" = type { %"class.SoLoud::AudioSource", ptr, i32, i32, [256 x float], [256 x float] }
%"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 @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216) %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
  %5 = getelementptr inbounds %"class.SoLoud::Bus", ptr %4, i32 0, i32 2
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %44

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %9

9:                                                ; preds = %40, %8
  %10 = getelementptr inbounds %"class.SoLoud::Bus", ptr %4, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %20

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

20:                                               ; preds = %13, %9
  %21 = phi i1 [ false, %9 ], [ %19, %13 ]
  br i1 %21, label %22, label %43

22:                                               ; preds = %20
  %23 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %4, i32 0, i32 12
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %"class.SoLoud::Soloud", ptr %24, i32 0, i32 16
  %26 = load i32, ptr %3, align 4, !tbaa !15
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1024 x ptr], ptr %25, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.SoLoud::Bus", ptr %4, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = icmp eq ptr %29, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %22
  %34 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %4, i32 0, i32 12
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %3, align 4, !tbaa !15
  %37 = call noundef i32 @_ZNK6SoLoud6Soloud27getHandleFromVoice_internalEj(ptr noundef nonnull align 8 dereferenceable(138833) %35, i32 noundef %36)
  %38 = getelementptr inbounds %"class.SoLoud::Bus", ptr %4, i32 0, i32 2
  store i32 %37, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %33, %22
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %3, align 4, !tbaa !15
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !15
  br label %9, !llvm.loop !23

43:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %44

44:                                               ; preds = %43, %1
  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, !12, i64 160}
!10 = !{!"_ZTSN6SoLoud3BusE", !11, i64 0, !6, i64 152, !12, i64 160, !12, i64 164, !7, i64 168, !7, i64 1192}
!11 = !{!"_ZTSN6SoLoud11AudioSourceE", !12, i64 8, !13, i64 12, !13, i64 16, !12, i64 20, !12, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !12, i64 40, !13, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !14, i64 144}
!12 = !{!"int", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !6, i64 112}
!17 = !{!18, !12, i64 52}
!18 = !{!"_ZTSN6SoLoud6SoloudE", !6, i64 0, !6, i64 8, !19, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !20, i64 56, !12, i64 80, !20, i64 88, !6, i64 112, !20, i64 120, !6, i64 144, !7, i64 152, !12, i64 8344, !12, i64 8348, !12, i64 8352, !12, i64 8356, !6, i64 8360, !12, i64 8368, !12, i64 8372, !13, i64 8376, !13, i64 8380, !12, i64 8384, !12, i64 8388, !21, i64 8392, !14, i64 8440, !14, 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, !13, i64 11736, !7, i64 11740, !7, i64 11840, !6, i64 134720, !12, i64 134728, !7, i64 134732, !12, i64 138828, !19, i64 138832}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSN6SoLoud18AlignedFloatBufferE", !6, i64 0, !6, i64 8, !12, i64 16}
!21 = !{!"_ZTSN6SoLoud5FaderE", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !13, i64 40, !12, i64 44}
!22 = !{!10, !6, i64 152}
!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 @_ZN6SoLoud3Bus13findBusHandleEv(ptr nocapture noundef nonnull align 8 dereferenceable(2216) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 160
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader, label %.critedge

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = getelementptr inbounds i8, ptr %0, i64 152
  br label %7

7:                                                ; preds = %.preheader, %22
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %22 ]
  %8 = load ptr, ptr %5, 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 %2, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %13, %19
  %.pr = phi i32 [ 0, %13 ], [ %21, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = icmp eq i32 %.pr, 0
  br i1 %23, 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 160}
!6 = !{!"_ZTSN6SoLoud3BusE", !7, i64 0, !12, i64 152, !8, i64 160, !8, i64 164, !9, i64 168, !9, i64 1192}
!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 152}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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