; 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 = type { %struct.drmp3dec, %struct.drmp3dec_frame_info, i32, i32, ptr, ptr, ptr, %struct.drmp3_allocation_callbacks, i32, i32, i32, i32, [9216 x i8], i64, i64, %struct.drmp3_src, ptr, i32, i64, i64, ptr, i8, %struct.anon.0 }
%struct.drmp3dec = type { [2 x [288 x float]], [960 x float], i32, i32, [4 x i8], [511 x i8] }
%struct.drmp3dec_frame_info = type { i32, i32, i32, i32, i32 }
%struct.drmp3_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drmp3_src = type { %struct.drmp3_src_config, ptr, ptr, [256 x float], %struct.drmp3_src_cache, %union.anon }
%struct.drmp3_src_config = type { i32, i32, i32, i32, i32 }
%struct.drmp3_src_cache = type { ptr, [1024 x float], i32, i32 }
%union.anon = type { %struct.anon }
%struct.anon = type { double, i8 }
%struct.anon.0 = type { ptr, i64, i64 }

; 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
declare dso_local void @drmp3dec_f32_to_s16(ptr noundef, ptr noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local i64 @drmp3_read_pcm_frames_s16(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 [4096 x float], align 16
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  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 16384, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %20, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.drmp3, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %15, %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %78

21:                                               ; preds = %15
  br label %22

22:                                               ; preds = %75, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = sub i64 %23, %24
  store i64 %25, ptr %12, align 8, !tbaa !9
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.drmp3, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %30 = zext i32 %29 to i64
  %31 = udiv i64 4096, %30
  %32 = icmp ugt i64 %26, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %22
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.drmp3, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !22
  %37 = zext i32 %36 to i64
  %38 = udiv i64 4096, %37
  store i64 %38, ptr %12, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %33, %22
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = getelementptr inbounds [4096 x float], ptr %8, i64 0, i64 0
  %43 = call i64 @drmp3_read_pcm_frames_f32(ptr noundef %40, i64 noundef %41, ptr noundef %42)
  store i64 %43, ptr %9, align 8, !tbaa !9
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  store i32 2, ptr %11, align 4
  br label %73

47:                                               ; preds = %39
  %48 = getelementptr inbounds [4096 x float], ptr %8, i64 0, i64 0
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.drmp3, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !22
  %54 = zext i32 %53 to i64
  %55 = mul i64 %50, %54
  %56 = trunc i64 %55 to i32
  call void @drmp3dec_f32_to_s16(ptr noundef %48, ptr noundef %49, i32 noundef %56)
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.drmp3, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 8, !tbaa !22
  %61 = zext i32 %60 to i64
  %62 = mul i64 %57, %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds i16, ptr %63, i64 %62
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = load i64, ptr %10, align 8, !tbaa !9
  %67 = add i64 %66, %65
  store i64 %67, ptr %10, align 8, !tbaa !9
  %68 = load i64, ptr %9, align 8, !tbaa !9
  %69 = load i64, ptr %12, align 8, !tbaa !9
  %70 = icmp ult i64 %68, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %47
  store i32 2, ptr %11, align 4
  br label %73

72:                                               ; preds = %47
  store i32 0, ptr %11, align 4
  br label %73

73:                                               ; preds = %72, %71, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %74 = load i32, ptr %11, align 4
  switch i32 %74, label %80 [
    i32 0, label %75
    i32 2, label %76
  ]

75:                                               ; preds = %73
  br label %22, !llvm.loop !23

76:                                               ; preds = %73
  %77 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %77, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %78

78:                                               ; preds = %76, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16384, ptr %8) #3
  %79 = load i64, ptr %4, align 8
  ret i64 %79

80:                                               ; preds = %73
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="128" "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 = { 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", !7, i64 0}
!11 = !{!12, !6, i64 6696}
!12 = !{!"_ZTS5drmp3", !13, i64 0, !15, i64 6668, !14, i64 6688, !14, i64 6692, !6, i64 6696, !6, i64 6704, !6, i64 6712, !16, i64 6720, !14, i64 6752, !14, i64 6756, !14, i64 6760, !14, i64 6764, !7, i64 6768, !10, i64 15984, !10, i64 15992, !17, i64 16000, !6, i64 21192, !14, i64 21200, !10, i64 21208, !10, i64 21216, !6, i64 21224, !14, i64 21232, !21, i64 21240}
!13 = !{!"_ZTS8drmp3dec", !7, i64 0, !7, i64 2304, !14, i64 6144, !14, i64 6148, !7, i64 6152, !7, i64 6156}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS19drmp3dec_frame_info", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16}
!16 = !{!"_ZTS26drmp3_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"_ZTS9drmp3_src", !18, i64 0, !6, i64 24, !6, i64 32, !7, i64 40, !20, i64 1064, !7, i64 5176}
!18 = !{!"_ZTS16drmp3_src_config", !14, i64 0, !14, i64 4, !14, i64 8, !19, i64 12, !14, i64 16}
!19 = !{!"_ZTS19drmp3_src_algorithm", !7, i64 0}
!20 = !{!"_ZTS15drmp3_src_cache", !6, i64 0, !7, i64 8, !14, i64 4104, !14, i64 4108}
!21 = !{!"_ZTSN5drmp3Ut_E", !6, i64 0, !10, i64 8, !10, i64 16}
!22 = !{!12, !14, i64 6688}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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 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 uwtable
declare dso_local void @drmp3dec_f32_to_s16(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local i64 @drmp3_read_pcm_frames_s16(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [4096 x float], align 16
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %4) #4
  %5 = icmp eq ptr %0, null
  br i1 %5, label %.thread, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 6696
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.thread, label %.preheader

.preheader:                                       ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 6688
  %.pre = load i32, ptr %10, align 8, !tbaa !20
  br label %11

11:                                               ; preds = %.preheader, %18
  %12 = phi i32 [ %22, %18 ], [ %.pre, %.preheader ]
  %.025 = phi ptr [ %25, %18 ], [ %2, %.preheader ]
  %.023 = phi i64 [ %26, %18 ], [ 0, %.preheader ]
  %13 = sub i64 %1, %.023
  %14 = udiv i32 4096, %12
  %15 = zext nneg i32 %14 to i64
  %spec.select = call i64 @llvm.umin.i64(i64 %13, i64 %15)
  %16 = call i64 @drmp3_read_pcm_frames_f32(ptr noundef nonnull %0, i64 noundef %spec.select, ptr noundef nonnull %4)
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %10, align 8, !tbaa !20
  %20 = trunc i64 %16 to i32
  %21 = mul i32 %19, %20
  call void @drmp3dec_f32_to_s16(ptr noundef nonnull %4, ptr noundef %.025, i32 noundef %21)
  %22 = load i32, ptr %10, align 8, !tbaa !20
  %23 = zext i32 %22 to i64
  %24 = mul i64 %16, %23
  %25 = getelementptr inbounds i16, ptr %.025, i64 %24
  %26 = add i64 %16, %.023
  %27 = icmp ult i64 %16, %spec.select
  br i1 %27, label %.thread, label %11

.thread:                                          ; preds = %18, %11, %3, %6
  %.024 = phi i64 [ 0, %6 ], [ 0, %3 ], [ %26, %18 ], [ %.023, %11 ]
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %4) #4
  ret i64 %.024
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="128" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 6696}
!6 = !{!"_ZTS5drmp3", !7, i64 0, !11, i64 6668, !10, i64 6688, !10, i64 6692, !12, i64 6696, !12, i64 6704, !12, i64 6712, !13, i64 6720, !10, i64 6752, !10, i64 6756, !10, i64 6760, !10, i64 6764, !8, i64 6768, !14, i64 15984, !14, i64 15992, !15, i64 16000, !12, i64 21192, !10, i64 21200, !14, i64 21208, !14, i64 21216, !12, i64 21224, !10, i64 21232, !19, i64 21240}
!7 = !{!"_ZTS8drmp3dec", !8, i64 0, !8, i64 2304, !10, i64 6144, !10, i64 6148, !8, i64 6152, !8, i64 6156}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS19drmp3dec_frame_info", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"_ZTS26drmp3_allocation_callbacks", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!14 = !{!"long", !8, i64 0}
!15 = !{!"_ZTS9drmp3_src", !16, i64 0, !12, i64 24, !12, i64 32, !8, i64 40, !18, i64 1064, !8, i64 5176}
!16 = !{!"_ZTS16drmp3_src_config", !10, i64 0, !10, i64 4, !10, i64 8, !17, i64 12, !10, i64 16}
!17 = !{!"_ZTS19drmp3_src_algorithm", !8, i64 0}
!18 = !{!"_ZTS15drmp3_src_cache", !12, i64 0, !8, i64 8, !10, i64 4104, !10, i64 4108}
!19 = !{!"_ZTSN5drmp3Ut_E", !12, i64 0, !14, i64 8, !14, i64 16}
!20 = !{!6, !10, i64 6688}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass