; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/wav (soloud_wav)

; 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"

%"class.SoLoud::Wav" = type <{ %"class.SoLoud::AudioSource", ptr, i32, [4 x i8] }>
%"class.SoLoud::AudioSource" = type { ptr, i32, float, float, i32, i32, float, float, float, i32, float, [8 x ptr], ptr, ptr, ptr, i32, double }

; 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

declare void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152)) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud3Wav12loadRawWave8EPhjfj(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef %1, i32 noundef %2, float noundef %3, i32 noundef %4) #5 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store float %3, ptr %10, align 4, !tbaa !11
  store i32 %4, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %25, label %16

16:                                               ; preds = %5
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %25, label %19

19:                                               ; preds = %16
  %20 = load float, ptr %10, align 4, !tbaa !11
  %21 = fcmp ole float %20, 0.000000e+00
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp ult i32 %23, 1
  br i1 %24, label %25, label %26

25:                                               ; preds = %22, %19, %16, %5
  store i32 1, ptr %6, align 4
  br label %71

26:                                               ; preds = %22
  call void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152) %13)
  %27 = getelementptr inbounds %"class.SoLoud::Wav", ptr %13, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp eq ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @_ZdaPv(ptr noundef %28) #6
  br label %31

31:                                               ; preds = %30, %26
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %33, i64 4)
  %35 = extractvalue { i64, i1 } %34, 1
  %36 = extractvalue { i64, i1 } %34, 0
  %37 = select i1 %35, i64 -1, i64 %36
  %38 = call noalias noundef nonnull ptr @_Znam(i64 noundef %37) #7
  %39 = getelementptr inbounds %"class.SoLoud::Wav", ptr %13, i32 0, i32 1
  store ptr %38, ptr %39, align 8, !tbaa !13
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = udiv i32 %40, %41
  %43 = getelementptr inbounds %"class.SoLoud::Wav", ptr %13, i32 0, i32 2
  store i32 %42, ptr %43, align 8, !tbaa !17
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %13, i32 0, i32 4
  store i32 %44, ptr %45, align 4, !tbaa !18
  %46 = load float, ptr %10, align 4, !tbaa !11
  %47 = getelementptr inbounds %"class.SoLoud::AudioSource", ptr %13, i32 0, i32 2
  store float %46, ptr %47, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %67, %31
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %52, label %70

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !20
  %58 = zext i8 %57 to i32
  %59 = sub nsw i32 %58, 128
  %60 = sitofp i32 %59 to float
  %61 = fdiv float %60, 1.280000e+02
  %62 = getelementptr inbounds %"class.SoLoud::Wav", ptr %13, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds float, ptr %63, i64 %65
  store float %61, ptr %66, align 4, !tbaa !11
  br label %67

67:                                               ; preds = %52
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %12, align 4, !tbaa !9
  br label %48, !llvm.loop !21

70:                                               ; preds = %48
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %71

71:                                               ; preds = %70, %25
  %72 = load i32, ptr %6, align 4
  ret i32 %72
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nobuiltin nounwind "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 = { nobuiltin allocsize(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 #5 = { 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 #6 = { builtin nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 152}
!14 = !{!"_ZTSN6SoLoud3WavE", !15, i64 0, !6, i64 152, !10, i64 160}
!15 = !{!"_ZTSN6SoLoud11AudioSourceE", !10, i64 8, !12, i64 12, !12, i64 16, !10, i64 20, !10, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !10, i64 40, !12, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !16, i64 144}
!16 = !{!"double", !7, i64 0}
!17 = !{!14, !10, i64 160}
!18 = !{!15, !10, i64 20}
!19 = !{!15, !12, i64 12}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

declare void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN6SoLoud3Wav12loadRawWave8EPhjfj(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef readonly %1, i32 noundef %2, float noundef %3, i32 noundef %4) local_unnamed_addr #3 align 2 {
  %6 = icmp eq ptr %1, null
  %7 = icmp eq i32 %2, 0
  %or.cond = or i1 %6, %7
  %8 = fcmp ole float %3, 0.000000e+00
  %or.cond3 = or i1 %or.cond, %8
  %9 = icmp eq i32 %4, 0
  %or.cond5 = or i1 %or.cond3, %9
  br i1 %or.cond5, label %.loopexit, label %10

10:                                               ; preds = %5
  tail call void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152) %0)
  %11 = getelementptr inbounds i8, ptr %0, i64 152
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %.lr.ph.preheader, label %14

14:                                               ; preds = %10
  tail call void @_ZdaPv(ptr noundef nonnull %12) #4
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %10, %14
  %15 = zext i32 %2 to i64
  %16 = shl nuw nsw i64 %15, 2
  %17 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %16) #5
  store ptr %17, ptr %11, align 8, !tbaa !5
  %18 = udiv i32 %2, %4
  %19 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %4, ptr %20, align 4, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  store float %3, ptr %21, align 4, !tbaa !16
  %min.iters.check = icmp ult i32 %2, 8
  br i1 %min.iters.check, label %.lr.ph.preheader30, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %15, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = getelementptr inbounds i8, ptr %1, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %wide.load = load <4 x i8>, ptr %22, align 1, !tbaa !17
  %wide.load29 = load <4 x i8>, ptr %23, align 1, !tbaa !17
  %24 = zext <4 x i8> %wide.load to <4 x i32>
  %25 = zext <4 x i8> %wide.load29 to <4 x i32>
  %26 = add nsw <4 x i32> %24, <i32 -128, i32 -128, i32 -128, i32 -128>
  %27 = add nsw <4 x i32> %25, <i32 -128, i32 -128, i32 -128, i32 -128>
  %28 = sitofp <4 x i32> %26 to <4 x float>
  %29 = sitofp <4 x i32> %27 to <4 x float>
  %30 = fmul <4 x float> %28, <float 7.812500e-03, float 7.812500e-03, float 7.812500e-03, float 7.812500e-03>
  %31 = fmul <4 x float> %29, <float 7.812500e-03, float 7.812500e-03, float 7.812500e-03, float 7.812500e-03>
  %32 = getelementptr inbounds float, ptr %17, i64 %index
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store <4 x float> %30, ptr %32, align 4, !tbaa !18
  store <4 x float> %31, ptr %33, align 4, !tbaa !18
  %index.next = add nuw i64 %index, 8
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %15
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader30

.lr.ph.preheader30:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader30, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader30 ]
  %35 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %36 = load i8, ptr %35, align 1, !tbaa !17
  %37 = zext i8 %36 to i32
  %38 = add nsw i32 %37, -128
  %39 = sitofp i32 %38 to float
  %40 = fmul float %39, 7.812500e-03
  %41 = getelementptr inbounds float, ptr %17, i64 %indvars.iv
  store float %40, ptr %41, align 4, !tbaa !18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %15
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %5
  %.021 = phi i32 [ 1, %5 ], [ 0, %middle.block ], [ 0, %.lr.ph ]
  ret i32 %.021
}

attributes #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 #1 = { nobuiltin nounwind "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 = { nobuiltin allocsize(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 = { 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 #4 = { builtin nounwind }
attributes #5 = { builtin allocsize(0) }

!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 152}
!6 = !{!"_ZTSN6SoLoud3WavE", !7, i64 0, !12, i64 152, !8, i64 160}
!7 = !{!"_ZTSN6SoLoud11AudioSourceE", !8, i64 8, !11, i64 12, !11, i64 16, !8, i64 20, !8, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !11, i64 44, !9, i64 48, !12, i64 112, !12, i64 120, !12, i64 128, !8, i64 136, !13, i64 144}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{!6, !8, i64 160}
!15 = !{!7, !8, i64 20}
!16 = !{!7, !11, i64 12}
!17 = !{!9, !9, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !22, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass