; 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.drwav = type { ptr, ptr, ptr, ptr, %struct.drwav_allocation_callbacks, i32, %struct.drwav_fmt, i32, i16, i16, i16, i64, i64, i64, i64, i64, i32, %struct.drwav_smpl, %struct.drwav__memory_stream, %struct.drwav__memory_stream_write, %struct.anon.1, %struct.anon.2, %struct.anon.3 }
%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_smpl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [1 x %struct.drwav_smpl_loop] }
%struct.drwav_smpl_loop = type { i32, i32, i32, i32, i32, i32 }
%struct.drwav__memory_stream = type { ptr, i64, i64 }
%struct.drwav__memory_stream_write = type { ptr, ptr, i64, i64, i64 }
%struct.anon.1 = type { i64 }
%struct.anon.2 = type { i32, [2 x i16], [2 x i32], [4 x i32], i32, [2 x [2 x i32]] }
%struct.anon.3 = 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(ptr noundef, i64 noundef, ptr noundef) #2

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

17:                                               ; preds = %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %76

18:                                               ; preds = %3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %73, %18
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = icmp ugt i64 %20, 0
  br i1 %21, label %22, label %74

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = udiv i64 4096, %26
  %28 = icmp ult i64 %24, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %22
  %30 = load i64, ptr %6, align 8, !tbaa !9
  br label %35

31:                                               ; preds = %22
  %32 = load i32, ptr %10, align 4, !tbaa !11
  %33 = zext i32 %32 to i64
  %34 = udiv i64 4096, %33
  br label %35

35:                                               ; preds = %31, %29
  %36 = phi i64 [ %30, %29 ], [ %34, %31 ]
  %37 = getelementptr inbounds [4096 x i8], ptr %9, i64 0, i64 0
  %38 = call i64 @drwav_read_pcm_frames(ptr noundef %23, i64 noundef %36, ptr noundef %37)
  store i64 %38, ptr %12, align 8, !tbaa !9
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i32 3, ptr %11, align 4
  br label %71

42:                                               ; preds = %35
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds [4096 x i8], ptr %9, i64 0, i64 0
  %45 = load i64, ptr %12, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.drwav, ptr %46, i32 0, i32 8
  %48 = load i16, ptr %47, align 8, !tbaa !13
  %49 = zext i16 %48 to i64
  %50 = mul i64 %45, %49
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.drwav, ptr %52, i32 0, i32 8
  %54 = load i16, ptr %53, align 8, !tbaa !13
  %55 = zext i16 %54 to i32
  %56 = udiv i32 %51, %55
  call void @_ZL17drwav__pcm_to_f32PfPKhmj(ptr noundef %43, ptr noundef %44, i64 noundef %50, i32 noundef %56)
  %57 = load i64, ptr %12, align 8, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.drwav, ptr %58, i32 0, i32 8
  %60 = load i16, ptr %59, align 8, !tbaa !13
  %61 = zext i16 %60 to i64
  %62 = mul i64 %57, %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds float, ptr %63, i64 %62
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load i64, ptr %12, align 8, !tbaa !9
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = sub i64 %66, %65
  store i64 %67, ptr %6, align 8, !tbaa !9
  %68 = load i64, ptr %12, align 8, !tbaa !9
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = add i64 %69, %68
  store i64 %70, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %71

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

73:                                               ; preds = %71
  br label %19, !llvm.loop !25

74:                                               ; preds = %71, %19
  %75 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %75, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %76

76:                                               ; preds = %74, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4096, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %77 = load i64, ptr %4, align 8
  ret i64 %77

78:                                               ; preds = %71
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL17drwav__pcm_to_f32PfPKhmj(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #1

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 = { 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, !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, !12, i64 160, !19, i64 164, !20, i64 224, !21, i64 248, !22, i64 288, !23, i64 296, !24, i64 348}
!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 = !{!"_ZTS10drwav_smpl", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !7, i64 36}
!20 = !{!"_ZTS20drwav__memory_stream", !6, i64 0, !10, i64 8, !10, i64 16}
!21 = !{!"_ZTS26drwav__memory_stream_write", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!22 = !{!"_ZTSN5drwavUt_E", !10, i64 0}
!23 = !{!"_ZTSN5drwavUt0_E", !12, i64 0, !7, i64 4, !7, i64 8, !7, i64 16, !12, i64 32, !7, i64 36}
!24 = !{!"_ZTSN5drwavUt1_E", !12, i64 0, !7, i64 4, !7, i64 12, !7, i64 20, !12, i64 84}
!25 = distinct !{!25, !26}
!26 = !{!"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 nounwind uwtable
declare hidden noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z30drwav_read_pcm_frames_f32__pcmP5drwavmPf(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %4) #4
  %5 = tail call noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef %0)
  %6 = icmp eq i32 %5, 0
  %.not37 = icmp eq i64 %1, 0
  %or.cond = or i1 %6, %.not37
  br i1 %or.cond, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = udiv i32 4096, %5
  %8 = zext nneg i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  br label %10

10:                                               ; preds = %.lr.ph, %13
  %.02440 = phi i64 [ %1, %.lr.ph ], [ %23, %13 ]
  %.02539 = phi i64 [ 0, %.lr.ph ], [ %24, %13 ]
  %.02738 = phi ptr [ %2, %.lr.ph ], [ %22, %13 ]
  %.024. = call i64 @llvm.umin.i64(i64 %.02440, i64 %8)
  %11 = call i64 @drwav_read_pcm_frames(ptr noundef %0, i64 noundef %.024., ptr noundef nonnull %4)
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %10
  %14 = load i16, ptr %9, align 8, !tbaa !5
  %15 = zext i16 %14 to i64
  %16 = mul i64 %11, %15
  %17 = zext i16 %14 to i32
  %18 = udiv i32 %5, %17
  call void @_ZL17drwav__pcm_to_f32PfPKhmj(ptr noundef %.02738, ptr noundef nonnull %4, i64 noundef %16, i32 noundef %18)
  %19 = load i16, ptr %9, align 8, !tbaa !5
  %20 = zext i16 %19 to i64
  %21 = mul i64 %11, %20
  %22 = getelementptr inbounds float, ptr %.02738, i64 %21
  %23 = sub i64 %.02440, %11
  %24 = add i64 %11, %.02539
  %.not = icmp eq i64 %23, 0
  br i1 %.not, label %.thread, label %10

.thread:                                          ; preds = %13, %10, %3
  %.0 = phi i64 [ 0, %3 ], [ %24, %13 ], [ %.02539, %10 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %4) #4
  ret i64 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL17drwav__pcm_to_f32PfPKhmj(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; 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 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 = { 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, !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, !14, i64 160, !16, i64 164, !17, i64 224, !18, i64 248, !19, i64 288, !20, i64 296, !21, i64 348}
!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", !8, i64 0}
!16 = !{!"_ZTS10drwav_smpl", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !8, i64 36}
!17 = !{!"_ZTS20drwav__memory_stream", !7, i64 0, !15, i64 8, !15, i64 16}
!18 = !{!"_ZTS26drwav__memory_stream_write", !7, i64 0, !7, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!19 = !{!"_ZTSN5drwavUt_E", !15, i64 0}
!20 = !{!"_ZTSN5drwavUt0_E", !14, i64 0, !8, i64 4, !8, i64 8, !8, i64 16, !14, i64 32, !8, i64 36}
!21 = !{!"_ZTSN5drwavUt1_E", !14, i64 0, !8, i64 4, !8, i64 12, !8, i64 20, !14, i64 84}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass