; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/wav (soloud_wav)

; 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::WavInstance" = type <{ %"class.SoLoud::AudioSourceInstance", ptr, 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::Fader" = type { float, float, float, double, double, double, float, i32 }
%"class.SoLoud::Wav" = type <{ %"class.SoLoud::AudioSource", 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 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN6SoLoud11WavInstance8getAudioEPfjj(ptr noundef nonnull align 8 dereferenceable(508) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  %14 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %"class.SoLoud::Wav", ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %75

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %21 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %"class.SoLoud::Wav", ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !21
  %27 = sub i32 %24, %26
  store i32 %27, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %28 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %28, ptr %11, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp ugt i32 %29, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %20
  %33 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %33, ptr %11, align 4, !tbaa !9
  br label %34

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

35:                                               ; preds = %66, %34
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %13, i32 0, i32 10
  %38 = load i32, ptr %37, align 8, !tbaa !22
  %39 = icmp ult i32 %36, %38
  br i1 %39, label %40, label %69

40:                                               ; preds = %35
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %41, i64 %45
  %47 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds %"class.SoLoud::Wav", ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !21
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %50, i64 %53
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %"class.SoLoud::Wav", ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !20
  %60 = mul i32 %55, %59
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds float, ptr %54, i64 %61
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = mul i64 4, %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %46, ptr align 4 %62, i64 %65, i1 false)
  br label %66

66:                                               ; preds = %40
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %12, align 4, !tbaa !9
  br label %35, !llvm.loop !23

69:                                               ; preds = %35
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = getelementptr inbounds %"class.SoLoud::WavInstance", ptr %13, i32 0, i32 2
  %72 = load i32, ptr %71, align 8, !tbaa !21
  %73 = add i32 %72, %70
  store i32 %73, ptr %71, align 8, !tbaa !21
  %74 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %74, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %75

75:                                               ; preds = %69, %19
  %76 = load i32, ptr %5, align 4
  ret i32 %76
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

attributes #0 = { mustprogress nounwind 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 496}
!12 = !{!"_ZTSN6SoLoud11WavInstanceE", !13, i64 0, !6, i64 496, !10, i64 504}
!13 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !10, i64 8, !10, i64 12, !10, i64 16, !14, i64 20, !7, i64 24, !14, i64 56, !14, i64 60, !14, i64 64, !14, i64 68, !10, i64 72, !14, i64 76, !14, i64 80, !15, i64 88, !15, i64 96, !16, i64 104, !16, i64 152, !16, i64 200, !16, i64 248, !16, 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, !15, i64 488}
!14 = !{!"float", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_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}
!17 = !{!18, !6, i64 152}
!18 = !{!"_ZTSN6SoLoud3WavE", !19, i64 0, !6, i64 152, !10, i64 160}
!19 = !{!"_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}
!20 = !{!18, !10, i64 160}
!21 = !{!12, !10, i64 504}
!22 = !{!13, !10, i64 72}
!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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN6SoLoud11WavInstance8getAudioEPfjj(ptr nocapture noundef nonnull align 8 dereferenceable(508) %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 496
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 152
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = icmp eq ptr %8, null
  br i1 %9, label %41, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %6, i64 160
  %12 = load i32, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %0, i64 504
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = sub i32 %12, %14
  %spec.select = tail call i32 @llvm.umin.i32(i32 %15, i32 %2)
  %16 = getelementptr inbounds i8, ptr %0, i64 72
  %17 = load i32, ptr %16, align 8, !tbaa !20
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %18 = zext i32 %spec.select to i64
  %19 = shl nuw nsw i64 %18, 2
  br label %20

20:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %21 = trunc nuw i64 %indvars.iv to i32
  %22 = mul i32 %21, %3
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %1, i64 %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 152
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %13, align 8, !tbaa !19
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  %31 = getelementptr inbounds i8, ptr %25, i64 160
  %32 = load i32, ptr %31, align 8, !tbaa !18
  %33 = mul i32 %32, %21
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds float, ptr %30, i64 %34
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %35, i64 %19, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = load i32, ptr %16, align 8, !tbaa !20
  %37 = zext i32 %36 to i64
  %38 = icmp ult i64 %indvars.iv.next, %37
  br i1 %38, label %20, label %._crit_edge.loopexit, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %20
  %.pre = load i32, ptr %13, align 8, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %10
  %39 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %14, %10 ]
  %40 = add i32 %39, %spec.select
  store i32 %40, ptr %13, align 8, !tbaa !19
  br label %41

41:                                               ; preds = %4, %._crit_edge
  %.015 = phi i32 [ %spec.select, %._crit_edge ], [ 0, %4 ]
  ret i32 %.015
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !14, i64 496}
!6 = !{!"_ZTSN6SoLoud11WavInstanceE", !7, i64 0, !14, i64 496, !8, i64 504}
!7 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !8, i64 8, !8, i64 12, !8, i64 16, !11, i64 20, !9, i64 24, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !8, i64 72, !11, i64 76, !11, i64 80, !12, i64 88, !12, i64 96, !13, i64 104, !13, i64 152, !13, i64 200, !13, i64 248, !13, i64 296, !8, i64 344, !9, i64 348, !8, i64 380, !8, i64 384, !9, i64 392, !9, i64 456, !8, i64 472, !8, i64 476, !8, i64 480, !12, i64 488}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"double", !9, i64 0}
!13 = !{!"_ZTSN6SoLoud5FaderE", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !8, i64 44}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!16, !14, i64 152}
!16 = !{!"_ZTSN6SoLoud3WavE", !17, i64 0, !14, i64 152, !8, i64 160}
!17 = !{!"_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, !14, i64 112, !14, i64 120, !14, i64 128, !8, i64 136, !12, i64 144}
!18 = !{!16, !8, i64 160}
!19 = !{!6, !8, i64 504}
!20 = !{!7, !8, i64 72}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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