; LLVM IR from merpheus-dev/LavaEngine :: src/Utils/soloud/src/audiosource/wav (dr_impl)

; 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.drmp3_src_config = type { i32, i32, i32, i32, i32 }
%struct.drmp3_src = type { %struct.drmp3_src_config, ptr, ptr, [256 x float], %struct.drmp3_src_cache, %union.anon }
%struct.drmp3_src_cache = type { ptr, [1024 x float], i32, i32 }
%union.anon = type { %struct.anon }
%struct.anon = type { double, i8 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; 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) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z14drmp3_src_initPK16drmp3_src_configPFmP9drmp3_srcmPvS4_ES4_S3_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, 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 ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

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

13:                                               ; preds = %4
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 5192, i1 false)
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %13
  store i32 0, ptr %5, align 4
  br label %61

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.drmp3_src_config, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %31, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.drmp3_src_config, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp ugt i32 %29, 2
  br i1 %30, label %31, label %32

31:                                               ; preds = %26, %21
  store i32 0, ptr %5, align 4
  br label %61

32:                                               ; preds = %26
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.drmp3_src, ptr %34, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %35, ptr align 4 %33, i64 20, i1 false), !tbaa.struct !13
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.drmp3_src, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !16
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.drmp3_src, ptr %40, i32 0, i32 2
  store ptr %39, ptr %41, align 8, !tbaa !19
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.drmp3_src, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.drmp3_src_config, ptr %43, i32 0, i32 4
  %45 = load i32, ptr %44, align 8, !tbaa !20
  %46 = icmp ugt i32 %45, 512
  br i1 %46, label %53, label %47

47:                                               ; preds = %32
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.drmp3_src, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.drmp3_src_config, ptr %49, i32 0, i32 4
  %51 = load i32, ptr %50, align 8, !tbaa !20
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %57

53:                                               ; preds = %47, %32
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.drmp3_src, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds %struct.drmp3_src_config, ptr %55, i32 0, i32 4
  store i32 512, ptr %56, align 8, !tbaa !20
  br label %57

57:                                               ; preds = %53, %47
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.drmp3_src, ptr %59, i32 0, i32 4
  call void @_Z20drmp3_src_cache_initP9drmp3_srcP15drmp3_src_cache(ptr noundef %58, ptr noundef %60)
  store i32 1, ptr %5, align 4
  br label %61

61:                                               ; preds = %57, %31, %20, %12
  %62 = load i32, ptr %5, align 4
  ret i32 %62
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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, !11, i64 8}
!10 = !{!"_ZTS16drmp3_src_config", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 12, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS19drmp3_src_algorithm", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 4, !14, i64 12, i64 4, !15, i64 16, i64 4, !14}
!14 = !{!11, !11, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !6, i64 24}
!17 = !{!"_ZTS9drmp3_src", !10, i64 0, !6, i64 24, !6, i64 32, !7, i64 40, !18, i64 1064, !7, i64 5176}
!18 = !{!"_ZTS15drmp3_src_cache", !6, i64 0, !7, i64 8, !11, i64 4104, !11, i64 4108}
!19 = !{!17, !6, i64 32}
!20 = !{!17, !11, i64 16}


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

; 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) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z20drmp3_src_cache_initP9drmp3_srcP15drmp3_src_cache(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z14drmp3_src_initPK16drmp3_src_configPFmP9drmp3_srcmPvS4_ES4_S3_(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = icmp eq ptr %3, null
  br i1 %5, label %22, label %6

6:                                                ; preds = %4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(5192) %3, i8 0, i64 5192, i1 false)
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %1, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %22, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add i32 %11, -3
  %or.cond23 = icmp ult i32 %12, -2
  br i1 %or.cond23, label %22, label %13

13:                                               ; preds = %9
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %3, ptr noundef nonnull align 4 dereferenceable(20) %0, i64 20, i1 false), !tbaa.struct !11
  %14 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %1, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %2, ptr %15, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %3, i64 16
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = add i32 %17, -513
  %or.cond24 = icmp ult i32 %18, -512
  br i1 %or.cond24, label %19, label %20

19:                                               ; preds = %13
  store i32 512, ptr %16, align 8, !tbaa !19
  br label %20

20:                                               ; preds = %13, %19
  %21 = getelementptr inbounds i8, ptr %3, i64 1064
  tail call void @_Z20drmp3_src_cache_initP9drmp3_srcP15drmp3_src_cache(ptr noundef nonnull %3, ptr noundef nonnull %21)
  br label %22

22:                                               ; preds = %9, %6, %4, %20
  %.0 = phi i32 [ 1, %20 ], [ 0, %4 ], [ 0, %6 ], [ 0, %9 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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 8}
!6 = !{!"_ZTS16drmp3_src_config", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS19drmp3_src_algorithm", !8, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !13, i64 16, i64 4, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !16, i64 24}
!15 = !{!"_ZTS9drmp3_src", !6, i64 0, !16, i64 24, !16, i64 32, !8, i64 40, !17, i64 1064, !8, i64 5176}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTS15drmp3_src_cache", !16, i64 0, !8, i64 8, !7, i64 4104, !7, i64 4108}
!18 = !{!15, !16, i64 32}
!19 = !{!15, !7, i64 16}


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