; 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_data_source_vtable = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.ma_data_source_config = type { ptr }
%struct.ma_waveform = type { %struct.ma_data_source_base, %struct.ma_waveform_config, double, double }
%struct.ma_data_source_base = type { ptr, i64, i64, i64, i64, ptr, ptr, ptr, i32 }
%struct.ma_waveform_config = type { i32, i32, i32, i32, double, double }

@_ZL32g_ma_waveform_data_source_vtable = external hidden global %struct.ma_data_source_vtable, align 8

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @ma_data_source_config_init() #3

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_waveform_init(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.ma_data_source_config, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.ma_data_source_config, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %42

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 120, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %15 = call ptr @ma_data_source_config_init()
  %16 = getelementptr inbounds %struct.ma_data_source_config, ptr %9, i32 0, i32 0
  store ptr %15, ptr %16, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %9, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %17 = getelementptr inbounds %struct.ma_data_source_config, ptr %7, i32 0, i32 0
  store ptr @_ZL32g_ma_waveform_data_source_vtable, ptr %17, align 8, !tbaa !10
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ma_waveform, ptr %18, i32 0, i32 0
  %20 = call i32 @ma_data_source_init(ptr noundef %7, ptr noundef %19)
  store i32 %20, ptr %6, align 4, !tbaa !12
  %21 = load i32, ptr %6, align 4, !tbaa !12
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %13
  %24 = load i32, ptr %6, align 4, !tbaa !12
  store i32 %24, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %42

25:                                               ; preds = %13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ma_waveform, ptr %27, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %28, ptr align 8 %26, i64 32, i1 false), !tbaa.struct !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ma_waveform, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.ma_waveform_config, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !23
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ma_waveform, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.ma_waveform_config, ptr %34, i32 0, i32 5
  %36 = load double, ptr %35, align 8, !tbaa !28
  %37 = call noundef double @_ZL30ma_waveform__calculate_advancejd(i32 noundef %32, double noundef %36)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ma_waveform, ptr %38, i32 0, i32 2
  store double %37, ptr %39, align 8, !tbaa !29
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ma_waveform, ptr %40, i32 0, i32 3
  store double 0.000000e+00, ptr %41, align 8, !tbaa !30
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %42

42:                                               ; preds = %25, %23, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %43 = load i32, ptr %3, align 4
  ret i32 %43
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZL30ma_waveform__calculate_advancejd(i32 noundef, double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 = !{i64 0, i64 8, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS21ma_data_source_config", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTS9ma_result", !7, i64 0}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !17, i64 8, i64 4, !17, i64 12, i64 4, !19, i64 16, i64 8, !21, i64 24, i64 8, !21}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTS9ma_format", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"_ZTS16ma_waveform_type", !7, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"double", !7, i64 0}
!23 = !{!24, !18, i64 80}
!24 = !{!"_ZTS11ma_waveform", !25, i64 0, !27, i64 72, !22, i64 104, !22, i64 112}
!25 = !{!"_ZTS19ma_data_source_base", !6, i64 0, !26, i64 8, !26, i64 16, !26, i64 24, !26, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !18, i64 64}
!26 = !{!"long long", !7, i64 0}
!27 = !{!"_ZTS18ma_waveform_config", !16, i64 0, !18, i64 4, !18, i64 8, !20, i64 12, !22, i64 16, !22, i64 24}
!28 = !{!24, !22, i64 96}
!29 = !{!24, !22, i64 104}
!30 = !{!24, !22, i64 112}


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

%struct.ma_data_source_vtable = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.ma_data_source_config = type { ptr }

@_ZL32g_ma_waveform_data_source_vtable = external hidden global %struct.ma_data_source_vtable, align 8

; 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @ma_data_source_config_init() local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @ma_waveform_init(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.ma_data_source_config, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = icmp eq ptr %1, null
  br i1 %4, label %17, label %5

5:                                                ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(120) %1, i8 0, i64 120, i1 false)
  %6 = tail call ptr @ma_data_source_config_init()
  store ptr @_ZL32g_ma_waveform_data_source_vtable, ptr %3, align 8, !tbaa !5
  %7 = call i32 @ma_data_source_init(ptr noundef nonnull %3, ptr noundef nonnull %1)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %17

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 72
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false), !tbaa.struct !10
  %10 = getelementptr inbounds i8, ptr %1, i64 80
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %1, i64 96
  %13 = load double, ptr %12, align 8, !tbaa !24
  %14 = call noundef double @_ZL30ma_waveform__calculate_advancejd(i32 noundef %11, double noundef %13)
  %15 = getelementptr inbounds i8, ptr %1, i64 104
  store double %14, ptr %15, align 8, !tbaa !25
  %16 = getelementptr inbounds i8, ptr %1, i64 112
  store double 0.000000e+00, ptr %16, align 8, !tbaa !26
  br label %17

17:                                               ; preds = %5, %2, %8
  %.0 = phi i32 [ 0, %8 ], [ -2, %2 ], [ %7, %5 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZL30ma_waveform__calculate_advancejd(i32 noundef, double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS21ma_data_source_config", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{i64 0, i64 4, !11, i64 4, i64 4, !13, i64 8, i64 4, !13, i64 12, i64 4, !15, i64 16, i64 8, !17, i64 24, i64 8, !17}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS9ma_format", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTS16ma_waveform_type", !8, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = !{!20, !14, i64 80}
!20 = !{!"_ZTS11ma_waveform", !21, i64 0, !23, i64 72, !18, i64 104, !18, i64 112}
!21 = !{!"_ZTS19ma_data_source_base", !7, i64 0, !22, i64 8, !22, i64 16, !22, i64 24, !22, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !14, i64 64}
!22 = !{!"long long", !8, i64 0}
!23 = !{!"_ZTS18ma_waveform_config", !12, i64 0, !14, i64 4, !14, i64 8, !16, i64 12, !18, i64 16, !18, i64 24}
!24 = !{!20, !18, i64 96}
!25 = !{!20, !18, i64 104}
!26 = !{!20, !18, i64 112}


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