; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/tedsid (soloud_tedsid)

; 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::TedSidInstance" = type { %"class.SoLoud::AudioSourceInstance", ptr, ptr, ptr, i32, i32, [128 x i32] }
%"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 }

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

13:                                               ; preds = %39, %4
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %42

17:                                               ; preds = %13
  %18 = load ptr, ptr %12, align 8, !tbaa !11
  %19 = getelementptr inbounds ptr, ptr %18, i64 7
  %20 = load ptr, ptr %19, align 8
  call void %20(ptr noundef nonnull align 8 dereferenceable(1040) %12)
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %21 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %12, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  call void @_ZN8SIDsound11calcSamplesEPsl(ptr noundef nonnull align 8 dereferenceable(16796) %22, ptr noundef %10, i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  store i16 0, ptr %11, align 2, !tbaa !19
  %23 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %12, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  call void @_ZN3TED11renderSoundEjPs(ptr noundef nonnull align 4 dereferenceable(352) %24, i32 noundef 1, ptr noundef %11)
  %25 = load i16, ptr %10, align 2, !tbaa !19
  %26 = sext i16 %25 to i32
  %27 = load i16, ptr %11, align 2, !tbaa !19
  %28 = sext i16 %27 to i32
  %29 = add nsw i32 %26, %28
  %30 = sitofp i32 %29 to float
  %31 = fdiv float %30, 8.192000e+03
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds float, ptr %32, i64 %34
  store float %31, ptr %35, align 4, !tbaa !22
  %36 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %12, i32 0, i32 5
  %37 = load i32, ptr %36, align 4, !tbaa !23
  %38 = add i32 %37, -1
  store i32 %38, ptr %36, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  br label %39

39:                                               ; preds = %17
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !24

42:                                               ; preds = %13
  %43 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %43
}

declare void @_ZN8SIDsound11calcSamplesEPsl(ptr noundef nonnull align 8 dereferenceable(16796), ptr noundef, i64 noundef) #2

declare void @_ZN3TED11renderSoundEjPs(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, ptr 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 504}
!14 = !{!"_ZTSN6SoLoud14TedSidInstanceE", !15, i64 0, !6, i64 496, !6, i64 504, !6, i64 512, !10, i64 520, !10, i64 524, !7, i64 528}
!15 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !10, i64 8, !10, i64 12, !10, i64 16, !16, i64 20, !7, i64 24, !16, i64 56, !16, i64 60, !16, i64 64, !16, i64 68, !10, i64 72, !16, i64 76, !16, i64 80, !17, i64 88, !17, i64 96, !18, i64 104, !18, i64 152, !18, i64 200, !18, i64 248, !18, 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, !17, i64 488}
!16 = !{!"float", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!"_ZTSN6SoLoud5FaderE", !16, i64 0, !16, i64 4, !16, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !16, i64 40, !10, i64 44}
!19 = !{!20, !20, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!14, !6, i64 512}
!22 = !{!16, !16, i64 0}
!23 = !{!14, !10, i64 524}
!24 = distinct !{!24, !25}
!25 = !{!"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
define dso_local noundef i32 @_ZN6SoLoud14TedSidInstance8getAudioEPfjj(ptr noundef nonnull align 8 dereferenceable(1040) %0, ptr nocapture noundef writeonly %1, i32 noundef returned %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 504
  %8 = getelementptr inbounds i8, ptr %0, i64 512
  %9 = getelementptr inbounds i8, ptr %0, i64 524
  %wide.trip.count = zext i32 %2 to i64
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 56
  %13 = load ptr, ptr %12, align 8
  call void %13(ptr noundef nonnull align 8 dereferenceable(1040) %0)
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !8
  call void @_ZN8SIDsound11calcSamplesEPsl(ptr noundef nonnull align 8 dereferenceable(16796) %14, ptr noundef nonnull %5, i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #3
  store i16 0, ptr %6, align 2, !tbaa !17
  %15 = load ptr, ptr %8, align 8, !tbaa !19
  call void @_ZN3TED11renderSoundEjPs(ptr noundef nonnull align 4 dereferenceable(352) %15, i32 noundef 1, ptr noundef nonnull %6)
  %16 = load i16, ptr %5, align 2, !tbaa !17
  %17 = sext i16 %16 to i32
  %18 = load i16, ptr %6, align 2, !tbaa !17
  %19 = sext i16 %18 to i32
  %20 = add nsw i32 %19, %17
  %21 = sitofp i32 %20 to float
  %22 = fmul float %21, 0x3F20000000000000
  %23 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %22, ptr %23, align 4, !tbaa !20
  %24 = load i32, ptr %9, align 4, !tbaa !21
  %25 = add i32 %24, -1
  store i32 %25, ptr %9, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !22

._crit_edge:                                      ; preds = %10, %4
  ret i32 %2
}

declare void @_ZN8SIDsound11calcSamplesEPsl(ptr noundef nonnull align 8 dereferenceable(16796), ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @_ZN3TED11renderSoundEjPs(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, ptr noundef) 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !16, i64 504}
!9 = !{!"_ZTSN6SoLoud14TedSidInstanceE", !10, i64 0, !16, i64 496, !16, i64 504, !16, i64 512, !11, i64 520, !11, i64 524, !12, i64 528}
!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 = !{!18, !18, i64 0}
!18 = !{!"short", !12, i64 0}
!19 = !{!9, !16, i64 512}
!20 = !{!13, !13, i64 0}
!21 = !{!9, !11, i64 524}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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