; LLVM IR from AnzoDK/RPAudio :: includes/minimp3/huffopt (huffopt)

; 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.huff_t = type { ptr, ptr, [2 x ptr], i32, i32, i32, %struct.anon, i32, i32, i32 }
%struct.anon = type { i32, i32, float }

; 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
declare hidden i32 @is_leaf(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @huff_depth(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @huff_size(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local float @huff_cost(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @huff_optimize_partition(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %145

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @is_leaf(ptr noundef %14)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %145, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.huff_t, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds [2 x ptr], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  call void @huff_optimize_partition(ptr noundef %21)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.huff_t, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds [2 x ptr], ptr %23, i64 0, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  call void @huff_optimize_partition(ptr noundef %25)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = call i32 @huff_depth(ptr noundef %26)
  store i32 %27, ptr %4, align 4, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.huff_t, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp ne i32 %30, 0
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, i32 1, i32 5
  store i32 %33, ptr %5, align 4, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp sgt i32 %34, 1
  br i1 %35, label %36, label %38

36:                                               ; preds = %17
  %37 = load i32, ptr %5, align 4, !tbaa !9
  br label %46

38:                                               ; preds = %17
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 7
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !9
  br label %44

43:                                               ; preds = %38
  br label %44

44:                                               ; preds = %43, %41
  %45 = phi i32 [ %42, %41 ], [ 7, %43 ]
  br label %46

46:                                               ; preds = %44, %36
  %47 = phi i32 [ %37, %36 ], [ %45, %44 ]
  store i32 %47, ptr %6, align 4, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.huff_t, ptr %48, i32 0, i32 9
  %50 = load i32, ptr %49, align 8, !tbaa !15
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %58

52:                                               ; preds = %46
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.huff_t, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %58, label %57

57:                                               ; preds = %52
  store i32 4, ptr %5, align 4, !tbaa !9
  store i32 4, ptr %6, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %57, %52, %46
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.huff_t, ptr %61, i32 0, i32 6
  %63 = getelementptr inbounds %struct.anon, ptr %62, i32 0, i32 0
  store i32 %60, ptr %63, align 4, !tbaa !16
  %64 = call i32 @huff_size(ptr noundef %59, i32 noundef %60)
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = shl i32 1, %65
  %67 = add nsw i32 %64, %66
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.huff_t, ptr %68, i32 0, i32 6
  %70 = getelementptr inbounds %struct.anon, ptr %69, i32 0, i32 1
  store i32 %67, ptr %70, align 4, !tbaa !17
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.huff_t, ptr %73, i32 0, i32 6
  %75 = getelementptr inbounds %struct.anon, ptr %74, i32 0, i32 0
  store i32 %72, ptr %75, align 4, !tbaa !16
  %76 = call float @huff_cost(ptr noundef %71, i32 noundef %72)
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.huff_t, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 8, !tbaa !11
  %80 = shl i32 1, %79
  %81 = sitofp i32 %80 to float
  %82 = fdiv float 1.000000e+00, %81
  %83 = fadd float %76, %82
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.huff_t, ptr %84, i32 0, i32 6
  %86 = getelementptr inbounds %struct.anon, ptr %85, i32 0, i32 2
  store float %83, ptr %86, align 4, !tbaa !18
  %87 = load i32, ptr %5, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %3, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %141, %58
  %90 = load i32, ptr %3, align 4, !tbaa !9
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = icmp sle i32 %90, %91
  br i1 %92, label %93, label %144

93:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = load i32, ptr %3, align 4, !tbaa !9
  %96 = call i32 @huff_size(ptr noundef %94, i32 noundef %95)
  %97 = load i32, ptr %3, align 4, !tbaa !9
  %98 = shl i32 1, %97
  %99 = add nsw i32 %96, %98
  store i32 %99, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = load i32, ptr %3, align 4, !tbaa !9
  %102 = call float @huff_cost(ptr noundef %100, i32 noundef %101)
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.huff_t, ptr %103, i32 0, i32 3
  %105 = load i32, ptr %104, align 8, !tbaa !11
  %106 = shl i32 1, %105
  %107 = sitofp i32 %106 to float
  %108 = fdiv float 1.000000e+00, %107
  %109 = fadd float %102, %108
  store float %109, ptr %8, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %110 = load float, ptr %8, align 4, !tbaa !19
  %111 = load i32, ptr %7, align 4, !tbaa !9
  %112 = sitofp i32 %111 to float
  %113 = call float @llvm.fmuladd.f32(float %110, float 5.120000e+02, float %112)
  store float %113, ptr %9, align 4, !tbaa !19
  %114 = load ptr, ptr %2, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.huff_t, ptr %114, i32 0, i32 6
  %116 = getelementptr inbounds %struct.anon, ptr %115, i32 0, i32 2
  %117 = load float, ptr %116, align 4, !tbaa !18
  %118 = load ptr, ptr %2, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.huff_t, ptr %118, i32 0, i32 6
  %120 = getelementptr inbounds %struct.anon, ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 4, !tbaa !17
  %122 = sitofp i32 %121 to float
  %123 = call float @llvm.fmuladd.f32(float %117, float 5.120000e+02, float %122)
  store float %123, ptr %10, align 4, !tbaa !19
  %124 = load float, ptr %9, align 4, !tbaa !19
  %125 = load float, ptr %10, align 4, !tbaa !19
  %126 = fcmp olt float %124, %125
  br i1 %126, label %127, label %140

127:                                              ; preds = %93
  %128 = load i32, ptr %3, align 4, !tbaa !9
  %129 = load ptr, ptr %2, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.huff_t, ptr %129, i32 0, i32 6
  %131 = getelementptr inbounds %struct.anon, ptr %130, i32 0, i32 0
  store i32 %128, ptr %131, align 4, !tbaa !16
  %132 = load i32, ptr %7, align 4, !tbaa !9
  %133 = load ptr, ptr %2, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.huff_t, ptr %133, i32 0, i32 6
  %135 = getelementptr inbounds %struct.anon, ptr %134, i32 0, i32 1
  store i32 %132, ptr %135, align 4, !tbaa !17
  %136 = load float, ptr %8, align 4, !tbaa !19
  %137 = load ptr, ptr %2, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.huff_t, ptr %137, i32 0, i32 6
  %139 = getelementptr inbounds %struct.anon, ptr %138, i32 0, i32 2
  store float %136, ptr %139, align 4, !tbaa !18
  br label %140

140:                                              ; preds = %127, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %141

141:                                              ; preds = %140
  %142 = load i32, ptr %3, align 4, !tbaa !9
  %143 = add nsw i32 %142, 1
  store i32 %143, ptr %3, align 4, !tbaa !9
  br label %89, !llvm.loop !20

144:                                              ; preds = %89
  br label %145

145:                                              ; preds = %144, %13, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 32}
!12 = !{!"huff_t", !6, i64 0, !6, i64 8, !7, i64 16, !10, i64 32, !10, i64 36, !10, i64 40, !13, i64 44, !10, i64 56, !10, i64 60, !10, i64 64}
!13 = !{!"", !10, i64 0, !10, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !10, i64 64}
!16 = !{!12, !10, i64 44}
!17 = !{!12, !10, i64 48}
!18 = !{!12, !14, i64 52}
!19 = !{!14, !14, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @huff_depth(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @huff_size(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @huff_cost(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @huff_optimize_partition(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %2

2:                                                ; preds = %1
  %3 = tail call i32 @is_leaf(ptr noundef nonnull %0)
  %.not47 = icmp eq i32 %3, 0
  br i1 %.not47, label %4, label %.loopexit

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  tail call void @huff_optimize_partition(ptr noundef %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  tail call void @huff_optimize_partition(ptr noundef %8)
  %9 = tail call i32 @huff_depth(ptr noundef nonnull %0)
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %.not48 = icmp eq i32 %11, 0
  %12 = select i1 %.not48, i32 5, i32 1
  %13 = tail call i32 @llvm.smin.i32(i32 %9, i32 7)
  %14 = select i1 %.not48, i32 5, i32 %13
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, 1
  %spec.select = select i1 %.not48, i32 4, i32 %13
  %spec.select51 = select i1 %.not48, i32 4, i32 1
  %.044 = select i1 %17, i32 %spec.select, i32 %14
  %.043 = select i1 %17, i32 %spec.select51, i32 %12
  %18 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %.043, ptr %18, align 4, !tbaa !15
  %19 = tail call i32 @huff_size(ptr noundef nonnull %0, i32 noundef %.043)
  %20 = shl nuw nsw i32 1, %.043
  %21 = add nsw i32 %20, %19
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %21, ptr %22, align 4, !tbaa !16
  store i32 %.043, ptr %18, align 4, !tbaa !15
  %23 = tail call float @huff_cost(ptr noundef nonnull %0, i32 noundef %.043)
  %24 = load i32, ptr %10, align 8, !tbaa !9
  %25 = shl nuw i32 1, %24
  %26 = sitofp i32 %25 to float
  %27 = fdiv float 1.000000e+00, %26
  %28 = fadd float %23, %27
  %29 = getelementptr inbounds i8, ptr %0, i64 52
  store float %28, ptr %29, align 4, !tbaa !17
  %.not50.not53 = icmp slt i32 %.043, %.044
  br i1 %.not50.not53, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4, %51
  %.0.in54 = phi i32 [ %.055, %51 ], [ %.043, %4 ]
  %.055 = add nuw nsw i32 %.0.in54, 1
  %30 = tail call i32 @huff_size(ptr noundef nonnull %0, i32 noundef %.055)
  %31 = shl nuw i32 2, %.0.in54
  %32 = add nsw i32 %30, %31
  %33 = tail call float @huff_cost(ptr noundef nonnull %0, i32 noundef %.055)
  %34 = load i32, ptr %10, align 8, !tbaa !9
  %35 = shl nuw i32 1, %34
  %36 = sitofp i32 %35 to float
  %37 = fdiv float 1.000000e+00, %36
  %38 = fadd float %33, %37
  %39 = load float, ptr %29, align 4, !tbaa !17
  %40 = load i32, ptr %22, align 4, !tbaa !16
  %41 = insertelement <2 x i32> poison, i32 %32, i64 0
  %42 = insertelement <2 x i32> %41, i32 %40, i64 1
  %43 = sitofp <2 x i32> %42 to <2 x float>
  %44 = insertelement <2 x float> poison, float %38, i64 0
  %45 = insertelement <2 x float> %44, float %39, i64 1
  %46 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %45, <2 x float> <float 5.120000e+02, float 5.120000e+02>, <2 x float> %43)
  %47 = extractelement <2 x float> %46, i64 0
  %48 = extractelement <2 x float> %46, i64 1
  %49 = fcmp olt float %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %.lr.ph
  store i32 %.055, ptr %18, align 4, !tbaa !15
  store i32 %32, ptr %22, align 4, !tbaa !16
  store float %38, ptr %29, align 4, !tbaa !17
  br label %51

51:                                               ; preds = %50, %.lr.ph
  %exitcond.not = icmp eq i32 %.055, %.044
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

.loopexit:                                        ; preds = %51, %4, %2, %1
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.fmuladd.v2f32(<2 x float>, <2 x float>, <2 x float>) #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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 32}
!10 = !{!"huff_t", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 32, !11, i64 36, !11, i64 40, !12, i64 44, !11, i64 56, !11, i64 60, !11, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !13, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!10, !11, i64 64}
!15 = !{!10, !11, i64 44}
!16 = !{!10, !11, i64 48}
!17 = !{!10, !13, i64 52}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass