; 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_decodevv_add(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) #1 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !11
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !11
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.codebook, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %103

25:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = load i32, ptr %13, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = add nsw i64 %26, %28
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = sdiv i64 %29, %31
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %18, align 4, !tbaa !11
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = sdiv i64 %34, %36
  store i64 %37, ptr %14, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %98, %25
  %39 = load i64, ptr %14, align 8, !tbaa !9
  %40 = load i32, ptr %18, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %39, %41
  br i1 %42, label %43, label %99

43:                                               ; preds = %38
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = call i64 @decode_packed_entry_number(ptr noundef %44, ptr noundef %45)
  store i64 %46, ptr %16, align 8, !tbaa !9
  %47 = load i64, ptr %16, align 8, !tbaa !9
  %48 = icmp eq i64 %47, -1
  br i1 %48, label %49, label %50

49:                                               ; preds = %43
  store i64 -1, ptr %7, align 8
  store i32 1, ptr %19, align 4
  br label %100

50:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.codebook, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i64, ptr %16, align 8, !tbaa !9
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.codebook, ptr %55, i32 0, i32 0
  %57 = load i64, ptr %56, align 8, !tbaa !16
  %58 = mul nsw i64 %54, %57
  %59 = getelementptr inbounds float, ptr %53, i64 %58
  store ptr %59, ptr %20, align 8, !tbaa !5
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %95, %50
  %61 = load i64, ptr %14, align 8, !tbaa !9
  %62 = load i32, ptr %18, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = icmp slt i64 %61, %63
  br i1 %64, label %65, label %71

65:                                               ; preds = %60
  %66 = load i64, ptr %15, align 8, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.codebook, ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = icmp slt i64 %66, %69
  br label %71

71:                                               ; preds = %65, %60
  %72 = phi i1 [ false, %60 ], [ %70, %65 ]
  br i1 %72, label %73, label %98

73:                                               ; preds = %71
  %74 = load ptr, ptr %20, align 8, !tbaa !5
  %75 = load i64, ptr %15, align 8, !tbaa !9
  %76 = getelementptr inbounds float, ptr %74, i64 %75
  %77 = load float, ptr %76, align 4, !tbaa !17
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load i32, ptr %17, align 4, !tbaa !11
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %17, align 4, !tbaa !11
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds ptr, ptr %78, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = load i64, ptr %14, align 8, !tbaa !9
  %85 = getelementptr inbounds float, ptr %83, i64 %84
  %86 = load float, ptr %85, align 4, !tbaa !17
  %87 = fadd float %86, %77
  store float %87, ptr %85, align 4, !tbaa !17
  %88 = load i32, ptr %17, align 4, !tbaa !11
  %89 = load i32, ptr %11, align 4, !tbaa !11
  %90 = icmp eq i32 %88, %89
  br i1 %90, label %91, label %94

91:                                               ; preds = %73
  store i32 0, ptr %17, align 4, !tbaa !11
  %92 = load i64, ptr %14, align 8, !tbaa !9
  %93 = add nsw i64 %92, 1
  store i64 %93, ptr %14, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %91, %73
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %15, align 8, !tbaa !9
  %97 = add nsw i64 %96, 1
  store i64 %97, ptr %15, align 8, !tbaa !9
  br label %60, !llvm.loop !19

98:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %38, !llvm.loop !21

99:                                               ; preds = %38
  store i32 0, ptr %19, align 4
  br label %100

100:                                              ; preds = %99, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %101 = load i32, ptr %19, align 4
  switch i32 %101, label %104 [
    i32 0, label %102
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102, %6
  store i64 0, ptr %7, align 8
  store i32 1, ptr %19, align 4
  br label %104

104:                                              ; preds = %103, %100
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %105 = load i64, ptr %7, align 8
  ret i64 %105
}

; 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"codebook", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88}
!15 = !{!14, !6, i64 32}
!16 = !{!14, !10, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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_decodevv_add(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %10, label %.critedge39

10:                                               ; preds = %6
  %11 = sext i32 %5 to i64
  %12 = add nsw i64 %11, %2
  %13 = sext i32 %3 to i64
  %14 = sdiv i64 %12, %13
  %15 = sdiv i64 %2, %13
  %sext = shl i64 %14, 32
  %16 = ashr exact i64 %sext, 32
  %.not45 = icmp slt i64 %15, %16
  br i1 %.not45, label %.lr.ph48, label %.critedge39

.lr.ph48:                                         ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  br label %18

.critedge.loopexit:                               ; preds = %.lr.ph, %21
  %.132.lcssa = phi i32 [ %.03146, %21 ], [ %spec.select, %.lr.ph ]
  %.130.lcssa = phi i64 [ %.02947, %21 ], [ %spec.select37, %.lr.ph ]
  %.not = icmp slt i64 %.130.lcssa, %16
  br i1 %.not, label %18, label %.critedge39, !llvm.loop !12

18:                                               ; preds = %.lr.ph48, %.critedge.loopexit
  %.02947 = phi i64 [ %15, %.lr.ph48 ], [ %.130.lcssa, %.critedge.loopexit ]
  %.03146 = phi i32 [ 0, %.lr.ph48 ], [ %.132.lcssa, %.critedge.loopexit ]
  %19 = tail call i64 @decode_packed_entry_number(ptr noundef %0, ptr noundef %4)
  %20 = icmp eq i64 %19, -1
  br i1 %20, label %.critedge39, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %17, align 8, !tbaa !14
  %23 = load i64, ptr %0, align 8, !tbaa !15
  %24 = mul nsw i64 %23, %19
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = icmp slt i64 %.02947, %16
  %27 = icmp sgt i64 %23, 0
  %or.cond40 = select i1 %26, i1 %27, i1 false
  br i1 %or.cond40, label %.lr.ph, label %.critedge.loopexit

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.13043 = phi i64 [ %spec.select37, %.lr.ph ], [ %.02947, %21 ]
  %.13242 = phi i32 [ %spec.select, %.lr.ph ], [ %.03146, %21 ]
  %.03441 = phi i64 [ %39, %.lr.ph ], [ 0, %21 ]
  %28 = getelementptr inbounds float, ptr %25, i64 %.03441
  %29 = load float, ptr %28, align 4, !tbaa !16
  %30 = add nsw i32 %.13242, 1
  %31 = sext i32 %.13242 to i64
  %32 = getelementptr inbounds ptr, ptr %1, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = getelementptr inbounds float, ptr %33, i64 %.13043
  %35 = load float, ptr %34, align 4, !tbaa !16
  %36 = fadd float %29, %35
  store float %36, ptr %34, align 4, !tbaa !16
  %37 = icmp eq i32 %30, %3
  %spec.select = select i1 %37, i32 0, i32 %30
  %38 = zext i1 %37 to i64
  %spec.select37 = add nsw i64 %.13043, %38
  %39 = add nuw nsw i64 %.03441, 1
  %40 = icmp slt i64 %spec.select37, %16
  %41 = icmp slt i64 %39, %23
  %or.cond = select i1 %40, i1 %41, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge.loopexit, !llvm.loop !19

.critedge39:                                      ; preds = %18, %.critedge.loopexit, %10, %6
  %.1 = phi i64 [ 0, %6 ], [ 0, %10 ], [ -1, %18 ], [ 0, %.critedge.loopexit ]
  ret i64 %.1
}

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

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

!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = !{!10, !10, i64 0}
!19 = distinct !{!19, !13}


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