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

@.str.6 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.157 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.ma_resource_manager_data_buffer_get_cursor_in_pcm_frames = external hidden unnamed_addr constant [115 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @ma_audio_buffer_get_cursor_in_pcm_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 nounwind uwtable
declare dso_local i32 @ma_decoder_get_cursor_in_pcm_frames(ptr noundef, ptr noundef) #1

; 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_cursor_in_pcm_frames(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %6, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = call noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef %8)
  %10 = icmp ne i32 %9, -22
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %14

12:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.157, ptr noundef @.str.6, i32 noundef 66185, ptr noundef @__PRETTY_FUNCTION__.ma_resource_manager_data_buffer_get_cursor_in_pcm_frames) #3
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %14
  store i32 -2, ptr %3, align 4
  br label %44

21:                                               ; preds = %17
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %25)
  switch i32 %26, label %43 [
    i32 1, label %27
    i32 2, label %32
    i32 3, label %37
    i32 0, label %42
  ]

27:                                               ; preds = %21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %28, i32 0, i32 11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i32 @ma_decoder_get_cursor_in_pcm_frames(ptr noundef %29, ptr noundef %30)
  store i32 %31, ptr %3, align 4
  br label %44

32:                                               ; preds = %21
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %33, i32 0, i32 11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @ma_audio_buffer_get_cursor_in_pcm_frames(ptr noundef %34, ptr noundef %35)
  store i32 %36, ptr %3, align 4
  br label %44

37:                                               ; preds = %21
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ma_resource_manager_data_buffer, ptr %38, i32 0, i32 11
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @ma_paged_audio_buffer_get_cursor_in_pcm_frames(ptr noundef %39, ptr noundef %40)
  store i32 %41, ptr %3, align 4
  br label %44

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

43:                                               ; preds = %21
  store i32 -2, ptr %3, align 4
  br label %44

44:                                               ; preds = %43, %42, %37, %32, %27, %20
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

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 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 = { 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, !6, i64 80}
!10 = !{!"_ZTS31ma_resource_manager_data_buffer", !11, i64 0, !6, i64 72, !6, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !12, i64 104, !13, i64 112, !14, i64 116, !13, i64 120, !13, i64 124, !7, i64 128}
!11 = !{!"_ZTS19ma_data_source_base", !6, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS9ma_result", !7, i64 0}
!15 = !{!12, !12, 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.6 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.157 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.ma_resource_manager_data_buffer_get_cursor_in_pcm_frames = external hidden unnamed_addr constant [115 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 nounwind uwtable
declare dso_local i32 @ma_audio_buffer_get_cursor_in_pcm_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 nounwind uwtable
declare dso_local i32 @ma_decoder_get_cursor_in_pcm_frames(ptr noundef, ptr noundef) local_unnamed_addr #1

; 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 nounwind uwtable
define dso_local i32 @ma_resource_manager_data_buffer_get_cursor_in_pcm_frames(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZL43ma_resource_manager_data_buffer_node_resultPK36ma_resource_manager_data_buffer_node(ptr noundef %4)
  %.not = icmp eq i32 %5, -22
  br i1 %.not, label %6, label %7

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.157, ptr noundef nonnull @.str.6, i32 noundef 66185, ptr noundef nonnull @__PRETTY_FUNCTION__.ma_resource_manager_data_buffer_get_cursor_in_pcm_frames) #2
  unreachable

7:                                                ; preds = %2
  %8 = icmp eq ptr %1, null
  br i1 %8, label %22, label %9

9:                                                ; preds = %7
  store i64 0, ptr %1, align 8, !tbaa !14
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = tail call noundef i32 @_ZL57ma_resource_manager_data_buffer_node_get_data_supply_typeP36ma_resource_manager_data_buffer_node(ptr noundef %10)
  switch i32 %11, label %21 [
    i32 1, label %12
    i32 2, label %15
    i32 3, label %18
    i32 0, label %22
  ]

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  %14 = tail call i32 @ma_decoder_get_cursor_in_pcm_frames(ptr noundef nonnull %13, ptr noundef nonnull %1)
  br label %22

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 128
  %17 = tail call i32 @ma_audio_buffer_get_cursor_in_pcm_frames(ptr noundef nonnull %16, ptr noundef nonnull %1)
  br label %22

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

21:                                               ; preds = %9
  br label %22

22:                                               ; preds = %9, %7, %21, %18, %15, %12
  %.0 = phi i32 [ -2, %21 ], [ %20, %18 ], [ %17, %15 ], [ %14, %12 ], [ -2, %7 ], [ -19, %9 ]
  ret i32 %.0
}

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 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 = { 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, !8, i64 80}
!6 = !{!"_ZTS31ma_resource_manager_data_buffer", !7, i64 0, !8, i64 72, !8, i64 80, !12, i64 88, !12, i64 92, !12, i64 96, !11, i64 104, !12, i64 112, !13, i64 116, !12, i64 120, !12, i64 124, !9, i64 128}
!7 = !{!"_ZTS19ma_data_source_base", !8, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !12, i64 64}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"_ZTS9ma_result", !9, i64 0}
!14 = !{!11, !11, i64 0}


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