; 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.drwav = type { ptr, ptr, ptr, ptr, %struct.drwav_allocation_callbacks, i32, %struct.drwav_fmt, i32, i16, i16, i16, i64, i64, i64, i64, i64, i64, i32, i32, ptr, i32, %struct.drwav__memory_stream, %struct.drwav__memory_stream_write, %struct.anon.57, %struct.anon.58 }
%struct.drwav_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drwav_fmt = type { i16, i16, i32, i32, i16, i16, i16, i16, i32, [16 x i8] }
%struct.drwav__memory_stream = type { ptr, i64, i64 }
%struct.drwav__memory_stream_write = type { ptr, ptr, i64, i64, i64 }
%struct.anon.57 = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.58 = type { i32, [2 x i32], [2 x i32], [16 x i32], i32 }

; 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 nounwind uwtable
declare hidden noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drwav_read_pcm_frames_le(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local i64 @drwav_read_pcm_frames_be(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call i64 @drwav_read_pcm_frames_le(ptr noundef %11, i64 noundef %12, ptr noundef %13)
  store i64 %14, ptr %8, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %43

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef %18)
  store i32 %19, ptr %9, align 4, !tbaa !11
  %20 = load i32, ptr %9, align 4, !tbaa !11
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %40

23:                                               ; preds = %17
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.drwav, ptr %26, i32 0, i32 8
  %28 = load i16, ptr %27, align 8, !tbaa !13
  %29 = zext i16 %28 to i64
  %30 = mul i64 %25, %29
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.drwav, ptr %32, i32 0, i32 8
  %34 = load i16, ptr %33, align 8, !tbaa !13
  %35 = zext i16 %34 to i32
  %36 = udiv i32 %31, %35
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.drwav, ptr %37, i32 0, i32 10
  %39 = load i16, ptr %38, align 4, !tbaa !25
  call void @_ZL20drwav__bswap_samplesPvyjt(ptr noundef %24, i64 noundef %30, i32 noundef %36, i16 noundef zeroext %39)
  store i32 0, ptr %10, align 4
  br label %40

40:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %41 = load i32, ptr %10, align 4
  switch i32 %41, label %45 [
    i32 0, label %42
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42, %3
  %44 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %44, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %45

45:                                               ; preds = %43, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %46 = load i64, ptr %4, align 8
  ret i64 %46
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden void @_ZL20drwav__bswap_samplesPvyjt(ptr noundef, i64 noundef, i32 noundef, i16 noundef zeroext) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !18, i64 112}
!14 = !{!"_ZTS5drwav", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !16, i64 64, !17, i64 68, !12, i64 108, !18, i64 112, !18, i64 114, !18, i64 116, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !12, i64 168, !19, i64 172, !6, i64 176, !12, i64 184, !20, i64 192, !22, i64 216, !23, i64 256, !24, i64 308}
!15 = !{!"_ZTS26drwav_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"_ZTS15drwav_container", !7, i64 0}
!17 = !{!"_ZTS9drwav_fmt", !18, i64 0, !18, i64 2, !12, i64 4, !12, i64 8, !18, i64 12, !18, i64 14, !18, i64 16, !18, i64 18, !12, i64 20, !7, i64 24}
!18 = !{!"short", !7, i64 0}
!19 = !{!"_ZTS19drwav_metadata_type", !7, i64 0}
!20 = !{!"_ZTS20drwav__memory_stream", !6, i64 0, !21, i64 8, !21, i64 16}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTS26drwav__memory_stream_write", !6, i64 0, !6, i64 8, !21, i64 16, !21, i64 24, !21, i64 32}
!23 = !{!"_ZTSN5drwavUt_E", !12, i64 0, !7, i64 4, !7, i64 8, !7, i64 16, !12, i64 32, !7, i64 36}
!24 = !{!"_ZTSN5drwavUt0_E", !12, i64 0, !7, i64 4, !7, i64 12, !7, i64 20, !12, i64 84}
!25 = !{!14, !18, i64 116}


; 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 nounwind uwtable
declare hidden noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local i64 @drwav_read_pcm_frames_le(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @drwav_read_pcm_frames_be(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call i64 @drwav_read_pcm_frames_le(ptr noundef %0, i64 noundef %1, ptr noundef %2)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.critedge, label %5

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef %0)
  %.not17 = icmp eq i32 %6, 0
  br i1 %.not17, label %.critedge, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  %9 = load i16, ptr %8, align 8, !tbaa !5
  %10 = zext i16 %9 to i64
  %11 = mul i64 %4, %10
  %12 = zext i16 %9 to i32
  %13 = udiv i32 %6, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 116
  %15 = load i16, ptr %14, align 4, !tbaa !22
  tail call void @_ZL20drwav__bswap_samplesPvyjt(ptr noundef nonnull %2, i64 noundef %11, i32 noundef %13, i16 noundef zeroext %15)
  br label %.critedge

.critedge:                                        ; preds = %3, %7, %5
  %.1 = phi i64 [ 0, %5 ], [ %4, %7 ], [ %4, %3 ]
  ret i64 %.1
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden void @_ZL20drwav__bswap_samplesPvyjt(ptr noundef, i64 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #2

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

!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, !13, i64 112}
!6 = !{!"_ZTS5drwav", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 64, !12, i64 68, !14, i64 108, !13, i64 112, !13, i64 114, !13, i64 116, !15, i64 120, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !14, i64 168, !16, i64 172, !7, i64 176, !14, i64 184, !17, i64 192, !19, i64 216, !20, i64 256, !21, i64 308}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS26drwav_allocation_callbacks", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!11 = !{!"_ZTS15drwav_container", !8, i64 0}
!12 = !{!"_ZTS9drwav_fmt", !13, i64 0, !13, i64 2, !14, i64 4, !14, i64 8, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18, !14, i64 20, !8, i64 24}
!13 = !{!"short", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = !{!"_ZTS19drwav_metadata_type", !8, i64 0}
!17 = !{!"_ZTS20drwav__memory_stream", !7, i64 0, !18, i64 8, !18, i64 16}
!18 = !{!"long", !8, i64 0}
!19 = !{!"_ZTS26drwav__memory_stream_write", !7, i64 0, !7, i64 8, !18, i64 16, !18, i64 24, !18, i64 32}
!20 = !{!"_ZTSN5drwavUt_E", !14, i64 0, !8, i64 4, !8, i64 8, !8, i64 16, !14, i64 32, !8, i64 36}
!21 = !{!"_ZTSN5drwavUt0_E", !14, i64 0, !8, i64 4, !8, i64 12, !8, i64 20, !14, i64 84}
!22 = !{!6, !13, i64 116}


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