; 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.drwav = type { ptr, ptr, ptr, ptr, %struct.drwav_allocation_callbacks, i32, %struct.drwav_fmt, i32, i16, i16, i16, i64, i64, i64, i64, i64, i64, i32, i32, ptr, i32, %struct.drwav__memory_stream, %struct.drwav__memory_stream_write, %struct.anon, %struct.anon.0 }
%struct.drwav_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drwav_fmt = type { i16, i16, i32, i32, i16, i16, i16, i16, i32, [16 x i8] }
%struct.drwav__memory_stream = type { ptr, i64, i64 }
%struct.drwav__memory_stream_write = type { ptr, ptr, i64, i64, i64 }
%struct.anon = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.0 = type { i32, [2 x i32], [2 x i32], [16 x i32], i32 }
%"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 @_ZN6SoLoud15drwav_read_funcEPvS0_m(ptr noundef, ptr noundef, i64 noundef) #1

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

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

declare i32 @drwav_uninit(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud9WavStream7loadwavEPNS_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.drwav, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds ptr, ptr %10, i64 5
  %12 = load ptr, ptr %11, align 8
  call void %12(ptr noundef nonnull align 8 dereferenceable(8) %9, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 400, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @drwav_init(ptr noundef %6, ptr noundef @_ZN6SoLoud15drwav_read_funcEPvS0_m, ptr noundef @_ZN6SoLoud15drwav_seek_funcEPvi17drwav_seek_origin, ptr noundef %13, ptr noundef null)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %17, label %16

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

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

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

27:                                               ; preds = %25, %17
  %28 = getelementptr inbounds %struct.drwav, ptr %6, i32 0, i32 7
  %29 = load i32, ptr %28, align 4, !tbaa !29
  %30 = uitofp i32 %29 to float
  %31 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 2
  store float %30, ptr %31, align 4, !tbaa !30
  %32 = getelementptr inbounds %struct.drwav, ptr %6, i32 0, i32 11
  %33 = load i64, ptr %32, align 8, !tbaa !31
  %34 = trunc i64 %33 to i32
  %35 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %8, i32 0, i32 6
  store i32 %34, ptr %35, align 8, !tbaa !32
  %36 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %8, i32 0, i32 1
  store i32 0, ptr %36, align 8, !tbaa !34
  %37 = call i32 @drwav_uninit(ptr noundef %6)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %38

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

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, !16, i64 112}
!12 = !{!"_ZTS5drwav", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !14, i64 64, !15, i64 68, !17, i64 108, !16, i64 112, !16, i64 114, !16, i64 116, !18, i64 120, !18, i64 128, !18, i64 136, !18, i64 144, !18, i64 152, !18, i64 160, !17, i64 168, !19, i64 172, !6, i64 176, !17, i64 184, !20, i64 192, !22, i64 216, !23, i64 256, !24, i64 308}
!13 = !{!"_ZTS26drwav_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"_ZTS15drwav_container", !7, i64 0}
!15 = !{!"_ZTS9drwav_fmt", !16, i64 0, !16, i64 2, !17, i64 4, !17, i64 8, !16, i64 12, !16, i64 14, !16, i64 16, !16, i64 18, !17, i64 20, !7, i64 24}
!16 = !{!"short", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!"_ZTS19drwav_metadata_type", !7, i64 0}
!20 = !{!"_ZTS20drwav__memory_stream", !6, i64 0, !21, i64 8, !21, i64 16}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTS26drwav__memory_stream_write", !6, i64 0, !6, i64 8, !21, i64 16, !21, i64 24, !21, i64 32}
!23 = !{!"_ZTSN5drwavUt_E", !17, i64 0, !7, i64 4, !7, i64 8, !7, i64 16, !17, i64 32, !7, i64 36}
!24 = !{!"_ZTSN5drwavUt0_E", !17, i64 0, !7, i64 4, !7, i64 12, !7, i64 20, !17, i64 84}
!25 = !{!26, !17, i64 20}
!26 = !{!"_ZTSN6SoLoud11AudioSourceE", !17, i64 8, !27, i64 12, !27, i64 16, !17, i64 20, !17, i64 24, !27, i64 28, !27, i64 32, !27, i64 36, !17, i64 40, !27, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !17, i64 136, !28, i64 144}
!27 = !{!"float", !7, i64 0}
!28 = !{!"double", !7, i64 0}
!29 = !{!12, !17, i64 108}
!30 = !{!26, !27, i64 12}
!31 = !{!12, !18, i64 120}
!32 = !{!33, !17, i64 184}
!33 = !{!"_ZTSN6SoLoud9WavStreamE", !26, i64 0, !17, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !17, i64 184}
!34 = !{!33, !17, 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.drwav = type { ptr, ptr, ptr, ptr, %struct.drwav_allocation_callbacks, i32, %struct.drwav_fmt, i32, i16, i16, i16, i64, i64, i64, i64, i64, i64, i32, i32, ptr, i32, %struct.drwav__memory_stream, %struct.drwav__memory_stream_write, %struct.anon, %struct.anon.0 }
%struct.drwav_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drwav_fmt = type { i16, i16, i32, i32, i16, i16, i16, i16, i32, [16 x i8] }
%struct.drwav__memory_stream = type { ptr, i64, i64 }
%struct.drwav__memory_stream_write = type { ptr, ptr, i64, i64, i64 }
%struct.anon = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.0 = type { i32, [2 x i32], [2 x i32], [16 x i32], i32 }

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

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

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

declare i32 @drwav_uninit(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_ZN6SoLoud9WavStream7loadwavEPNS_4FileE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(188) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %struct.drwav, 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 400, ptr nonnull %3) #4
  %7 = call i32 @drwav_init(ptr noundef nonnull %3, ptr noundef nonnull @_ZN6SoLoud15drwav_read_funcEPvS0_m, ptr noundef nonnull @_ZN6SoLoud15drwav_seek_funcEPvi17drwav_seek_origin, ptr noundef nonnull %1, ptr noundef null)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %22, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 112
  %10 = load i16, ptr %9, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %narrow = call i16 @llvm.umin.i16(i16 %10, i16 8)
  %spec.select = zext nneg i16 %narrow to i32
  store i32 %spec.select, ptr %11, align 4, !tbaa !24
  %12 = getelementptr inbounds i8, ptr %3, i64 108
  %13 = load i32, ptr %12, align 4, !tbaa !28
  %14 = uitofp i32 %13 to float
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  store float %14, ptr %15, align 4, !tbaa !29
  %16 = getelementptr inbounds i8, ptr %3, i64 120
  %17 = load i64, ptr %16, align 8, !tbaa !30
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %18, ptr %19, align 8, !tbaa !31
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  store i32 0, ptr %20, align 8, !tbaa !33
  %21 = call i32 @drwav_uninit(ptr noundef nonnull %3)
  br label %22

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #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, !15, i64 112}
!9 = !{!"_ZTS5drwav", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !13, i64 64, !14, i64 68, !16, i64 108, !15, i64 112, !15, i64 114, !15, i64 116, !17, i64 120, !17, i64 128, !17, i64 136, !17, i64 144, !17, i64 152, !17, i64 160, !16, i64 168, !18, i64 172, !10, i64 176, !16, i64 184, !19, i64 192, !21, i64 216, !22, i64 256, !23, i64 308}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"_ZTS26drwav_allocation_callbacks", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!"_ZTS15drwav_container", !11, i64 0}
!14 = !{!"_ZTS9drwav_fmt", !15, i64 0, !15, i64 2, !16, i64 4, !16, i64 8, !15, i64 12, !15, i64 14, !15, i64 16, !15, i64 18, !16, i64 20, !11, i64 24}
!15 = !{!"short", !11, i64 0}
!16 = !{!"int", !11, i64 0}
!17 = !{!"long long", !11, i64 0}
!18 = !{!"_ZTS19drwav_metadata_type", !11, i64 0}
!19 = !{!"_ZTS20drwav__memory_stream", !10, i64 0, !20, i64 8, !20, i64 16}
!20 = !{!"long", !11, i64 0}
!21 = !{!"_ZTS26drwav__memory_stream_write", !10, i64 0, !10, i64 8, !20, i64 16, !20, i64 24, !20, i64 32}
!22 = !{!"_ZTSN5drwavUt_E", !16, i64 0, !11, i64 4, !11, i64 8, !11, i64 16, !16, i64 32, !11, i64 36}
!23 = !{!"_ZTSN5drwavUt0_E", !16, i64 0, !11, i64 4, !11, i64 12, !11, i64 20, !16, i64 84}
!24 = !{!25, !16, i64 20}
!25 = !{!"_ZTSN6SoLoud11AudioSourceE", !16, i64 8, !26, i64 12, !26, i64 16, !16, i64 20, !16, i64 24, !26, i64 28, !26, i64 32, !26, i64 36, !16, i64 40, !26, i64 44, !11, i64 48, !10, i64 112, !10, i64 120, !10, i64 128, !16, i64 136, !27, i64 144}
!26 = !{!"float", !11, i64 0}
!27 = !{!"double", !11, i64 0}
!28 = !{!9, !16, i64 108}
!29 = !{!25, !26, i64 12}
!30 = !{!9, !17, i64 120}
!31 = !{!32, !16, i64 184}
!32 = !{!"_ZTSN6SoLoud9WavStreamE", !25, i64 0, !16, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !16, i64 184}
!33 = !{!32, !16, i64 152}


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