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

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_waveform_read_pcm_frames(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %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
  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
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %14

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

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

17:                                               ; preds = %14
  store i32 -2, ptr %5, align 4
  br label %65

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

21:                                               ; preds = %18
  store i32 -2, ptr %5, align 4
  br label %65

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %48

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ma_waveform, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.ma_waveform_config, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !11
  switch i32 %29, label %46 [
    i32 0, label %30
    i32 1, label %34
    i32 2, label %38
    i32 3, label %42
  ]

30:                                               ; preds = %25
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZL33ma_waveform_read_pcm_frames__sineP11ma_waveformPvy(ptr noundef %31, ptr noundef %32, i64 noundef %33)
  br label %47

34:                                               ; preds = %25
  %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
  call void @_ZL35ma_waveform_read_pcm_frames__squareP11ma_waveformPvy(ptr noundef %35, ptr noundef %36, i64 noundef %37)
  br label %47

38:                                               ; preds = %25
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZL37ma_waveform_read_pcm_frames__triangleP11ma_waveformPvy(ptr noundef %39, ptr noundef %40, i64 noundef %41)
  br label %47

42:                                               ; preds = %25
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZL37ma_waveform_read_pcm_frames__sawtoothP11ma_waveformPvy(ptr noundef %43, ptr noundef %44, i64 noundef %45)
  br label %47

46:                                               ; preds = %25
  store i32 -3, ptr %5, align 4
  br label %65

47:                                               ; preds = %42, %38, %34, %30
  br label %58

48:                                               ; preds = %22
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ma_waveform, ptr %49, i32 0, i32 2
  %51 = load double, ptr %50, align 8, !tbaa !19
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = sitofp i64 %52 to double
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ma_waveform, ptr %54, i32 0, i32 3
  %56 = load double, ptr %55, align 8, !tbaa !20
  %57 = call double @llvm.fmuladd.f64(double %51, double %53, double %56)
  store double %57, ptr %55, align 8, !tbaa !20
  br label %58

58:                                               ; preds = %48, %47
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %64

61:                                               ; preds = %58
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %62, ptr %63, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %61, %58
  store i32 0, ptr %5, align 4
  br label %65

65:                                               ; preds = %64, %46, %21, %17
  %66 = load i32, ptr %5, align 4
  ret i32 %66
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ma_waveform_read_pcm_frames__sineP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35ma_waveform_read_pcm_frames__squareP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL37ma_waveform_read_pcm_frames__triangleP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL37ma_waveform_read_pcm_frames__sawtoothP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 84}
!12 = !{!"_ZTS11ma_waveform", !13, i64 0, !15, i64 72, !18, i64 104, !18, i64 112}
!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 = !{!"_ZTS18ma_waveform_config", !16, i64 0, !14, i64 4, !14, i64 8, !17, i64 12, !18, i64 16, !18, i64 24}
!16 = !{!"_ZTS9ma_format", !7, i64 0}
!17 = !{!"_ZTS16ma_waveform_type", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!12, !18, i64 104}
!20 = !{!12, !18, 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"

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -3, 1) i32 @ma_waveform_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 %26, label %9

9:                                                ; preds = %6
  %.not28 = icmp eq ptr %1, null
  br i1 %.not28, label %17, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %0, i64 84
  %12 = load i32, ptr %11, align 4, !tbaa !9
  switch i32 %12, label %26 [
    i32 0, label %13
    i32 1, label %14
    i32 2, label %15
    i32 3, label %16
  ]

13:                                               ; preds = %10
  tail call void @_ZL33ma_waveform_read_pcm_frames__sineP11ma_waveformPvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %24

14:                                               ; preds = %10
  tail call void @_ZL35ma_waveform_read_pcm_frames__squareP11ma_waveformPvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %24

15:                                               ; preds = %10
  tail call void @_ZL37ma_waveform_read_pcm_frames__triangleP11ma_waveformPvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %24

16:                                               ; preds = %10
  tail call void @_ZL37ma_waveform_read_pcm_frames__sawtoothP11ma_waveformPvy(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2)
  br label %24

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %0, i64 104
  %19 = load double, ptr %18, align 8, !tbaa !18
  %20 = sitofp i64 %2 to double
  %21 = getelementptr inbounds i8, ptr %0, i64 112
  %22 = load double, ptr %21, align 8, !tbaa !19
  %23 = tail call double @llvm.fmuladd.f64(double %19, double %20, double %22)
  store double %23, ptr %21, align 8, !tbaa !19
  br label %24

24:                                               ; preds = %13, %14, %15, %16, %17
  br i1 %.not, label %26, label %25

25:                                               ; preds = %24
  store i64 %2, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %24, %25, %10, %6
  %.0 = phi i32 [ -2, %6 ], [ -3, %10 ], [ 0, %25 ], [ 0, %24 ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL33ma_waveform_read_pcm_frames__sineP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL35ma_waveform_read_pcm_frames__squareP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL37ma_waveform_read_pcm_frames__triangleP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL37ma_waveform_read_pcm_frames__sawtoothP11ma_waveformPvy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 84}
!10 = !{!"_ZTS11ma_waveform", !11, i64 0, !14, i64 72, !17, i64 104, !17, i64 112}
!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 = !{!"_ZTS18ma_waveform_config", !15, i64 0, !13, i64 4, !13, i64 8, !16, i64 12, !17, i64 16, !17, i64 24}
!15 = !{!"_ZTS9ma_format", !7, i64 0}
!16 = !{!"_ZTS16ma_waveform_type", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!10, !17, i64 104}
!19 = !{!10, !17, i64 112}


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