; 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 noundef i64 @_Z24drmp3_src_read_frames_exP9drmp3_srcmPvj(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @drmp3_read_pcm_frames_f32(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %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 [4096 x float], align 16
  %11 = alloca i64, align 8
  %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 8, ptr %8) #2
  store i64 0, ptr %8, 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 %9, align 4
  br label %71

21:                                               ; preds = %15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %58

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 16384, ptr %10) #2
  br label %25

25:                                               ; preds = %56, %24
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp ugt i64 %26, 0
  br i1 %27, label %28, label %57

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.drmp3, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !22
  %32 = zext i32 %31 to i64
  %33 = udiv i64 4096, %32
  store i64 %33, ptr %12, align 8, !tbaa !9
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp ugt i64 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %28
  %38 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %38, ptr %12, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %37, %28
  %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 %10, 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 %11, align 8, !tbaa !9
  %44 = load i64, ptr %11, align 8, !tbaa !9
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  store i32 3, ptr %9, align 4
  br label %54

47:                                               ; preds = %39
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = sub i64 %49, %48
  store i64 %50, ptr %6, align 8, !tbaa !9
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = add i64 %52, %51
  store i64 %53, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %54

54:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %55 = load i32, ptr %9, align 4
  switch i32 %55, label %73 [
    i32 0, label %56
    i32 3, label %57
  ]

56:                                               ; preds = %54
  br label %25, !llvm.loop !23

57:                                               ; preds = %54, %25
  call void @llvm.lifetime.end.p0(i64 16384, ptr %10) #2
  br label %69

58:                                               ; preds = %21
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.drmp3, ptr %59, i32 0, i32 15
  %61 = load i64, ptr %6, align 8, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = call noundef i64 @_Z24drmp3_src_read_frames_exP9drmp3_srcmPvj(ptr noundef %60, i64 noundef %61, ptr noundef %62, i32 noundef 1)
  store i64 %63, ptr %8, align 8, !tbaa !9
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.drmp3, ptr %65, i32 0, i32 13
  %67 = load i64, ptr %66, align 8, !tbaa !25
  %68 = add i64 %67, %64
  store i64 %68, ptr %66, align 8, !tbaa !25
  br label %69

69:                                               ; preds = %58, %57
  %70 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %70, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %69, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %72 = load i64, ptr %4, align 8
  ret i64 %72

73:                                               ; preds = %54
  unreachable
}

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 = { 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"}
!25 = !{!12, !10, i64 15984}


; 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 noundef i64 @_Z24drmp3_src_read_frames_exP9drmp3_srcmPvj(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @drmp3_read_pcm_frames_f32(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [4096 x float], align 16
  %5 = icmp eq ptr %0, null
  br i1 %5, label %30, 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 %30, label %10

10:                                               ; preds = %6
  %11 = icmp eq ptr %2, null
  br i1 %11, label %12, label %24

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %4) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 6688
  br label %14

14:                                               ; preds = %15, %12
  %.025 = phi i64 [ %1, %12 ], [ %21, %15 ]
  %.024 = phi i64 [ 0, %12 ], [ %22, %15 ]
  %.not = icmp eq i64 %.025, 0
  br i1 %.not, label %23, label %15

15:                                               ; preds = %14
  %16 = load i32, ptr %13, align 8, !tbaa !20
  %17 = udiv i32 4096, %16
  %18 = zext nneg i32 %17 to i64
  %spec.select = call i64 @llvm.umin.i64(i64 %.025, i64 %18)
  %19 = call i64 @drmp3_read_pcm_frames_f32(ptr noundef nonnull %0, i64 noundef %spec.select, ptr noundef nonnull %4)
  %20 = icmp eq i64 %19, 0
  %21 = sub i64 %.025, %19
  %22 = add i64 %19, %.024
  br i1 %20, label %23, label %14

23:                                               ; preds = %15, %14
  %.2 = phi i64 [ %22, %15 ], [ %.024, %14 ]
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %4) #3
  br label %30

24:                                               ; preds = %10
  %25 = getelementptr inbounds i8, ptr %0, i64 16000
  %26 = tail call noundef i64 @_Z24drmp3_src_read_frames_exP9drmp3_srcmPvj(ptr noundef nonnull %25, i64 noundef %1, ptr noundef nonnull %2, i32 noundef 1)
  %27 = getelementptr inbounds i8, ptr %0, i64 15984
  %28 = load i64, ptr %27, align 8, !tbaa !21
  %29 = add i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !21
  br label %30

30:                                               ; preds = %23, %24, %3, %6
  %.022 = phi i64 [ 0, %6 ], [ 0, %3 ], [ %.2, %23 ], [ %26, %24 ]
  ret i64 %.022
}

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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}
!21 = !{!6, !14, i64 15984}


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