; 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: nounwind uwtable
define dso_local i64 @vorbis_book_decodev_add(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %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
  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
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.codebook, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %19, label %75

19:                                               ; 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 %20

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

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

31:                                               ; preds = %24
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %72

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

43:                                               ; preds = %56, %32
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %54

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

54:                                               ; preds = %47, %43
  %55 = phi i1 [ false, %43 ], [ %53, %47 ]
  br i1 %55, label %56, label %70

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

70:                                               ; preds = %54
  br label %20, !llvm.loop !20

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

72:                                               ; preds = %71, %31
  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
  %73 = load i32, ptr %14, align 4
  switch i32 %73, label %78 [
    i32 0, label %74
    i32 1, label %76
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74, %4
  store i64 0, ptr %5, align 8
  br label %76

76:                                               ; preds = %75, %72
  %77 = load i64, ptr %5, align 8
  ret i64 %77

78:                                               ; preds = %72
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @decode_packed_entry_number(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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}


; 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: nounwind uwtable
define dso_local range(i64 -1, 1) i64 @vorbis_book_decodev_add(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  %8 = icmp sgt i32 %3, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %.lr.ph31, label %.thread

.lr.ph31:                                         ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = zext nneg i32 %3 to i64
  %scevgep41 = getelementptr i8, ptr %1, i64 4
  br label %11

11:                                               ; preds = %.lr.ph31, %.critedge
  %.01930 = phi i32 [ 0, %.lr.ph31 ], [ %.120.lcssa, %.critedge ]
  %12 = tail call i64 @decode_packed_entry_number(ptr noundef %0, ptr noundef %2)
  %13 = and i64 %12, 4294967295
  %14 = icmp eq i64 %13, 4294967295
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %11
  %16 = load ptr, ptr %9, align 8, !tbaa !12
  %sext = shl i64 %12, 32
  %17 = ashr exact i64 %sext, 32
  %18 = load i64, ptr %0, align 8, !tbaa !13
  %19 = mul i64 %18, %17
  %20 = getelementptr float, ptr %16, i64 %19
  %21 = icmp slt i32 %.01930, %3
  br i1 %21, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %15
  %22 = sext i32 %.01930 to i64
  %smax = tail call i64 @llvm.smax.i64(i64 %18, i64 0)
  %23 = sub nsw i64 %10, %22
  %24 = xor i64 %22, -1
  %25 = add nsw i64 %24, %10
  %umin45 = tail call i64 @llvm.umin.i64(i64 %smax, i64 %25)
  %26 = add nuw i64 %umin45, 1
  %min.iters.check = icmp ult i64 %umin45, 8
  br i1 %min.iters.check, label %.lr.ph.preheader50, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %27 = shl nsw i64 %22, 2
  %scevgep = getelementptr i8, ptr %1, i64 %27
  %28 = xor i64 %22, -1
  %29 = add nsw i64 %28, %10
  %umin = tail call i64 @llvm.umin.i64(i64 %smax, i64 %29)
  %30 = shl i64 %umin, 2
  %31 = getelementptr i8, ptr %scevgep41, i64 %30
  %scevgep42 = getelementptr i8, ptr %31, i64 %27
  %scevgep43 = getelementptr i8, ptr %16, i64 4
  %32 = shl i64 %18, 2
  %33 = mul i64 %32, %17
  %34 = getelementptr i8, ptr %scevgep43, i64 %33
  %scevgep44 = getelementptr i8, ptr %34, i64 %30
  %bound0 = icmp ult ptr %scevgep, %scevgep44
  %bound1 = icmp ult ptr %20, %scevgep42
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader50, label %vector.ph

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

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %37 = getelementptr inbounds float, ptr %20, i64 %index
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %wide.load = load <4 x float>, ptr %37, align 4, !tbaa !14, !alias.scope !16
  %wide.load47 = load <4 x float>, ptr %38, align 4, !tbaa !14, !alias.scope !16
  %gep = getelementptr float, ptr %invariant.gep, i64 %index
  %39 = getelementptr inbounds i8, ptr %gep, i64 16
  %wide.load48 = load <4 x float>, ptr %gep, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %wide.load49 = load <4 x float>, ptr %39, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %40 = fadd <4 x float> %wide.load, %wide.load48
  %41 = fadd <4 x float> %wide.load47, %wide.load49
  store <4 x float> %40, ptr %gep, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  store <4 x float> %41, ptr %39, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 8
  %42 = icmp eq i64 %index.next, %n.vec
  br i1 %42, label %.lr.ph.preheader50, label %vector.body, !llvm.loop !21

.lr.ph.preheader50:                               ; preds = %vector.body, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv35.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %vector.body ]
  %indvars.iv.ph = phi i64 [ %22, %vector.memcheck ], [ %22, %.lr.ph.preheader ], [ %ind.end, %vector.body ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader50, %43
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %43 ], [ %indvars.iv35.ph, %.lr.ph.preheader50 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %43 ], [ %indvars.iv.ph, %.lr.ph.preheader50 ]
  %exitcond.not = icmp eq i64 %indvars.iv35, %smax
  br i1 %exitcond.not, label %.critedge.loopexit, label %43

43:                                               ; preds = %.lr.ph
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %44 = getelementptr inbounds float, ptr %20, i64 %indvars.iv35
  %45 = load float, ptr %44, align 4, !tbaa !14
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %47 = load float, ptr %46, align 4, !tbaa !14
  %48 = fadd float %45, %47
  store float %48, ptr %46, align 4, !tbaa !14
  %exitcond40.not = icmp eq i64 %indvars.iv.next36, %23
  br i1 %exitcond40.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !25

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

.critedge:                                        ; preds = %.critedge.loopexit, %15
  %.120.lcssa = phi i32 [ %.01930, %15 ], [ %.120.lcssa.ph, %.critedge.loopexit ]
  %49 = icmp slt i32 %.120.lcssa, %3
  br i1 %49, label %11, label %.thread, !llvm.loop !26

.thread:                                          ; preds = %11, %.critedge, %4
  %.1 = phi i64 [ 0, %4 ], [ -1, %11 ], [ 0, %.critedge ]
  ret i64 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @decode_packed_entry_number(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

attributes #0 = { 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 = { 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 = { 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 = !{!6, !10, i64 32}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!17}
!17 = distinct !{!17, !18}
!18 = distinct !{!18, !"LVerDomain"}
!19 = !{!20}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !22, !23, !24}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.isvectorized", i32 1}
!24 = !{!"llvm.loop.unroll.runtime.disable"}
!25 = distinct !{!25, !22, !23}
!26 = distinct !{!26, !22}


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