; 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_s16__pcmP5drwavmPs(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 i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca [4096 x i8], align 16
  %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 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4096, ptr %10) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.drwav, ptr %13, i32 0, i32 10
  %15 = load i16, ptr %14, align 4, !tbaa !11
  %16 = zext i16 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %29

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.drwav, ptr %19, i32 0, i32 9
  %21 = load i16, ptr %20, align 2, !tbaa !24
  %22 = zext i16 %21 to i32
  %23 = icmp eq i32 %22, 16
  br i1 %23, label %24, label %29

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 @drwav_read_pcm_frames(ptr noundef %25, i64 noundef %26, ptr noundef %27)
  store i64 %28, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %93

29:                                               ; preds = %18, %3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef %30)
  store i32 %31, ptr %8, align 4, !tbaa !25
  %32 = load i32, ptr %8, align 4, !tbaa !25
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %93

35:                                               ; preds = %29
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %90, %35
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = icmp ugt i64 %37, 0
  br i1 %38, label %39, label %91

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !25
  %43 = zext i32 %42 to i64
  %44 = udiv i64 4096, %43
  %45 = icmp ult i64 %41, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %39
  %47 = load i64, ptr %6, align 8, !tbaa !9
  br label %52

48:                                               ; preds = %39
  %49 = load i32, ptr %8, align 4, !tbaa !25
  %50 = zext i32 %49 to i64
  %51 = udiv i64 4096, %50
  br label %52

52:                                               ; preds = %48, %46
  %53 = phi i64 [ %47, %46 ], [ %51, %48 ]
  %54 = getelementptr inbounds [4096 x i8], ptr %10, i64 0, i64 0
  %55 = call i64 @drwav_read_pcm_frames(ptr noundef %40, i64 noundef %53, ptr noundef %54)
  store i64 %55, ptr %12, align 8, !tbaa !9
  %56 = load i64, ptr %12, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  store i32 3, ptr %11, align 4
  br label %88

59:                                               ; preds = %52
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds [4096 x i8], ptr %10, i64 0, i64 0
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.drwav, ptr %63, i32 0, i32 8
  %65 = load i16, ptr %64, align 8, !tbaa !26
  %66 = zext i16 %65 to i64
  %67 = mul i64 %62, %66
  %68 = load i32, ptr %8, align 4, !tbaa !25
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.drwav, ptr %69, i32 0, i32 8
  %71 = load i16, ptr %70, align 8, !tbaa !26
  %72 = zext i16 %71 to i32
  %73 = udiv i32 %68, %72
  call void @_ZL17drwav__pcm_to_s16PsPKhmj(ptr noundef %60, ptr noundef %61, i64 noundef %67, i32 noundef %73)
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.drwav, ptr %75, i32 0, i32 8
  %77 = load i16, ptr %76, align 8, !tbaa !26
  %78 = zext i16 %77 to i64
  %79 = mul i64 %74, %78
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds i16, ptr %80, i64 %79
  store ptr %81, ptr %7, align 8, !tbaa !5
  %82 = load i64, ptr %12, align 8, !tbaa !9
  %83 = load i64, ptr %6, align 8, !tbaa !9
  %84 = sub i64 %83, %82
  store i64 %84, ptr %6, align 8, !tbaa !9
  %85 = load i64, ptr %12, align 8, !tbaa !9
  %86 = load i64, ptr %9, align 8, !tbaa !9
  %87 = add i64 %86, %85
  store i64 %87, ptr %9, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %88

88:                                               ; preds = %59, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %89 = load i32, ptr %11, align 4
  switch i32 %89, label %95 [
    i32 0, label %90
    i32 3, label %91
  ]

90:                                               ; preds = %88
  br label %36, !llvm.loop !27

91:                                               ; preds = %88, %36
  %92 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %92, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %93

