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

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

%struct.drmp3 = type { %struct.drmp3dec, %struct.drmp3dec_frame_info, i32, i32, ptr, ptr, ptr, %struct.drmp3_allocation_callbacks, i32, i32, i32, i32, [9216 x i8], i64, i64, ptr, i32, i64, i64, i64, ptr, i8, %struct.anon.1 }
%struct.drmp3dec = type { [2 x [288 x float]], [960 x float], i32, i32, [4 x i8], [511 x i8] }
%struct.drmp3dec_frame_info = type { i32, i32, i32, i32, i32 }
%struct.drmp3_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.anon.1 = type { ptr, i64, i64 }
%"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::WavStream" = type <{ %"class.SoLoud::AudioSource", i32, [4 x i8], ptr, ptr, ptr, 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
declare dso_local noundef i64 @_ZN6SoLoud15drmp3_read_funcEPvS0_m(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud15drmp3_seek_funcEPvi17drmp3_seek_origin(ptr noundef, i32 noundef, i32 noundef) #1

declare i32 @drmp3_init(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @drmp3_uninit(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud9WavStream7loadmp3EPNS_4FileE(ptr noundef nonnull align 8 dereferenceable(188) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.drmp3, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds ptr, ptr %11, i64 5
  %13 = load ptr, ptr %12, align 8
  call void %13(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 16080, ptr %6) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @drmp3_init(ptr noundef %6, ptr noundef @_ZN6SoLoud15drmp3_read_funcEPvS0_m, ptr noundef @_ZN6SoLoud15drmp3_seek_funcEPvi17drmp3_seek_origin, ptr noundef %14, ptr noundef null)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %2
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %37

18:                                               ; preds = %2
  %19 = getelementptr inbounds %struct.drmp3, ptr %6, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %9, i32 0, i32 4
  store i32 %20, ptr %21, align 4, !tbaa !20
  %22 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %9, i32 0, i32 4
  %23 = load i32, ptr %22, align 4, !tbaa !20
  %24 = icmp ugt i32 %23, 8
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %9, i32 0, i32 4
  store i32 8, ptr %26, align 4, !tbaa !20
  br label %27

27:                                               ; preds = %25, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %28 = call i64 @drmp3_get_pcm_frame_count(ptr noundef %6)
  store i64 %28, ptr %8, align 8, !tbaa !24
  %29 = getelementptr inbounds %struct.drmp3, ptr %6, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !25
  %31 = uitofp i32 %30 to float
  %32 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %9, i32 0, i32 2
  store float %31, ptr %32, align 4, !tbaa !26
  %33 = load i64, ptr %8, align 8, !tbaa !24
  %34 = trunc i64 %33 to i32
  %35 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %9, i32 0, i32 6
  store i32 %34, ptr %35, align 8, !tbaa !27
  %36 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %9, i32 0, i32 1
  store i32 3, ptr %36, align 8, !tbaa !29
  call void @drmp3_uninit(ptr noundef %6)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %37

37:                                               ; preds = %27, %17
  call void @llvm.lifetime.end.p0(i64 16080, ptr %6) #3
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

declare i64 @drmp3_get_pcm_frame_count(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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !14, i64 6688}
!12 = !{!"_ZTS5drmp3", !13, i64 0, !15, i64 6668, !14, i64 6688, !14, i64 6692, !6, i64 6696, !6, i64 6704, !6, i64 6712, !16, i64 6720, !14, i64 6752, !14, i64 6756, !14, i64 6760, !14, i64 6764, !7, i64 6768, !17, i64 15984, !17, i64 15992, !6, i64 16000, !14, i64 16008, !18, i64 16016, !18, i64 16024, !18, i64 16032, !6, i64 16040, !14, i64 16048, !19, i64 16056}
!13 = !{!"_ZTS8drmp3dec", !7, i64 0, !7, i64 2304, !14, i64 6144, !14, i64 6148, !7, i64 6152, !7, i64 6156}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS19drmp3dec_frame_info", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16}
!16 = !{!"_ZTS26drmp3_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSN5drmp3Ut_E", !6, i64 0, !18, i64 8, !18, i64 16}
!20 = !{!21, !14, i64 20}
!21 = !{!"_ZTSN6SoLoud11AudioSourceE", !14, i64 8, !22, i64 12, !22, i64 16, !14, i64 20, !14, i64 24, !22, i64 28, !22, i64 32, !22, i64 36, !14, i64 40, !22, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !14, i64 136, !23, i64 144}
!22 = !{!"float", !7, i64 0}
!23 = !{!"double", !7, i64 0}
!24 = !{!17, !17, i64 0}
!25 = !{!12, !14, i64 6692}
!26 = !{!21, !22, i64 12}
!27 = !{!28, !14, i64 184}
!28 = !{!"_ZTSN6SoLoud9WavStreamE", !21, i64 0, !14, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !14, i64 184}
!29 = !{!28, !14, i64 152}


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

%struct.drmp3 = type { %struct.drmp3dec, %struct.drmp3dec_frame_info, i32, i32, ptr, ptr, ptr, %struct.drmp3_allocation_callbacks, i32, i32, i32, i32, [9216 x i8], i64, i64, ptr, i32, i64, i64, i64, ptr, i8, %struct.anon.1 }
%struct.drmp3dec = type { [2 x [288 x float]], [960 x float], i32, i32, [4 x i8], [511 x i8] }
%struct.drmp3dec_frame_info = type { i32, i32, i32, i32, i32 }
%struct.drmp3_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.anon.1 = type { ptr, i64, i64 }

; 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
declare dso_local noundef i64 @_ZN6SoLoud15drmp3_read_funcEPvS0_m(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud15drmp3_seek_funcEPvi17drmp3_seek_origin(ptr noundef, i32 noundef, i32 noundef) #1

declare i32 @drmp3_init(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @drmp3_uninit(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_ZN6SoLoud9WavStream7loadmp3EPNS_4FileE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(188) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %struct.drmp3, align 8
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load ptr, ptr %5, align 8
  tail call void %6(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 16080, ptr nonnull %3) #4
  %7 = call i32 @drmp3_init(ptr noundef nonnull %3, ptr noundef nonnull @_ZN6SoLoud15drmp3_read_funcEPvS0_m, ptr noundef nonnull @_ZN6SoLoud15drmp3_seek_funcEPvi17drmp3_seek_origin, ptr noundef nonnull %1, ptr noundef null)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %20, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 6688
  %10 = load i32, ptr %9, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %spec.select = call i32 @llvm.umin.i32(i32 %10, i32 8)
  store i32 %spec.select, ptr %11, align 4, !tbaa !19
  %12 = call i64 @drmp3_get_pcm_frame_count(ptr noundef nonnull %3)
  %13 = getelementptr inbounds i8, ptr %3, i64 6692
  %14 = load i32, ptr %13, align 4, !tbaa !23
  %15 = uitofp i32 %14 to float
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  store float %15, ptr %16, align 4, !tbaa !24
  %17 = trunc i64 %12 to i32
  %18 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %17, ptr %18, align 8, !tbaa !25
  %19 = getelementptr inbounds i8, ptr %0, i64 152
  store i32 3, ptr %19, align 8, !tbaa !27
  call void @drmp3_uninit(ptr noundef nonnull %3)
  br label %20

20:                                               ; preds = %2, %8
  %.0 = phi i32 [ 0, %8 ], [ 3, %2 ]
  call void @llvm.lifetime.end.p0(i64 16080, ptr nonnull %3) #4
  ret i32 %.0
}

declare i64 @drmp3_get_pcm_frame_count(ptr noundef) local_unnamed_addr #2

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 6688}
!9 = !{!"_ZTS5drmp3", !10, i64 0, !13, i64 6668, !12, i64 6688, !12, i64 6692, !14, i64 6696, !14, i64 6704, !14, i64 6712, !15, i64 6720, !12, i64 6752, !12, i64 6756, !12, i64 6760, !12, i64 6764, !11, i64 6768, !16, i64 15984, !16, i64 15992, !14, i64 16000, !12, i64 16008, !17, i64 16016, !17, i64 16024, !17, i64 16032, !14, i64 16040, !12, i64 16048, !18, i64 16056}
!10 = !{!"_ZTS8drmp3dec", !11, i64 0, !11, i64 2304, !12, i64 6144, !12, i64 6148, !11, i64 6152, !11, i64 6156}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"int", !11, i64 0}
!13 = !{!"_ZTS19drmp3dec_frame_info", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"_ZTS26drmp3_allocation_callbacks", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!16 = !{!"long long", !11, i64 0}
!17 = !{!"long", !11, i64 0}
!18 = !{!"_ZTSN5drmp3Ut_E", !14, i64 0, !17, i64 8, !17, i64 16}
!19 = !{!20, !12, i64 20}
!20 = !{!"_ZTSN6SoLoud11AudioSourceE", !12, i64 8, !21, i64 12, !21, i64 16, !12, i64 20, !12, i64 24, !21, i64 28, !21, i64 32, !21, i64 36, !12, i64 40, !21, i64 44, !11, i64 48, !14, i64 112, !14, i64 120, !14, i64 128, !12, i64 136, !22, i64 144}
!21 = !{!"float", !11, i64 0}
!22 = !{!"double", !11, i64 0}
!23 = !{!9, !12, i64 6692}
!24 = !{!20, !21, i64 12}
!25 = !{!26, !12, i64 184}
!26 = !{!"_ZTSN6SoLoud9WavStreamE", !20, i64 0, !12, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !12, i64 184}
!27 = !{!26, !12, i64 152}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass