; 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.drflac = type { ptr, ptr, %struct.drflac_allocation_callbacks, i32, i8, i8, i16, i64, i32, i32, %struct.drflac_frame, i64, i64, %struct.drflac__memory_stream, ptr, ptr, ptr, i8, %struct.drflac_bs, [1 x i8] }
%struct.drflac_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%struct.drflac_frame = type { %struct.drflac_frame_header, i32, [8 x %struct.drflac_subframe] }
%struct.drflac_frame_header = type { i64, i32, i32, i16, i8, i8, i8 }
%struct.drflac_subframe = type { i8, i8, i8, ptr }
%struct.drflac__memory_stream = type { ptr, i64, i64 }
%struct.drflac_bs = type { ptr, ptr, ptr, i64, i64, i32, i32, [512 x i64], i64, i16, i64, 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 uwtable
define dso_local noundef i64 @_Z34drflac__seek_forward_by_pcm_framesP6drflacm(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %59, %2
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = icmp ugt i64 %7, 0
  br i1 %8, label %9, label %60

9:                                                ; preds = %6
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.drflac, ptr %10, i32 0, i32 10
  %12 = getelementptr inbounds %struct.drflac_frame, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call noundef i32 @_ZL39drflac__read_and_decode_next_flac_frameP6drflac(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  br label %60

20:                                               ; preds = %15
  br label %59

21:                                               ; preds = %9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.drflac, ptr %22, i32 0, i32 10
  %24 = getelementptr inbounds %struct.drflac_frame, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = icmp ugt i64 %26, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %21
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = add i64 %31, %30
  store i64 %32, ptr %5, align 8, !tbaa !9
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.drflac, ptr %35, i32 0, i32 10
  %37 = getelementptr inbounds %struct.drflac_frame, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = sub i32 %38, %34
  store i32 %39, ptr %37, align 8, !tbaa !11
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %58

40:                                               ; preds = %21
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.drflac, ptr %41, i32 0, i32 10
  %43 = getelementptr inbounds %struct.drflac_frame, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = zext i32 %44 to i64
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = add i64 %46, %45
  store i64 %47, ptr %5, align 8, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.drflac, ptr %48, i32 0, i32 10
  %50 = getelementptr inbounds %struct.drflac_frame, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = zext i32 %51 to i64
  %53 = load i64, ptr %4, align 8, !tbaa !9
  %54 = sub i64 %53, %52
  store i64 %54, ptr %4, align 8, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.drflac, ptr %55, i32 0, i32 10
  %57 = getelementptr inbounds %struct.drflac_frame, ptr %56, i32 0, i32 1
  store i32 0, ptr %57, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %40, %29
  br label %59

59:                                               ; preds = %58, %20
  br label %6, !llvm.loop !21

60:                                               ; preds = %19, %6
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.drflac, ptr %62, i32 0, i32 11
  %64 = load i64, ptr %63, align 8, !tbaa !23
  %65 = add i64 %64, %61
  store i64 %65, ptr %63, align 8, !tbaa !23
  %66 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %66
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL39drflac__read_and_decode_next_flac_frameP6drflac(ptr noundef) #1

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, !14, i64 96}
!12 = !{!"_ZTS6drflac", !6, i64 0, !6, i64 8, !13, i64 16, !14, i64 48, !7, i64 52, !7, i64 53, !15, i64 54, !10, i64 56, !16, i64 64, !14, i64 68, !17, i64 72, !10, i64 232, !10, i64 240, !19, i64 248, !6, i64 272, !6, i64 280, !6, i64 288, !14, i64 296, !14, i64 296, !14, i64 296, !20, i64 304, !7, i64 4480}
!13 = !{!"_ZTS27drflac_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"int", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTS16drflac_container", !7, i64 0}
!17 = !{!"_ZTS12drflac_frame", !18, i64 0, !14, i64 24, !7, i64 32}
!18 = !{!"_ZTS19drflac_frame_header", !10, i64 0, !14, i64 8, !14, i64 12, !15, i64 16, !7, i64 18, !7, i64 19, !7, i64 20}
!19 = !{!"_ZTS21drflac__memory_stream", !6, i64 0, !10, i64 8, !10, i64 16}
!20 = !{!"_ZTS9drflac_bs", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !14, i64 40, !14, i64 44, !7, i64 48, !10, i64 4144, !15, i64 4152, !10, i64 4160, !14, i64 4168}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!12, !10, i64 232}


; 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 uwtable
define dso_local noundef i64 @_Z34drflac__seek_forward_by_pcm_framesP6drflacm(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not21 = icmp eq i64 %1, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  br label %4

4:                                                ; preds = %.lr.ph, %18
  %.023 = phi i64 [ 0, %.lr.ph ], [ %.1, %18 ]
  %.01622 = phi i64 [ %1, %.lr.ph ], [ %.117, %18 ]
  %5 = load i32, ptr %3, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_ZL39drflac__read_and_decode_next_flac_frameP6drflac(ptr noundef nonnull %0)
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %._crit_edge, label %18

9:                                                ; preds = %4
  %10 = zext i32 %5 to i64
  %11 = icmp ult i64 %.01622, %10
  br i1 %11, label %.thread, label %15

.thread:                                          ; preds = %9
  %12 = add i64 %.023, %.01622
  %13 = trunc nuw i64 %.01622 to i32
  %14 = sub i32 %5, %13
  store i32 %14, ptr %3, align 8, !tbaa !5
  br label %._crit_edge

15:                                               ; preds = %9
  %16 = add i64 %.023, %10
  %17 = sub i64 %.01622, %10
  store i32 0, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %15, %7
  %.117 = phi i64 [ %.01622, %7 ], [ %17, %15 ]
  %.1 = phi i64 [ %.023, %7 ], [ %16, %15 ]
  %.not = icmp eq i64 %.117, 0
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !19

._crit_edge:                                      ; preds = %18, %7, %.thread, %2
  %.0.lcssa = phi i64 [ 0, %2 ], [ %12, %.thread ], [ %.023, %7 ], [ %.1, %18 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 232
  %20 = load i64, ptr %19, align 8, !tbaa !21
  %21 = add i64 %20, %.0.lcssa
  store i64 %21, ptr %19, align 8, !tbaa !21
  ret i64 %.0.lcssa
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL39drflac__read_and_decode_next_flac_frameP6drflac(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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, !11, i64 96}
!6 = !{!"_ZTS6drflac", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 48, !8, i64 52, !8, i64 53, !12, i64 54, !13, i64 56, !14, i64 64, !11, i64 68, !15, i64 72, !13, i64 232, !13, i64 240, !17, i64 248, !7, i64 272, !7, i64 280, !7, i64 288, !11, i64 296, !11, i64 296, !11, i64 296, !18, i64 304, !8, i64 4480}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS27drflac_allocation_callbacks", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"_ZTS16drflac_container", !8, i64 0}
!15 = !{!"_ZTS12drflac_frame", !16, i64 0, !11, i64 24, !8, i64 32}
!16 = !{!"_ZTS19drflac_frame_header", !13, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !8, i64 18, !8, i64 19, !8, i64 20}
!17 = !{!"_ZTS21drflac__memory_stream", !7, i64 0, !13, i64 8, !13, i64 16}
!18 = !{!"_ZTS9drflac_bs", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !11, i64 44, !8, i64 48, !13, i64 4144, !12, i64 4152, !13, i64 4160, !11, i64 4168}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !13, i64 232}


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