; 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.drflac = type { ptr, ptr, %struct.drflac_allocation_callbacks, i32, i8, i8, i16, i64, i32, i32, %struct.drflac_frame, i64, i64, %struct.drflac__memory_stream, ptr, ptr, ptr, i8, %struct.drflac_bs, [1 x i8] }
%struct.drflac_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drflac_frame = type { %struct.drflac_frame_header, i32, [8 x %struct.drflac_subframe] }
%struct.drflac_frame_header = type { i64, i32, i32, i16, i8, i8, i8 }
%struct.drflac_subframe = type { i8, i8, i8, ptr }
%struct.drflac__memory_stream = type { ptr, i64, i64 }
%struct.drflac_bs = type { ptr, ptr, ptr, i64, i64, i32, i32, [512 x i64], i64, i16, i64, 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: mustprogress uwtable
declare dso_local noundef i64 @_ZN6SoLoud16drflac_read_funcEPvS0_m(ptr noundef, ptr noundef, i64 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

declare ptr @drflac_open(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @drflac_close(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud9WavStream8loadflacEPNS_4FileE(ptr noundef nonnull align 8 dereferenceable(188) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, 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 8, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call ptr @drflac_open(ptr noundef @_ZN6SoLoud16drflac_read_funcEPvS0_m, ptr noundef @_ZN6SoLoud16drflac_seek_funcEPvi18drflac_seek_origin, ptr noundef %13, ptr noundef null)
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

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

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

27:                                               ; preds = %18
  %28 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 4
  store i32 8, ptr %28, align 4, !tbaa !23
  br label %29

29:                                               ; preds = %27, %18
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.drflac, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 8, !tbaa !27
  %33 = uitofp i32 %32 to float
  %34 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %8, i32 0, i32 2
  store float %33, ptr %34, align 4, !tbaa !28
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.drflac, ptr %35, i32 0, i32 7
  %37 = load i64, ptr %36, align 8, !tbaa !29
  %38 = trunc i64 %37 to i32
  %39 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %8, i32 0, i32 6
  store i32 %38, ptr %39, align 8, !tbaa !30
  %40 = getelementptr inbounds %"class.SoLoud::WavStream", ptr %8, i32 0, i32 1
  store i32 2, ptr %40, align 8, !tbaa !32
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  call void @drflac_close(ptr noundef %41)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %42

42:                                               ; preds = %29, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %43 = load i32, ptr %3, align 4
  ret i32 %43
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 52}
!12 = !{!"_ZTS6drflac", !6, i64 0, !6, i64 8, !13, i64 16, !14, i64 48, !7, i64 52, !7, i64 53, !15, i64 54, !16, i64 56, !17, i64 64, !14, i64 68, !18, i64 72, !16, i64 232, !16, i64 240, !20, i64 248, !6, i64 272, !6, i64 280, !6, i64 288, !14, i64 296, !14, i64 296, !14, i64 296, !22, i64 304, !7, i64 4480}
!13 = !{!"_ZTS27drflac_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"int", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"_ZTS16drflac_container", !7, i64 0}
!18 = !{!"_ZTS12drflac_frame", !19, i64 0, !14, i64 24, !7, i64 32}
!19 = !{!"_ZTS19drflac_frame_header", !16, i64 0, !14, i64 8, !14, i64 12, !15, i64 16, !7, i64 18, !7, i64 19, !7, i64 20}
!20 = !{!"_ZTS21drflac__memory_stream", !6, i64 0, !21, i64 8, !21, i64 16}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTS9drflac_bs", !6, i64 0, !6, i64 8, !6, i64 16, !21, i64 24, !16, i64 32, !14, i64 40, !14, i64 44, !7, i64 48, !16, i64 4144, !15, i64 4152, !16, i64 4160, !14, i64 4168}
!23 = !{!24, !14, i64 20}
!24 = !{!"_ZTSN6SoLoud11AudioSourceE", !14, i64 8, !25, i64 12, !25, i64 16, !14, i64 20, !14, i64 24, !25, i64 28, !25, i64 32, !25, i64 36, !14, i64 40, !25, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !14, i64 136, !26, i64 144}
!25 = !{!"float", !7, i64 0}
!26 = !{!"double", !7, i64 0}
!27 = !{!12, !14, i64 48}
!28 = !{!24, !25, i64 12}
!29 = !{!12, !16, i64 56}
!30 = !{!31, !14, i64 184}
!31 = !{!"_ZTSN6SoLoud9WavStreamE", !24, i64 0, !14, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !14, i64 184}
!32 = !{!31, !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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN6SoLoud16drflac_read_funcEPvS0_m(ptr noundef, ptr noundef, i64 noundef) #0

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

declare ptr @drflac_open(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @drflac_close(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_ZN6SoLoud9WavStream8loadflacEPNS_4FileE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(188) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = load ptr, ptr %4, align 8
  tail call void %5(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 0)
  %6 = tail call ptr @drflac_open(ptr noundef nonnull @_ZN6SoLoud16drflac_read_funcEPvS0_m, ptr noundef nonnull @_ZN6SoLoud16drflac_seek_funcEPvi18drflac_seek_origin, ptr noundef nonnull %1, ptr noundef null)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %21, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %6, i64 52
  %10 = load i8, ptr %9, align 4, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %narrow = tail call i8 @llvm.umin.i8(i8 %10, i8 8)
  %spec.select = zext nneg i8 %narrow to i32
  store i32 %spec.select, ptr %11, align 4, !tbaa !22
  %12 = getelementptr inbounds i8, ptr %6, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !26
  %14 = uitofp i32 %13 to float
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  store float %14, ptr %15, align 4, !tbaa !27
  %16 = getelementptr inbounds i8, ptr %6, i64 56
  %17 = load i64, ptr %16, align 8, !tbaa !28
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %18, ptr %19, align 8, !tbaa !29
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  store i32 2, ptr %20, align 8, !tbaa !31
  tail call void @drflac_close(ptr noundef nonnull %6)
  br label %21

21:                                               ; preds = %2, %8
  %.0 = phi i32 [ 0, %8 ], [ 3, %2 ]
  ret i32 %.0
}

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

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 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, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 52}
!9 = !{!"_ZTS6drflac", !10, i64 0, !10, i64 8, !12, i64 16, !13, i64 48, !11, i64 52, !11, i64 53, !14, i64 54, !15, i64 56, !16, i64 64, !13, i64 68, !17, i64 72, !15, i64 232, !15, i64 240, !19, i64 248, !10, i64 272, !10, i64 280, !10, i64 288, !13, i64 296, !13, i64 296, !13, i64 296, !21, i64 304, !11, i64 4480}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"_ZTS27drflac_allocation_callbacks", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!"int", !11, i64 0}
!14 = !{!"short", !11, i64 0}
!15 = !{!"long long", !11, i64 0}
!16 = !{!"_ZTS16drflac_container", !11, i64 0}
!17 = !{!"_ZTS12drflac_frame", !18, i64 0, !13, i64 24, !11, i64 32}
!18 = !{!"_ZTS19drflac_frame_header", !15, i64 0, !13, i64 8, !13, i64 12, !14, i64 16, !11, i64 18, !11, i64 19, !11, i64 20}
!19 = !{!"_ZTS21drflac__memory_stream", !10, i64 0, !20, i64 8, !20, i64 16}
!20 = !{!"long", !11, i64 0}
!21 = !{!"_ZTS9drflac_bs", !10, i64 0, !10, i64 8, !10, i64 16, !20, i64 24, !15, i64 32, !13, i64 40, !13, i64 44, !11, i64 48, !15, i64 4144, !14, i64 4152, !15, i64 4160, !13, i64 4168}
!22 = !{!23, !13, i64 20}
!23 = !{!"_ZTSN6SoLoud11AudioSourceE", !13, i64 8, !24, i64 12, !24, i64 16, !13, i64 20, !13, i64 24, !24, i64 28, !24, i64 32, !24, i64 36, !13, i64 40, !24, i64 44, !11, i64 48, !10, i64 112, !10, i64 120, !10, i64 128, !13, i64 136, !25, i64 144}
!24 = !{!"float", !11, i64 0}
!25 = !{!"double", !11, i64 0}
!26 = !{!9, !13, i64 48}
!27 = !{!23, !24, i64 12}
!28 = !{!9, !15, i64 56}
!29 = !{!30, !13, i64 184}
!30 = !{!"_ZTSN6SoLoud9WavStreamE", !23, i64 0, !13, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !13, i64 184}
!31 = !{!30, !13, i64 152}


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