; LLVM IR from SelfishOlex/MiniAudioO3DE :: MiniAudio/Code/Source/Clients (MiniAudioImplementation)

; 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.ma_wav = type { %struct.ma_data_source_base, ptr, ptr, ptr, ptr, i32, %struct.drwav }
%struct.ma_data_source_base = type { ptr, i64, i64, i64, i64, ptr, ptr, ptr, i32 }
%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.57, %struct.anon.58 }
%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.57 = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.58 = type { i32, [2 x i32], [2 x i32], [16 x i32], i32 }

; 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
define dso_local noundef i32 @_Z22ma_wav_read_pcm_framesP6ma_wavPvyPy(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %4
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 -2, ptr %5, align 4
  br label %75

22:                                               ; preds = %18
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 -2, ptr %5, align 4
  br label %75

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call noundef i32 @_Z22ma_wav_get_data_formatP6ma_wavP9ma_formatPjS3_Phm(ptr noundef %27, ptr noundef %12, ptr noundef null, ptr noundef null, ptr noundef null, i64 noundef 0)
  %29 = load i32, ptr %12, align 4, !tbaa !13
  switch i32 %29, label %49 [
    i32 5, label %30
    i32 2, label %36
    i32 4, label %42
    i32 0, label %48
  ]

30:                                               ; preds = %26
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ma_wav, ptr %31, i32 0, i32 6
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call i64 @drwav_read_pcm_frames_f32(ptr noundef %32, i64 noundef %33, ptr noundef %34)
  store i64 %35, ptr %11, align 8, !tbaa !9
  br label %55

36:                                               ; preds = %26
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ma_wav, ptr %37, i32 0, i32 6
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = call i64 @drwav_read_pcm_frames_s16(ptr noundef %38, i64 noundef %39, ptr noundef %40)
  store i64 %41, ptr %11, align 8, !tbaa !9
  br label %55

42:                                               ; preds = %26
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ma_wav, ptr %43, i32 0, i32 6
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call i64 @drwav_read_pcm_frames_s32(ptr noundef %44, i64 noundef %45, ptr noundef %46)
  store i64 %47, ptr %11, align 8, !tbaa !9
  br label %55

48:                                               ; preds = %26
  store i32 -3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %74

49:                                               ; preds = %26
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ma_wav, ptr %50, i32 0, i32 6
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i64 @drwav_read_pcm_frames(ptr noundef %51, i64 noundef %52, ptr noundef %53)
  store i64 %54, ptr %11, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %49, %42, %36, %30
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  store i32 -17, ptr %10, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %58, %55
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %63, ptr %64, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %62, %59
  %66 = load i32, ptr %10, align 4, !tbaa !11
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %72

68:                                               ; preds = %65
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = icmp eq i64 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 -17, ptr %10, align 4, !tbaa !11
  br label %72

72:                                               ; preds = %71, %68, %65
  %73 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %73, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %74

74:                                               ; preds = %72, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %75

75:                                               ; preds = %74, %25, %21
  %76 = load i32, ptr %5, align 4
  ret i32 %76
}

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

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

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

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

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

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 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS9ma_result", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS9ma_format", !7, 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"

; 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
define dso_local noundef range(i32 -17, 1) i32 @_Z22ma_wav_read_pcm_framesP6ma_wavPvyPy(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %4
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %4
  %8 = icmp eq i64 %2, 0
  %9 = icmp eq ptr %0, null
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %29, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %11 = call noundef i32 @_Z22ma_wav_get_data_formatP6ma_wavP9ma_formatPjS3_Phm(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef null, ptr noundef null, ptr noundef null, i64 noundef 0)
  %12 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %12, label %22 [
    i32 5, label %13
    i32 2, label %16
    i32 4, label %19
    i32 0, label %28
  ]

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 112
  %15 = call i64 @drwav_read_pcm_frames_f32(ptr noundef nonnull %14, i64 noundef %2, ptr noundef %1)
  br label %25

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 112
  %18 = call i64 @drwav_read_pcm_frames_s16(ptr noundef nonnull %17, i64 noundef %2, ptr noundef %1)
  br label %25

19:                                               ; preds = %10
  %20 = getelementptr inbounds i8, ptr %0, i64 112
  %21 = call i64 @drwav_read_pcm_frames_s32(ptr noundef nonnull %20, i64 noundef %2, ptr noundef %1)
  br label %25

22:                                               ; preds = %10
  %23 = getelementptr inbounds i8, ptr %0, i64 112
  %24 = call i64 @drwav_read_pcm_frames(ptr noundef nonnull %23, i64 noundef %2, ptr noundef %1)
  br label %25

25:                                               ; preds = %22, %19, %16, %13
  %.0 = phi i64 [ %24, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ]
  %26 = icmp eq i64 %.0, 0
  %spec.select = select i1 %26, i32 -17, i32 0
  br i1 %.not, label %28, label %27

27:                                               ; preds = %25
  store i64 %.0, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %27, %10
  %.026 = phi i32 [ -3, %10 ], [ %spec.select, %27 ], [ %spec.select, %25 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  br label %29

29:                                               ; preds = %7, %28
  %.1 = phi i32 [ %.026, %28 ], [ -2, %7 ]
  ret i32 %.1
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drwav_read_pcm_frames_f32(ptr noundef, i64 noundef, 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
declare dso_local i64 @drwav_read_pcm_frames_s32(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS9ma_format", !7, i64 0}


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