; 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_sound = type { %struct.ma_engine_node, ptr, i64, i32, i8, ptr }
%struct.ma_engine_node = type { %struct.ma_node_base, ptr, i32, %struct.ma_fader, %struct.ma_linear_resampler, %struct.ma_spatializer, %struct.ma_panner, float, float, float, i32, i32, i32, i8, ptr }
%struct.ma_node_base = type { ptr, ptr, ptr, i16, i16, i16, i16, i32, [2 x i64], i64, i32, i32, ptr, ptr, [2 x %struct.ma_node_input_bus], [2 x %struct.ma_node_output_bus], ptr, i32 }
%struct.ma_node_input_bus = type { %struct.ma_node_output_bus, i32, i32, i8 }
%struct.ma_node_output_bus = type { ptr, i8, i8, i8, i32, i32, i32, i32, float, ptr, ptr, ptr }
%struct.ma_fader = type { %struct.ma_fader_config, float, float, i64, i64 }
%struct.ma_fader_config = type { i32, i32, i32 }
%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_spatializer = type { i32, i32, ptr, i32, i32, i32, float, float, float, float, float, float, float, float, float, float, i32, %struct.ma_vec3f, %struct.ma_vec3f, %struct.ma_vec3f, float, %struct.ma_gainer, ptr, ptr, i32 }
%struct.ma_vec3f = type { float, float, float }
%struct.ma_gainer = type { %struct.ma_gainer_config, i32, ptr, ptr, ptr, i32 }
%struct.ma_gainer_config = type { i32, i32 }
%struct.ma_panner = type { i32, i32, i32, float }

; 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
declare dso_local i32 @ma_data_source_seek_to_pcm_frame(ptr noundef, i64 noundef) #1

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

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

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

