; LLVM IR from merpheus-dev/LavaEngine :: src/Utils/soloud/src/audiosource/wav (dr_impl)

; 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, i32, %struct.drwav_smpl, %struct.drwav__memory_stream, %struct.drwav__memory_stream_write, %struct.anon.1, %struct.anon.2, %struct.anon.3 }
%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_smpl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [1 x %struct.drwav_smpl_loop] }
%struct.drwav_smpl_loop = type { i32, i32, i32, i32, i32, i32 }
%struct.drwav__memory_stream = type { ptr, i64, i64 }
%struct.drwav__memory_stream_write = type { ptr, ptr, i64, i64, i64 }
%struct.anon.1 = type { i64 }
%struct.anon.2 = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.3 = type { i32, [2 x i32], [2 x i32], [16 x i32], i32 }

@.str.16 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._Z36drwav__read_pcm_frames_and_close_s16P5drwavPjS1_Pm = external hidden unnamed_addr constant [107 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local i32 @drwav_uninit(ptr noundef) #2

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

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

16:                                               ; preds = %4
  br label %19

17:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.29, ptr noundef @.str.16, i32 noundef 4665, ptr noundef @__PRETTY_FUNCTION__._Z36drwav__read_pcm_frames_and_close_s16P5drwavPjS1_Pm) #4
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.drwav, ptr %20, i32 0, i32 11
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.drwav, ptr %23, i32 0, i32 8
  %25 = load i16, ptr %24, align 8, !tbaa !23
  %26 = zext i16 %25 to i64
  %27 = mul i64 %22, %26
  %28 = mul i64 %27, 2
  store i64 %28, ptr %10, align 8, !tbaa !24
  %29 = load i64, ptr %10, align 8, !tbaa !24
  %30 = icmp ugt i64 %29, -1
  br i1 %30, label %31, label %34

31:                                               ; preds = %19
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i32 @drwav_uninit(ptr noundef %32)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %91

34:                                               ; preds = %19
  %35 = load i64, ptr %10, align 8, !tbaa !24
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.drwav, ptr %36, i32 0, i32 4
  %38 = call noundef ptr @_ZL28drwav__malloc_from_callbacksmPK26drwav_allocation_callbacks(i64 noundef %35, ptr noundef %37)
  store ptr %38, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %34
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @drwav_uninit(ptr noundef %42)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %91

44:                                               ; preds = %34
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.drwav, ptr %46, i32 0, i32 11
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = call i64 @drwav_read_pcm_frames_s16(ptr noundef %45, i64 noundef %48, ptr noundef %49)
  store i64 %50, ptr %12, align 8, !tbaa !24
  %51 = load i64, ptr %12, align 8, !tbaa !24
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.drwav, ptr %52, i32 0, i32 11
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = icmp ne i64 %51, %54
  br i1 %55, label %56, label %62

56:                                               ; preds = %44
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.drwav, ptr %58, i32 0, i32 4
  call void @_ZL26drwav__free_from_callbacksPvPK26drwav_allocation_callbacks(ptr noundef %57, ptr noundef %59)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call i32 @drwav_uninit(ptr noundef %60)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %91

62:                                               ; preds = %44
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = call i32 @drwav_uninit(ptr noundef %63)
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %72

67:                                               ; preds = %62
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.drwav, ptr %68, i32 0, i32 7
  %70 = load i32, ptr %69, align 4, !tbaa !25
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !26
  br label %72

72:                                               ; preds = %67, %62
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %81

75:                                               ; preds = %72
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.drwav, ptr %76, i32 0, i32 8
  %78 = load i16, ptr %77, align 8, !tbaa !23
  %79 = zext i16 %78 to i32
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !26
  br label %81

81:                                               ; preds = %75, %72
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %89

84:                                               ; preds = %81
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.drwav, ptr %85, i32 0, i32 11
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %87, ptr %88, align 8, !tbaa !24
  br label %89

89:                                               ; preds = %84, %81
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %90, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %91

91:                                               ; preds = %89, %56, %41, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %92 = load ptr, ptr %5, align 8
  ret ptr %92
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL28drwav__malloc_from_callbacksmPK26drwav_allocation_callbacks(i64 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL26drwav__free_from_callbacksPvPK26drwav_allocation_callbacks(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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, !16, i64 120}
!10 = !{!"_ZTS5drwav", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 64, !13, i64 68, !15, i64 108, !14, i64 112, !14, i64 114, !14, i64 116, !16, i64 120, !16, i64 128, !16, i64 136, !16, i64 144, !16, i64 152, !15, i64 160, !17, i64 164, !18, i64 224, !19, i64 248, !20, i64 288, !21, i64 296, !22, i64 348}
!11 = !{!"_ZTS26drwav_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!"_ZTS15drwav_container", !7, i64 0}
!13 = !{!"_ZTS9drwav_fmt", !14, i64 0, !14, i64 2, !15, i64 4, !15, i64 8, !14, i64 12, !14, i64 14, !14, i64 16, !14, i64 18, !15, i64 20, !7, i64 24}
!14 = !{!"short", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTS10drwav_smpl", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !7, i64 36}
!18 = !{!"_ZTS20drwav__memory_stream", !6, i64 0, !16, i64 8, !16, i64 16}
!19 = !{!"_ZTS26drwav__memory_stream_write", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!20 = !{!"_ZTSN5drwavUt_E", !16, i64 0}
!21 = !{!"_ZTSN5drwavUt0_E", !15, i64 0, !7, i64 4, !7, i64 8, !7, i64 16, !15, i64 32, !7, i64 36}
!22 = !{!"_ZTSN5drwavUt1_E", !15, i64 0, !7, i64 4, !7, i64 12, !7, i64 20, !15, i64 84}
!23 = !{!10, !14, i64 112}
!24 = !{!16, !16, i64 0}
!25 = !{!10, !15, i64 108}
!26 = !{!15, !15, i64 0}


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

@.str.16 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._Z36drwav__read_pcm_frames_and_close_s16P5drwavPjS1_Pm = external hidden unnamed_addr constant [107 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drwav_read_pcm_frames_s16(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z36drwav__read_pcm_frames_and_close_s16P5drwavPjS1_Pm(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.29, ptr noundef nonnull @.str.16, i32 noundef 4665, ptr noundef nonnull @__PRETTY_FUNCTION__._Z36drwav__read_pcm_frames_and_close_s16P5drwavPjS1_Pm) #2
  unreachable

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  %9 = load i64, ptr %7, align 8, !tbaa !5
  %10 = load i16, ptr %8, align 8, !tbaa !22
  %11 = zext i16 %10 to i64
  %12 = shl i64 %9, 1
  %13 = mul i64 %12, %11
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = tail call noundef ptr @_ZL28drwav__malloc_from_callbacksmPK26drwav_allocation_callbacks(i64 noundef %13, ptr noundef nonnull %14)
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %6
  %18 = tail call i32 @drwav_uninit(ptr noundef nonnull %0)
  br label %37

19:                                               ; preds = %6
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = tail call i64 @drwav_read_pcm_frames_s16(ptr noundef nonnull %0, i64 noundef %20, ptr noundef nonnull %15)
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %.not33 = icmp eq i64 %21, %22
  br i1 %.not33, label %25, label %23

23:                                               ; preds = %19
  tail call void @_ZL26drwav__free_from_callbacksPvPK26drwav_allocation_callbacks(ptr noundef nonnull %15, ptr noundef nonnull %14)
  %24 = tail call i32 @drwav_uninit(ptr noundef nonnull %0)
  br label %37

25:                                               ; preds = %19
  %26 = tail call i32 @drwav_uninit(ptr noundef nonnull %0)
  %.not34 = icmp eq ptr %2, null
  br i1 %.not34, label %30, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %0, i64 108
  %29 = load i32, ptr %28, align 4, !tbaa !23
  store i32 %29, ptr %2, align 4, !tbaa !24
  br label %30

30:                                               ; preds = %27, %25
  %.not35 = icmp eq ptr %1, null
  br i1 %.not35, label %34, label %31

31:                                               ; preds = %30
  %32 = load i16, ptr %8, align 8, !tbaa !22
  %33 = zext i16 %32 to i32
  store i32 %33, ptr %1, align 4, !tbaa !24
  br label %34

34:                                               ; preds = %31, %30
  %.not36 = icmp eq ptr %3, null
  br i1 %.not36, label %37, label %35

35:                                               ; preds = %34
  %36 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %36, ptr %3, align 8, !tbaa !25
  br label %37

37:                                               ; preds = %34, %35, %23, %17
  %.0 = phi ptr [ null, %17 ], [ null, %23 ], [ %15, %35 ], [ %15, %34 ]
  ret ptr %.0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL28drwav__malloc_from_callbacksmPK26drwav_allocation_callbacks(i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL26drwav__free_from_callbacksPvPK26drwav_allocation_callbacks(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { noreturn nounwind "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 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 = { noreturn 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, !15, i64 120}
!6 = !{!"_ZTS5drwav", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 64, !12, i64 68, !14, i64 108, !13, i64 112, !13, i64 114, !13, i64 116, !15, i64 120, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !14, i64 160, !16, i64 164, !17, i64 224, !18, i64 248, !19, i64 288, !20, i64 296, !21, i64 348}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS26drwav_allocation_callbacks", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!11 = !{!"_ZTS15drwav_container", !8, i64 0}
!12 = !{!"_ZTS9drwav_fmt", !13, i64 0, !13, i64 2, !14, i64 4, !14, i64 8, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18, !14, i64 20, !8, i64 24}
!13 = !{!"short", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTS10drwav_smpl", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !8, i64 36}
!17 = !{!"_ZTS20drwav__memory_stream", !7, i64 0, !15, i64 8, !15, i64 16}
!18 = !{!"_ZTS26drwav__memory_stream_write", !7, i64 0, !7, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!19 = !{!"_ZTSN5drwavUt_E", !15, i64 0}
!20 = !{!"_ZTSN5drwavUt0_E", !14, i64 0, !8, i64 4, !8, i64 8, !8, i64 16, !14, i64 32, !8, i64 36}
!21 = !{!"_ZTSN5drwavUt1_E", !14, i64 0, !8, i64 4, !8, i64 12, !8, i64 20, !14, i64 84}
!22 = !{!6, !13, i64 112}
!23 = !{!6, !14, i64 108}
!24 = !{!14, !14, i64 0}
!25 = !{!15, !15, i64 0}


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