; 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_noise = type { %struct.ma_data_source_vtable, %struct.ma_noise_config, %struct.ma_lcg, %union.anon.68, ptr, i32 }
%struct.ma_data_source_vtable = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.ma_noise_config = type { i32, i32, i32, i32, double, i32 }
%struct.ma_lcg = type { i32 }
%union.anon.68 = type { %struct.anon.69 }
%struct.anon.69 = type { ptr, ptr, ptr }

; 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 i32 @ma_noise_read_pcm_frames(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 i64, align 8
  %11 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %4
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %14, %4
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

20:                                               ; preds = %16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

24:                                               ; preds = %20
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %28, ptr %10, align 8, !tbaa !9
  br label %51

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ma_noise, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.ma_noise_config, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !11
  switch i32 %33, label %49 [
    i32 0, label %34
    i32 1, label %39
    i32 2, label %44
  ]

34:                                               ; preds = %29
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = call noundef i64 @_ZL31ma_noise_read_pcm_frames__whiteP8ma_noisePvy(ptr noundef %35, ptr noundef %36, i64 noundef %37)
  store i64 %38, ptr %10, align 8, !tbaa !9
  br label %50

39:                                               ; preds = %29
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = call noundef i64 @_ZL30ma_noise_read_pcm_frames__pinkP8ma_noisePvy(ptr noundef %40, ptr noundef %41, i64 noundef %42)
  store i64 %43, ptr %10, align 8, !tbaa !9
  br label %50

44:                                               ; preds = %29
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = call noundef i64 @_ZL34ma_noise_read_pcm_frames__brownianP8ma_noisePvy(ptr noundef %45, ptr noundef %46, i64 noundef %47)
  store i64 %48, ptr %10, align 8, !tbaa !9
  br label %50

49:                                               ; preds = %29
  store i32 -3, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

50:                                               ; preds = %44, %39, %34
  br label %51

51:                                               ; preds = %50, %27
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %57

54:                                               ; preds = %51
  %55 = load i64, ptr %10, align 8, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %55, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %54, %51
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

58:                                               ; preds = %57, %49, %23, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %59 = load i32, ptr %5, align 4
  ret i32 %59
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL31ma_noise_read_pcm_frames__whiteP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL30ma_noise_read_pcm_frames__pinkP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL34ma_noise_read_pcm_frames__brownianP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) #2

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 = { alwaysinline 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, !17, i64 64}
!12 = !{!"_ZTS8ma_noise", !13, i64 0, !15, i64 56, !19, i64 88, !7, i64 96, !6, i64 120, !14, i64 128}
!13 = !{!"_ZTS21ma_data_source_vtable", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS15ma_noise_config", !16, i64 0, !14, i64 4, !17, i64 8, !14, i64 12, !18, i64 16, !14, i64 24}
!16 = !{!"_ZTS9ma_format", !7, i64 0}
!17 = !{!"_ZTS13ma_noise_type", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!"_ZTS6ma_lcg", !14, 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
define dso_local range(i32 -3, 1) i32 @ma_noise_read_pcm_frames(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %4
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %4
  %7 = icmp eq i64 %2, 0
  %8 = icmp eq ptr %0, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %22, label %9

9:                                                ; preds = %6
  %10 = icmp eq ptr %1, null
  br i1 %10, label %20, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = load i32, ptr %12, align 8, !tbaa !9
  switch i32 %13, label %22 [
    i32 0, label %14
    i32 1, label %16
    i32 2, label %18
  ]

14:                                               ; preds = %11
  %15 = tail call noundef i64 @_ZL31ma_noise_read_pcm_frames__whiteP8ma_noisePvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %20

16:                                               ; preds = %11
  %17 = tail call noundef i64 @_ZL30ma_noise_read_pcm_frames__pinkP8ma_noisePvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %20

18:                                               ; preds = %11
  %19 = tail call noundef i64 @_ZL34ma_noise_read_pcm_frames__brownianP8ma_noisePvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %20

20:                                               ; preds = %9, %14, %16, %18
  %.0 = phi i64 [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %2, %9 ]
  br i1 %.not, label %22, label %21

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

22:                                               ; preds = %20, %21, %11, %6
  %.019 = phi i32 [ -2, %6 ], [ -3, %11 ], [ 0, %21 ], [ 0, %20 ]
  ret i32 %.019
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL31ma_noise_read_pcm_frames__whiteP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL30ma_noise_read_pcm_frames__pinkP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZL34ma_noise_read_pcm_frames__brownianP8ma_noisePvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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 = { alwaysinline 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" }

!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, !16, i64 64}
!10 = !{!"_ZTS8ma_noise", !11, i64 0, !14, i64 56, !18, i64 88, !7, i64 96, !12, i64 120, !13, i64 128}
!11 = !{!"_ZTS21ma_data_source_vtable", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !13, i64 48}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS15ma_noise_config", !15, i64 0, !13, i64 4, !16, i64 8, !13, i64 12, !17, i64 16, !13, i64 24}
!15 = !{!"_ZTS9ma_format", !7, i64 0}
!16 = !{!"_ZTS13ma_noise_type", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!"_ZTS6ma_lcg", !13, i64 0}


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