10:                                               ; preds = %1
  store i32 -2, ptr %2, align 4
  br label %44

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call i32 @ma_sound_is_playing(ptr noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i32 0, ptr %2, align 4
  br label %44

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i32 @ma_sound_at_end(ptr noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %41

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ma_sound, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call i32 @ma_data_source_seek_to_pcm_frame(ptr noundef %23, i64 noundef 0)
  store i32 %24, ptr %4, align 4, !tbaa !34
  %25 = load i32, ptr %4, align 4, !tbaa !34
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %20
  %28 = load i32, ptr %4, align 4, !tbaa !34
  %29 = icmp ne i32 %28, -29
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = load i32, ptr %4, align 4, !tbaa !34
  store i32 %31, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %38

32:                                               ; preds = %27, %20
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ma_sound, ptr %33, i32 0, i32 3
  store i32 0, ptr %6, align 4, !tbaa !36
  %35 = load i32, ptr %6, align 4
  %36 = atomicrmw xchg ptr %34, i32 %35 seq_cst, align 8
  store i32 %36, ptr %7, align 4
  %37 = load i32, ptr %7, align 4, !tbaa !36
  store i32 0, ptr %5, align 4
  br label %38

38:                                               ; preds = %32, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %39 = load i32, ptr %5, align 4
  switch i32 %39, label %46 [
    i32 0, label %40
    i32 1, label %44
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40, %16
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i32 @ma_node_set_state(ptr noundef %42, i32 noundef 0)
  store i32 0, ptr %2, align 4
  br label %44

44:                                               ; preds = %41, %38, %15, %10
  %45 = load i32, ptr %2, align 4
  ret i32 %45

46:                                               ; preds = %38
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local i32 @ma_sound_is_playing(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 = { 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 #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, !6, i64 792}
!10 = !{!"_ZTS8ma_sound", !11, i64 0, !6, i64 792, !15, i64 800, !16, i64 808, !7, i64 812, !6, i64 816}
!11 = !{!"_ZTS14ma_engine_node", !12, i64 0, !6, i64 360, !16, i64 368, !17, i64 376, !21, i64 416, !25, i64 552, !32, i64 736, !20, i64 752, !20, i64 756, !20, i64 760, !16, i64 764, !16, i64 768, !16, i64 772, !7, i64 776, !6, i64 784}
!12 = !{!"_ZTS12ma_node_base", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 26, !13, i64 28, !13, i64 30, !14, i64 32, !7, i64 40, !15, i64 56, !16, i64 64, !16, i64 68, !6, i64 72, !6, i64 80, !7, i64 88, !7, i64 232, !6, i64 344, !16, i64 352}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTS13ma_node_state", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS8ma_fader", !18, i64 0, !20, i64 12, !20, i64 16, !15, i64 24, !15, i64 32}
!18 = !{!"_ZTS15ma_fader_config", !19, i64 0, !16, i64 4, !16, i64 8}
!19 = !{!"_ZTS9ma_format", !7, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = !{!"_ZTS19ma_linear_resampler", !22, i64 0, !16, i64 32, !16, i64 36, !16, i64 40, !16, i64 44, !7, i64 48, !7, i64 56, !24, i64 64, !6, i64 120, !16, i64 128}
!22 = !{!"_ZTS26ma_linear_resampler_config", !19, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !23, i64 24}
!23 = !{!"double", !7, i64 0}
!24 = !{!"_ZTS6ma_lpf", !19, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !16, i64 48}
!25 = !{!"_ZTS14ma_spatializer", !16, i64 0, !16, i64 4, !6, i64 8, !26, i64 16, !27, i64 20, !28, i64 24, !20, i64 28, !20, i64 32, !20, i64 36, !20, i64 40, !20, i64 44, !20, i64 48, !20, i64 52, !20, i64 56, !20, i64 60, !20, i64 64, !16, i64 68, !29, i64 72, !29, i64 84, !29, i64 96, !20, i64 108, !30, i64 112, !6, i64 160, !6, i64 168, !16, i64 176}
!26 = !{!"_ZTS20ma_attenuation_model", !7, i64 0}
!27 = !{!"_ZTS14ma_positioning", !7, i64 0}
!28 = !{!"_ZTS13ma_handedness", !7, i64 0}
!29 = !{!"_ZTS8ma_vec3f", !20, i64 0, !20, i64 4, !20, i64 8}
!30 = !{!"_ZTS9ma_gainer", !31, i64 0, !16, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !16, i64 40}
!31 = !{!"_ZTS16ma_gainer_config", !16, i64 0, !16, i64 4}
!32 = !{!"_ZTS9ma_panner", !19, i64 0, !16, i64 4, !33, i64 8, !20, i64 12}
!33 = !{!"_ZTS11ma_pan_mode", !7, i64 0}
!34 = !{!35, !35, i64 0}
!35 = !{!"_ZTS9ma_result", !7, i64 0}
!36 = !{!16, !16, 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 uwtable
declare dso_local i32 @ma_data_source_seek_to_pcm_frame(ptr noundef, i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @ma_sound_start(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %16, label %3

3:                                                ; preds = %1
  %4 = tail call i32 @ma_sound_is_playing(ptr noundef nonnull %0)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %16

5:                                                ; preds = %3
  %6 = tail call i32 @ma_sound_at_end(ptr noundef nonnull %0)
  %.not14 = icmp eq i32 %6, 0
  br i1 %.not14, label %14, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 792
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call i32 @ma_data_source_seek_to_pcm_frame(ptr noundef %9, i64 noundef 0)
  switch i32 %10, label %16 [
    i32 -29, label %11
    i32 0, label %11
  ]

11:                                               ; preds = %7, %7
  %12 = getelementptr inbounds i8, ptr %0, i64 808
  %13 = atomicrmw xchg ptr %12, i32 0 seq_cst, align 8
  switch i32 %10, label %16 [
    i32 -29, label %14
    i32 0, label %14
  ]

14:                                               ; preds = %11, %11, %5
  %15 = tail call i32 @ma_node_set_state(ptr noundef nonnull %0, i32 noundef 0)
  br label %16

16:                                               ; preds = %7, %11, %3, %1, %14
  %.1 = phi i32 [ %10, %11 ], [ 0, %14 ], [ -2, %1 ], [ 0, %3 ], [ %10, %7 ]
  ret i32 %.1
}

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

attributes #0 = { 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 #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" }

!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, !9, i64 792}
!6 = !{!"_ZTS8ma_sound", !7, i64 0, !9, i64 792, !14, i64 800, !15, i64 808, !10, i64 812, !9, i64 816}
!7 = !{!"_ZTS14ma_engine_node", !8, i64 0, !9, i64 360, !15, i64 368, !16, i64 376, !20, i64 416, !24, i64 552, !31, i64 736, !19, i64 752, !19, i64 756, !19, i64 760, !15, i64 764, !15, i64 768, !15, i64 772, !10, i64 776, !9, i64 784}
!8 = !{!"_ZTS12ma_node_base", !9, i64 0, !9, i64 8, !9, i64 16, !12, i64 24, !12, i64 26, !12, i64 28, !12, i64 30, !13, i64 32, !10, i64 40, !14, i64 56, !15, i64 64, !15, i64 68, !9, i64 72, !9, i64 80, !10, i64 88, !10, i64 232, !9, i64 344, !15, i64 352}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"short", !10, i64 0}
!13 = !{!"_ZTS13ma_node_state", !10, i64 0}
!14 = !{!"long long", !10, i64 0}
!15 = !{!"int", !10, i64 0}
!16 = !{!"_ZTS8ma_fader", !17, i64 0, !19, i64 12, !19, i64 16, !14, i64 24, !14, i64 32}
!17 = !{!"_ZTS15ma_fader_config", !18, i64 0, !15, i64 4, !15, i64 8}
!18 = !{!"_ZTS9ma_format", !10, i64 0}
!19 = !{!"float", !10, i64 0}
!20 = !{!"_ZTS19ma_linear_resampler", !21, i64 0, !15, i64 32, !15, i64 36, !15, i64 40, !15, i64 44, !10, i64 48, !10, i64 56, !23, i64 64, !9, i64 120, !15, i64 128}
!21 = !{!"_ZTS26ma_linear_resampler_config", !18, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !22, i64 24}
!22 = !{!"double", !10, i64 0}
!23 = !{!"_ZTS6ma_lpf", !18, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !9, i64 24, !9, i64 32, !9, i64 40, !15, i64 48}
!24 = !{!"_ZTS14ma_spatializer", !15, i64 0, !15, i64 4, !9, i64 8, !25, i64 16, !26, i64 20, !27, i64 24, !19, i64 28, !19, i64 32, !19, i64 36, !19, i64 40, !19, i64 44, !19, i64 48, !19, i64 52, !19, i64 56, !19, i64 60, !19, i64 64, !15, i64 68, !28, i64 72, !28, i64 84, !28, i64 96, !19, i64 108, !29, i64 112, !9, i64 160, !9, i64 168, !15, i64 176}
!25 = !{!"_ZTS20ma_attenuation_model", !10, i64 0}
!26 = !{!"_ZTS14ma_positioning", !10, i64 0}
!27 = !{!"_ZTS13ma_handedness", !10, i64 0}
!28 = !{!"_ZTS8ma_vec3f", !19, i64 0, !19, i64 4, !19, i64 8}
!29 = !{!"_ZTS9ma_gainer", !30, i64 0, !15, i64 8, !9, i64 16, !9, i64 24, !9, i64 32, !15, i64 40}
!30 = !{!"_ZTS16ma_gainer_config", !15, i64 0, !15, i64 4}
!31 = !{!"_ZTS9ma_panner", !18, i64 0, !15, i64 4, !32, i64 8, !19, i64 12}
!32 = !{!"_ZTS11ma_pan_mode", !10, i64 0}


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