93:                                               ; preds = %91, %34, %24
  call void @llvm.lifetime.end.p0(i64 4096, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %94 = load i64, ptr %4, align 8
  ret i64 %94

95:                                               ; preds = %88
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL17drwav__pcm_to_s16PsPKhmj(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, !16, i64 116}
!12 = !{!"_ZTS5drwav", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !14, i64 64, !15, i64 68, !17, i64 108, !16, i64 112, !16, i64 114, !16, i64 116, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !17, i64 160, !18, i64 164, !19, i64 224, !20, i64 248, !21, i64 288, !22, i64 296, !23, i64 348}
!13 = !{!"_ZTS26drwav_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"_ZTS15drwav_container", !7, i64 0}
!15 = !{!"_ZTS9drwav_fmt", !16, i64 0, !16, i64 2, !17, i64 4, !17, i64 8, !16, i64 12, !16, i64 14, !16, i64 16, !16, i64 18, !17, i64 20, !7, i64 24}
!16 = !{!"short", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"_ZTS10drwav_smpl", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20, !17, i64 24, !17, i64 28, !17, i64 32, !7, i64 36}
!19 = !{!"_ZTS20drwav__memory_stream", !6, i64 0, !10, i64 8, !10, i64 16}
!20 = !{!"_ZTS26drwav__memory_stream_write", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!21 = !{!"_ZTSN5drwavUt_E", !10, i64 0}
!22 = !{!"_ZTSN5drwavUt0_E", !17, i64 0, !7, i64 4, !7, i64 8, !7, i64 16, !17, i64 32, !7, i64 36}
!23 = !{!"_ZTSN5drwavUt1_E", !17, i64 0, !7, i64 4, !7, i64 12, !7, i64 20, !17, i64 84}
!24 = !{!12, !16, i64 114}
!25 = !{!17, !17, i64 0}
!26 = !{!12, !16, i64 112}
!27 = distinct !{!27, !28}
!28 = !{!"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_s16__pcmP5drwavmPs(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 = getelementptr inbounds i8, ptr %0, i64 116
  %6 = load i16, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i16 %6, 1
  br i1 %7, label %8, label %14

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 114
  %10 = load i16, ptr %9, align 2, !tbaa !22
  %11 = icmp eq i16 %10, 16
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = tail call i64 @drwav_read_pcm_frames(ptr noundef nonnull %0, i64 noundef %1, ptr noundef %2)
  br label %.thread

14:                                               ; preds = %8, %3
  %15 = tail call noundef i32 @_ZL29drwav_get_bytes_per_pcm_frameP5drwav(ptr noundef nonnull %0)
  %16 = icmp eq i32 %15, 0
  %.not42 = icmp eq i64 %1, 0
  %or.cond = or i1 %16, %.not42
  br i1 %or.cond, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %14
  %17 = udiv i32 4096, %15
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 112
  br label %20

20:                                               ; preds = %.lr.ph, %23
  %.02945 = phi i64 [ 0, %.lr.ph ], [ %34, %23 ]
  %.03044 = phi i64 [ %1, %.lr.ph ], [ %33, %23 ]
  %.03243 = phi ptr [ %2, %.lr.ph ], [ %32, %23 ]
  %.030. = call i64 @llvm.umin.i64(i64 %.03044, i64 %18)
  %21 = call i64 @drwav_read_pcm_frames(ptr noundef nonnull %0, i64 noundef %.030., ptr noundef nonnull %4)
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %20
  %24 = load i16, ptr %19, align 8, !tbaa !23
  %25 = zext i16 %24 to i64
  %26 = mul i64 %21, %25
  %27 = zext i16 %24 to i32
  %28 = udiv i32 %15, %27
  call void @_ZL17drwav__pcm_to_s16PsPKhmj(ptr noundef %.03243, ptr noundef nonnull %4, i64 noundef %26, i32 noundef %28)
  %29 = load i16, ptr %19, align 8, !tbaa !23
  %30 = zext i16 %29 to i64
  %31 = mul i64 %21, %30
  %32 = getelementptr inbounds i16, ptr %.03243, i64 %31
  %33 = sub i64 %.03044, %21
  %34 = add i64 %21, %.02945
  %.not = icmp eq i64 %33, 0
  br i1 %.not, label %.thread, label %20

.thread:                                          ; preds = %23, %20, %14, %12
  %.0 = phi i64 [ %13, %12 ], [ 0, %14 ], [ %34, %23 ], [ %.02945, %20 ]
  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_s16PsPKhmj(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 116}
!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}
!22 = !{!6, !13, i64 114}
!23 = !{!6, !13, i64 112}


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