; 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_mp3 = type { %struct.ma_data_source_base, ptr, ptr, ptr, ptr, i32, %struct.drmp3, i32, ptr }
%struct.ma_data_source_base = type { ptr, i64, i64, i64, i64, ptr, ptr, ptr, i32 }
%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.59 }
%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.59 = type { ptr, i64, i64 }

; 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_mp3_read_pcm_framesP6ma_mp3PvyPy(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 %57

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 %57

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_mp3_get_data_formatP6ma_mp3P9ma_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 %43 [
    i32 5, label %30
    i32 2, label %36
    i32 1, label %42
    i32 3, label %42
    i32 4, label %42
    i32 0, label %42
  ]

30:                                               ; preds = %26
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ma_mp3, 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 @drmp3_read_pcm_frames_f32(ptr noundef %32, i64 noundef %33, ptr noundef %34)
  store i64 %35, ptr %11, align 8, !tbaa !9
  br label %44

36:                                               ; preds = %26
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ma_mp3, 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 @drmp3_read_pcm_frames_s16(ptr noundef %38, i64 noundef %39, ptr noundef %40)
  store i64 %41, ptr %11, align 8, !tbaa !9
  br label %44

42:                                               ; preds = %26, %26, %26, %26
  br label %43

43:                                               ; preds = %42, %26
  store i32 -3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %56

44:                                               ; preds = %36, %30
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 -17, ptr %10, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %47, %44
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %51, %48
  %55 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %55, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %56

56:                                               ; preds = %54, %43
  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 %57

57:                                               ; preds = %56, %25, %21
  %58 = load i32, ptr %5, align 4
  ret i32 %58
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drmp3_read_pcm_frames_s16(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_mp3_read_pcm_framesP6ma_mp3PvyPy(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 %23, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %11 = call noundef i32 @_Z22ma_mp3_get_data_formatP6ma_mp3P9ma_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
  ]

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

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

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

21:                                               ; preds = %19
  store i64 %.0, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %19, %21, %10
  %.017 = phi i32 [ -3, %10 ], [ %spec.select, %21 ], [ %spec.select, %19 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  br label %23

23:                                               ; preds = %7, %22
  %.1 = phi i32 [ %.017, %22 ], [ -2, %7 ]
  ret i32 %.1
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drmp3_read_pcm_frames_s16(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