; 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_resource_manager_data_buffer = type { %struct.ma_data_source_base, ptr, ptr, i32, i32, i32, i64, i32, i32, i32, i32, %union.anon.71 }
%struct.ma_data_source_base = type { ptr, i64, i64, i64, i64, ptr, ptr, ptr, i32 }
%union.anon.71 = type { %struct.ma_decoder }
%struct.ma_decoder = type { %struct.ma_data_source_base, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i32, i32, i32, %struct.ma_data_converter, ptr, i64, i64, i64, %struct.ma_allocation_callbacks, %union.anon.61 }
%struct.ma_data_converter = type { i32, i32, i32, i32, i32, i32, i32, i32, %struct.ma_channel_converter, %struct.ma_resampler, i8, i8, i8, i8, i8, i8, ptr }
%struct.ma_channel_converter = type { i32, i32, i32, i32, i32, ptr, ptr, ptr, %union.anon.27, ptr, i32 }
%union.anon.27 = type { ptr }
%struct.ma_resampler = type { ptr, ptr, ptr, i32, i32, i32, i32, %union.anon.28, ptr, i32 }
%union.anon.28 = type { %struct.ma_linear_resampler }
%struct.ma_linear_resampler = type { %struct.ma_linear_resampler_config, i32, i32, i32, i32, %union.anon.29, %union.anon.30, %struct.ma_lpf, ptr, i32 }
%struct.ma_linear_resampler_config = type { i32, i32, i32, i32, i32, double }
%union.anon.29 = type { ptr }
%union.anon.30 = type { ptr }
%struct.ma_lpf = type { i32, i32, i32, i32, i32, ptr, ptr, ptr, i32 }
%struct.ma_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%union.anon.61 = type { %struct.anon.63 }
%struct.anon.63 = type { ptr, i64, i64 }
%struct.ma_resource_manager_data_buffer_node = type { i32, i32, i32, i32, i32, i32, %struct.ma_resource_manager_data_supply, ptr, ptr, ptr }
%struct.ma_resource_manager_data_supply = type { i32, %union.anon.72 }
%union.anon.72 = type { %struct.anon.75 }
%struct.anon.75 = type { %struct.ma_paged_audio_buffer_data, i64, i32 }
%struct.ma_paged_audio_buffer_data = type { i32, i32, %struct.ma_paged_audio_buffer_page, ptr }
%struct.ma_paged_audio_buffer_page = type { ptr, i64, [1 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 nounwind uwtable
declare dso_local i32 @ma_audio_buffer_get_available_frames(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_resource_manager_data_buffer_get_available_frames(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i32 -2, ptr %3, align 4
  br label %73

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %11, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  store i32 -2, ptr %3, align 4
  br label %73

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %18)
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = call noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef %24)
  %26 = icmp eq i32 %25, -19
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 -19, ptr %3, align 4
  br label %73

28:                                               ; preds = %21
  store i32 -3, ptr %3, align 4
  br label %73

29:                                               ; preds = %15
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %32)
  switch i32 %33, label %72 [
    i32 1, label %34
    i32 2, label %39
    i32 3, label %44
    i32 0, label %71
  ]

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %35, i32 0, i32 11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call i32 @ma_decoder_get_available_frames(ptr noundef %36, ptr noundef %37)
  store i32 %38, ptr %3, align 4
  br label %73

39:                                               ; preds = %29
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %40, i32 0, i32 11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @ma_audio_buffer_get_available_frames(ptr noundef %41, ptr noundef %42)
  store i32 %43, ptr %3, align 4
  br label %73

44:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %45, i32 0, i32 11
  %47 = call i32 @ma_paged_audio_buffer_get_cursor_in_pcm_frames(ptr noundef %46, ptr noundef %6)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.ma_resource_manager_data_buffer_node, ptr %50, i32 0, i32 6
  %52 = getelementptr inbounds %struct.ma_resource_manager_data_supply, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.anon.75, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !16
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = icmp ugt i64 %54, %55
  br i1 %56, label %57, label %68

57:                                               ; preds = %44
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.ma_resource_manager_data_buffer_node, ptr %60, i32 0, i32 6
  %62 = getelementptr inbounds %struct.ma_resource_manager_data_supply, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.anon.75, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !16
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = sub i64 %64, %65
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %66, ptr %67, align 8, !tbaa !9
  br label %70

68:                                               ; preds = %44
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %69, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %68, %57
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %73

71:                                               ; preds = %29
  br label %72

72:                                               ; preds = %71, %29
  store i32 -2, ptr %3, align 4
  br label %73

73:                                               ; preds = %72, %70, %39, %34, %28, %27, %14, %9
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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 = { 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 }

!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, !6, i64 80}
!12 = !{!"_ZTS31ma_resource_manager_data_buffer", !13, i64 0, !6, i64 72, !6, i64 80, !14, i64 88, !14, i64 92, !14, i64 96, !10, i64 104, !14, i64 112, !15, i64 116, !14, i64 120, !14, i64 124, !7, i64 128}
!13 = !{!"_ZTS19ma_data_source_base", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !14, i64 64}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS9ma_result", !7, i64 0}
!16 = !{!7, !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 nounwind uwtable
declare dso_local i32 @ma_audio_buffer_get_available_frames(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_resource_manager_data_buffer_get_available_frames(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = icmp eq ptr %1, null
  br i1 %4, label %31, label %5

5:                                                ; preds = %2
  store i64 0, ptr %1, align 8, !tbaa !5
  %6 = icmp eq ptr %0, null
  br i1 %6, label %31, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = tail call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %9)
  %11 = icmp eq i32 %10, 0
  %12 = load ptr, ptr %8, align 8, !tbaa !9
  br i1 %11, label %13, label %16

13:                                               ; preds = %7
  %14 = tail call noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef %12)
  %15 = icmp eq i32 %14, -19
  %. = select i1 %15, i32 -19, i32 -3
  br label %31

16:                                               ; preds = %7
  %17 = tail call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %12)
  switch i32 %17, label %31 [
    i32 1, label %18
    i32 2, label %21
    i32 3, label %24
  ]

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %0, i64 128
  %20 = tail call i32 @ma_decoder_get_available_frames(ptr noundef nonnull %19, ptr noundef nonnull %1)
  br label %31

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %0, i64 128
  %23 = tail call i32 @ma_audio_buffer_get_available_frames(ptr noundef nonnull %22, ptr noundef nonnull %1)
  br label %31

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %25 = getelementptr inbounds i8, ptr %0, i64 128
  %26 = call i32 @ma_paged_audio_buffer_get_cursor_in_pcm_frames(ptr noundef nonnull %25, ptr noundef nonnull %3)
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 72
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %storemerge = call i64 @llvm.usub.sat.i64(i64 %29, i64 %30)
  store i64 %storemerge, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  br label %31

31:                                               ; preds = %16, %13, %5, %2, %24, %21, %18
  %.0 = phi i32 [ 0, %24 ], [ %23, %21 ], [ %20, %18 ], [ -2, %2 ], [ -2, %5 ], [ %., %13 ], [ -2, %16 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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 = { 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 80}
!10 = !{!"_ZTS31ma_resource_manager_data_buffer", !11, i64 0, !12, i64 72, !12, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !6, i64 104, !13, i64 112, !14, i64 116, !13, i64 120, !13, i64 124, !7, i64 128}
!11 = !{!"_ZTS19ma_data_source_base", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !13, i64 64}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS9ma_result", !7, i64 0}
!15 = !{!7, !7, i64 0}


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