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

; 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::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 }
%"class.SoLoud::Bus" = type { %"class.SoLoud::AudioSource", ptr, i32, i32, [256 x float], [256 x float] }

; 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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud3Bus19getActiveVoiceCountEv(ptr noundef nonnull align 8 dereferenceable(2216) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216) %5)
  %6 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %5, i32 0, i32 12
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  call void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %7)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %37, %1
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 1024
  br i1 %10, label %11, label %40

11:                                               ; preds = %8
  %12 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %5, i32 0, i32 12
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.SoLoud::Soloud", ptr %13, i32 0, i32 16
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1024 x ptr], ptr %14, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %36

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

33:                                               ; preds = %20
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = add i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %33, %20, %11
  br label %37

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

40:                                               ; preds = %8
  %41 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %5, i32 0, i32 12
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  call void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %42)
  %43 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %43
}

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 384}
!16 = !{!"_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, !17, i64 104, !17, i64 152, !17, i64 200, !17, i64 248, !17, 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}
!17 = !{!"_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}
!18 = !{!19, !10, i64 160}
!19 = !{!"_ZTSN6SoLoud3BusE", !12, i64 0, !6, i64 152, !10, i64 160, !10, i64 164, !7, i64 168, !7, i64 1192}
!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 uwtable
declare dso_local void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud3Bus19getActiveVoiceCountEv(ptr noundef nonnull align 8 dereferenceable(2216) %0) local_unnamed_addr #0 align 2 {
  tail call void @_ZN6SoLoud3Bus13findBusHandleEv(ptr noundef nonnull align 8 dereferenceable(2216) %0)
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @_ZN6SoLoud6Soloud23lockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %3)
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 152
  %6 = getelementptr inbounds i8, ptr %0, i64 160
  %7 = load i32, ptr %6, align 8
  br label %8

8:                                                ; preds = %24, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.1, %24 ]
  %.09 = phi i32 [ 0, %1 ], [ %.1.1, %24 ]
  %9 = getelementptr inbounds [1024 x ptr], ptr %5, i64 0, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %16, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %10, i64 384
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp eq i32 %13, %7
  %15 = zext i1 %14 to i32
  %spec.select = add i32 %.09, %15
  br label %16

16:                                               ; preds = %11, %8
  %.1 = phi i32 [ %.09, %8 ], [ %spec.select, %11 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds [1024 x ptr], ptr %5, i64 0, i64 %indvars.iv.next
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %.not.1 = icmp eq ptr %18, null
  br i1 %.not.1, label %24, label %19

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %18, i64 384
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = icmp eq i32 %21, %7
  %23 = zext i1 %22 to i32
  %spec.select.1 = add i32 %.1, %23
  br label %24

24:                                               ; preds = %19, %16
  %.1.1 = phi i32 [ %.1, %16 ], [ %spec.select.1, %19 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1024
  br i1 %exitcond.not.1, label %25, label %8, !llvm.loop !17

25:                                               ; preds = %24
  tail call void @_ZN6SoLoud6Soloud25unlockAudioMutex_internalEv(ptr noundef nonnull align 8 dereferenceable(138833) %4)
  ret i32 %.1.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, !11, i64 112}
!6 = !{!"_ZTSN6SoLoud11AudioSourceE", !7, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 44, !8, i64 48, !11, i64 112, !11, i64 120, !11, i64 128, !7, i64 136, !12, i64 144}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !7, i64 384}
!15 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !8, i64 24, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 76, !10, i64 80, !12, i64 88, !12, i64 96, !16, i64 104, !16, i64 152, !16, i64 200, !16, i64 248, !16, i64 296, !7, i64 344, !8, i64 348, !7, i64 380, !7, i64 384, !8, i64 392, !8, i64 456, !7, i64 472, !7, i64 476, !7, i64 480, !12, i64 488}
!16 = !{!"_ZTSN6SoLoud5FaderE", !10, i64 0, !10, i64 4, !10, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !10, i64 40, !7, i64 44}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass