; LLVM IR from merpheus-dev/LavaEngine :: src/Utils/soloud/src/core/soloud_bus.ll (ZN6SoLoud11BusInstanceC2EPNS_3BusE)

; 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::BusInstance" = type { %"class.SoLoud::AudioSourceInstance", ptr, i32, [4 x i8], %"class.SoLoud::AlignedFloatBuffer", [8 x float], [256 x float] }
%"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::Fader" = type { float, float, float, double, double, double, float, i32 }
%"class.SoLoud::AlignedFloatBuffer" = type <{ ptr, ptr, i32, [4 x i8] }>

@_ZTVN6SoLoud11BusInstanceE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6SoLoud11BusInstanceC2EPNS_3BusE(ptr noundef nonnull align 8 dereferenceable(1592) %0, ptr noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @_ZN6SoLoud19AudioSourceInstanceC2Ev(ptr noundef nonnull align 8 dereferenceable(496) %9)
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTVN6SoLoud11BusInstanceE, i32 0, i32 0, i32 2), ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.SoLoud::BusInstance", ptr %9, i32 0, i32 4
  invoke void @_ZN6SoLoud18AlignedFloatBufferC1Ev(ptr noundef nonnull align 8 dereferenceable(20) %10)
          to label %11 unwind label %22

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.SoLoud::BusInstance", ptr %9, i32 0, i32 1
  store ptr %12, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.SoLoud::BusInstance", ptr %9, i32 0, i32 2
  store i32 0, ptr %14, align 8, !tbaa !19
  %15 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %9, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !20
  %17 = or i32 %16, 130
  store i32 %17, ptr %15, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !21
  br label %18

18:                                               ; preds = %31, %11
  %19 = load i32, ptr %7, align 4, !tbaa !21
  %20 = icmp slt i32 %19, 8
  br i1 %20, label %26, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %34

22:                                               ; preds = %2
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %5, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %6, align 4
  call void @_ZN6SoLoud19AudioSourceInstanceD2Ev(ptr noundef nonnull align 8 dereferenceable(496) %9) #4
  br label %48

26:                                               ; preds = %18
  %27 = getelementptr inbounds %"class.SoLoud::BusInstance", ptr %9, i32 0, i32 5
  %28 = load i32, ptr %7, align 4, !tbaa !21
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [8 x float], ptr %27, i64 0, i64 %29
  store float 0.000000e+00, ptr %30, align 4, !tbaa !22
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %7, align 4, !tbaa !21
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !21
  br label %18, !llvm.loop !23

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

35:                                               ; preds = %44, %34
  %36 = load i32, ptr %8, align 4, !tbaa !21
  %37 = icmp slt i32 %36, 256
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %47

39:                                               ; preds = %35
  %40 = getelementptr inbounds %"class.SoLoud::BusInstance", ptr %9, i32 0, i32 6
  %41 = load i32, ptr %8, align 4, !tbaa !21
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [256 x float], ptr %40, i64 0, i64 %42
  store float 0.000000e+00, ptr %43, align 4, !tbaa !22
  br label %44

44:                                               ; preds = %39
  %45 = load i32, ptr %8, align 4, !tbaa !21
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !21
  br label %35, !llvm.loop !25

47:                                               ; preds = %38
  ret void

48:                                               ; preds = %22
  %49 = load ptr, ptr %5, align 8
  %50 = load i32, ptr %6, align 4
  %51 = insertvalue { ptr, i32 } poison, ptr %49, 0
  %52 = insertvalue { ptr, i32 } %51, i32 %50, 1
  resume { ptr, i32 } %52
}

declare void @_ZN6SoLoud19AudioSourceInstanceC2Ev(ptr noundef nonnull align 8 dereferenceable(496)) unnamed_addr #1

declare void @_ZN6SoLoud18AlignedFloatBufferC1Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: nounwind
declare void @_ZN6SoLoud19AudioSourceInstanceD2Ev(ptr noundef nonnull align 8 dereferenceable(496)) unnamed_addr #3

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 #4 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 496}
!12 = !{!"_ZTSN6SoLoud11BusInstanceE", !13, i64 0, !6, i64 496, !14, i64 504, !18, i64 512, !7, i64 536, !7, i64 568}
!13 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !14, i64 8, !14, i64 12, !14, i64 16, !15, i64 20, !7, i64 24, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !14, i64 72, !15, i64 76, !15, i64 80, !16, i64 88, !16, i64 96, !17, i64 104, !17, i64 152, !17, i64 200, !17, i64 248, !17, i64 296, !14, i64 344, !7, i64 348, !14, i64 380, !14, i64 384, !7, i64 392, !7, i64 456, !14, i64 472, !14, i64 476, !14, i64 480, !16, i64 488}
!14 = !{!"int", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!"_ZTSN6SoLoud5FaderE", !15, i64 0, !15, i64 4, !15, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !15, i64 40, !14, i64 44}
!18 = !{!"_ZTSN6SoLoud18AlignedFloatBufferE", !6, i64 0, !6, i64 8, !14, i64 16}
!19 = !{!12, !14, i64 504}
!20 = !{!13, !14, i64 16}
!21 = !{!14, !14, i64 0}
!22 = !{!15, !15, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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

@_ZTVN6SoLoud11BusInstanceE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6SoLoud11BusInstanceC2EPNS_3BusE(ptr noundef nonnull align 8 dereferenceable(1592) %0, ptr noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN6SoLoud19AudioSourceInstanceC2Ev(ptr noundef nonnull align 8 dereferenceable(496) %0)
  store ptr getelementptr inbounds inrange(-16, 56) (i8, ptr @_ZTVN6SoLoud11BusInstanceE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 512
  invoke void @_ZN6SoLoud18AlignedFloatBufferC1Ev(ptr noundef nonnull align 8 dereferenceable(20) %3)
          to label %.preheader unwind label %10

.preheader:                                       ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 496
  store ptr %1, ptr %4, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 504
  store i32 0, ptr %5, align 8, !tbaa !18
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !19
  %8 = or i32 %7, 130
  store i32 %8, ptr %6, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %0, i64 536
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1056) %9, i8 0, i64 1056, i1 false)
  ret void

10:                                               ; preds = %2
  %11 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6SoLoud19AudioSourceInstanceD2Ev(ptr noundef nonnull align 8 dereferenceable(496) %0) #4
  resume { ptr, i32 } %11
}

declare void @_ZN6SoLoud19AudioSourceInstanceC2Ev(ptr noundef nonnull align 8 dereferenceable(496)) unnamed_addr #1

declare void @_ZN6SoLoud18AlignedFloatBufferC1Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6SoLoud19AudioSourceInstanceD2Ev(ptr noundef nonnull align 8 dereferenceable(496)) unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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" }
attributes #2 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !16, i64 496}
!9 = !{!"_ZTSN6SoLoud11BusInstanceE", !10, i64 0, !16, i64 496, !11, i64 504, !17, i64 512, !12, i64 536, !12, i64 568}
!10 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !11, i64 8, !11, i64 12, !11, i64 16, !13, i64 20, !12, i64 24, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !11, i64 72, !13, i64 76, !13, i64 80, !14, i64 88, !14, i64 96, !15, i64 104, !15, i64 152, !15, i64 200, !15, i64 248, !15, i64 296, !11, i64 344, !12, i64 348, !11, i64 380, !11, i64 384, !12, i64 392, !12, i64 456, !11, i64 472, !11, i64 476, !11, i64 480, !14, i64 488}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"float", !12, i64 0}
!14 = !{!"double", !12, i64 0}
!15 = !{!"_ZTSN6SoLoud5FaderE", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !13, i64 40, !11, i64 44}
!16 = !{!"any pointer", !12, i64 0}
!17 = !{!"_ZTSN6SoLoud18AlignedFloatBufferE", !16, i64 0, !16, i64 8, !11, i64 16}
!18 = !{!9, !11, i64 504}
!19 = !{!10, !11, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass