; LLVM IR from VoidRune/Audio-engine :: src (minivorbis)

; 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.codebook = type { i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, 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: inlinehint nounwind uwtable
declare hidden i64 @decode_packed_entry_number(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @vorbis_book_decodev_set(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.codebook, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %20, label %74

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %69, %20
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %70

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call i64 @decode_packed_entry_number(ptr noundef %26, ptr noundef %27)
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %71

33:                                               ; preds = %25
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.codebook, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.codebook, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = mul nsw i64 %38, %41
  %43 = getelementptr inbounds float, ptr %36, i64 %42
  store ptr %43, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %57, %33
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %44
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.codebook, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = icmp slt i64 %50, %53
  br label %55

55:                                               ; preds = %48, %44
  %56 = phi i1 [ false, %44 ], [ %54, %48 ]
  br i1 %56, label %57, label %69

57:                                               ; preds = %55
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  %61 = sext i32 %59 to i64
  %62 = getelementptr inbounds float, ptr %58, i64 %61
  %63 = load float, ptr %62, align 4, !tbaa !16
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !9
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds float, ptr %64, i64 %67
  store float %63, ptr %68, align 4, !tbaa !16
  br label %44, !llvm.loop !18

69:                                               ; preds = %55
  br label %21, !llvm.loop !20

70:                                               ; preds = %21
  store i32 0, ptr %14, align 4
  br label %71

71:                                               ; preds = %70, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %72 = load i32, ptr %14, align 4
  switch i32 %72, label %89 [
    i32 0, label %73
    i32 1, label %87
  ]

73:                                               ; preds = %71
  br label %86

74:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %79, %74
  %76 = load i32, ptr %15, align 4, !tbaa !9
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %85

79:                                               ; preds = %75
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %15, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %15, align 4, !tbaa !9
  %83 = sext i32 %81 to i64
  %84 = getelementptr inbounds float, ptr %80, i64 %83
  store float 0.000000e+00, ptr %84, align 4, !tbaa !16
  br label %75, !llvm.loop !21

85:                                               ; preds = %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %86

86:                                               ; preds = %85, %73
  store i64 0, ptr %5, align 8
  br label %87

87:                                               ; preds = %86, %71
  %88 = load i64, ptr %5, align 8
  ret i64 %88

89:                                               ; preds = %71
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"codebook", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!12, !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


; 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: inlinehint nounwind uwtable
declare hidden i64 @decode_packed_entry_number(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -1, 1) i64 @vorbis_book_decodev_set(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = ptrtoint ptr %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 0
  %9 = icmp sgt i32 %3, 0
  br i1 %8, label %.preheader, label %.preheader31

.preheader31:                                     ; preds = %4
  br i1 %9, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %.preheader31
  %10 = zext nneg i32 %3 to i64
  %11 = shl nuw nsw i64 %10, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %1, i8 0, i64 %11, i1 false), !tbaa !12
  br label %.thread

.preheader:                                       ; preds = %4
  br i1 %9, label %.lr.ph40, label %.thread

.lr.ph40:                                         ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = zext nneg i32 %3 to i64
  br label %14

14:                                               ; preds = %.lr.ph40, %.critedge
  %.02439 = phi i32 [ 0, %.lr.ph40 ], [ %.125.lcssa, %.critedge ]
  %15 = tail call i64 @decode_packed_entry_number(ptr noundef %0, ptr noundef %2)
  %16 = and i64 %15, 4294967295
  %17 = icmp eq i64 %16, 4294967295
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %14
  %19 = load ptr, ptr %12, align 8, !tbaa !14
  %20 = ptrtoint ptr %19 to i64
  %sext = shl i64 %15, 32
  %21 = ashr exact i64 %sext, 32
  %22 = load i64, ptr %0, align 8, !tbaa !15
  %23 = mul nsw i64 %22, %21
  %24 = getelementptr inbounds float, ptr %19, i64 %23
  %25 = icmp slt i32 %.02439, %3
  br i1 %25, label %.lr.ph36.preheader, label %.critedge

.lr.ph36.preheader:                               ; preds = %18
  %26 = sext i32 %.02439 to i64
  %smax = tail call i64 @llvm.smax.i64(i64 %22, i64 0)
  %27 = sub nsw i64 %13, %26
  %28 = xor i64 %26, -1
  %29 = add nsw i64 %28, %13
  %umin = tail call i64 @llvm.umin.i64(i64 %smax, i64 %29)
  %30 = add nuw i64 %umin, 1
  %min.iters.check = icmp ult i64 %umin, 8
  br i1 %min.iters.check, label %.lr.ph36.preheader54, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph36.preheader
  %31 = shl nsw i64 %26, 2
  %32 = add i64 %31, %5
  %33 = shl i64 %22, 2
  %34 = mul i64 %33, %21
  %35 = add i64 %34, %20
  %36 = sub i64 %32, %35
  %diff.check = icmp ult i64 %36, 32
  br i1 %diff.check, label %.lr.ph36.preheader54, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.mod.vf = and i64 %30, 7
  %37 = icmp eq i64 %n.mod.vf, 0
  %38 = select i1 %37, i64 8, i64 %n.mod.vf
  %n.vec = sub i64 %30, %38
  %ind.end = add i64 %n.vec, %26
  %invariant.gep = getelementptr float, ptr %1, i64 %26
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %39 = getelementptr inbounds float, ptr %24, i64 %index
  %40 = getelementptr inbounds i8, ptr %39, i64 16
  %wide.load = load <4 x float>, ptr %39, align 4, !tbaa !12
  %wide.load53 = load <4 x float>, ptr %40, align 4, !tbaa !12
  %gep = getelementptr float, ptr %invariant.gep, i64 %index
  %41 = getelementptr inbounds i8, ptr %gep, i64 16
  store <4 x float> %wide.load, ptr %gep, align 4, !tbaa !12
  store <4 x float> %wide.load53, ptr %41, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %42 = icmp eq i64 %index.next, %n.vec
  br i1 %42, label %.lr.ph36.preheader54, label %vector.body, !llvm.loop !16

.lr.ph36.preheader54:                             ; preds = %vector.body, %vector.memcheck, %.lr.ph36.preheader
  %indvars.iv46.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph36.preheader ], [ %n.vec, %vector.body ]
  %indvars.iv.ph = phi i64 [ %26, %vector.memcheck ], [ %26, %.lr.ph36.preheader ], [ %ind.end, %vector.body ]
  br label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph36.preheader54, %43
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %43 ], [ %indvars.iv46.ph, %.lr.ph36.preheader54 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %43 ], [ %indvars.iv.ph, %.lr.ph36.preheader54 ]
  %exitcond.not = icmp eq i64 %indvars.iv46, %smax
  br i1 %exitcond.not, label %.critedge.loopexit, label %43

43:                                               ; preds = %.lr.ph36
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %44 = getelementptr inbounds float, ptr %24, i64 %indvars.iv46
  %45 = load float, ptr %44, align 4, !tbaa !12
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %45, ptr %46, align 4, !tbaa !12
  %exitcond51.not = icmp eq i64 %indvars.iv.next47, %27
  br i1 %exitcond51.not, label %.critedge.loopexit, label %.lr.ph36, !llvm.loop !20

.critedge.loopexit:                               ; preds = %43, %.lr.ph36
  %.125.lcssa.ph.in = phi i64 [ %indvars.iv, %.lr.ph36 ], [ %indvars.iv.next, %43 ]
  %.125.lcssa.ph = trunc i64 %.125.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %18
  %.125.lcssa = phi i32 [ %.02439, %18 ], [ %.125.lcssa.ph, %.critedge.loopexit ]
  %47 = icmp slt i32 %.125.lcssa, %3
  br i1 %47, label %14, label %.thread, !llvm.loop !21

.thread:                                          ; preds = %14, %.critedge, %.lr.ph.preheader, %.preheader31, %.preheader
  %.1 = phi i64 [ 0, %.preheader ], [ 0, %.preheader31 ], [ 0, %.lr.ph.preheader ], [ -1, %14 ], [ 0, %.critedge ]
  ret i64 %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

attributes #0 = { inlinehint 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 #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 16}
!6 = !{!"codebook", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !18}
!21 = distinct !{!21, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass