; 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 ptr @huff_decode(ptr noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @huff_set_links_bfs(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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 ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %82, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp sle i32 %14, 1
  br i1 %15, label %16, label %85

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %17, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr %7, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %80, %16
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %81

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.huff_t, ptr %22, i32 0, i32 6
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = shl i32 1, %25
  store i32 %26, ptr %11, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %60, %21
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %63

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.huff_t, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds %struct.anon, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = call ptr @huff_decode(ptr noundef %32, i32 noundef %33, i32 noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %31
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.huff_t, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 8, !tbaa !15
  call void @huff_print_one(ptr noundef %42, ptr noundef %43, i32 noundef %46, i32 noundef 0)
  br label %47

47:                                               ; preds = %41, %31
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = call i32 @is_leaf(ptr noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %59, label %51

51:                                               ; preds = %47
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.huff_t, ptr %53, i32 0, i32 7
  store i32 %52, ptr %54, align 8, !tbaa !16
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.huff_t, ptr %57, i32 0, i32 0
  store ptr %58, ptr %8, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %51, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %10, align 4, !tbaa !9
  br label %27, !llvm.loop !17

63:                                               ; preds = %27
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, %64
  store i32 %66, ptr %9, align 4, !tbaa !9
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %67, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %80

70:                                               ; preds = %63
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.huff_t, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  store ptr %73, ptr %7, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  store ptr %7, ptr %8, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %75, %70
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.huff_t, ptr %78, i32 0, i32 8
  store i32 %77, ptr %79, align 4, !tbaa !20
  br label %80

80:                                               ; preds = %76, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %18, !llvm.loop !21

81:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %5, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !22

85:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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 44}
!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 32}
!16 = !{!12, !10, i64 56}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !6, i64 0}
!20 = !{!12, !10, i64 60}
!21 = distinct !{!21, !18}
!22 = distinct !{!22, !18}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @huff_set_links_bfs(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  %.not37 = icmp eq ptr %0, null
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3)
  br i1 %.not37, label %.split.us.preheader, label %.lr.ph43.split.us.preheader

.split.us.preheader:                              ; preds = %2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3)
  br label %.split47.us

.lr.ph43.split.us.preheader:                      ; preds = %2
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %.lr.ph43.split.us

.lr.ph43.split.us:                                ; preds = %7, %.lr.ph43.split.us.preheader
  %.0..0..0..us55 = phi ptr [ %9, %7 ], [ null, %.lr.ph43.split.us.preheader ]
  %.02641.us = phi ptr [ %.0..0..0..us, %7 ], [ %0, %.lr.ph43.split.us.preheader ]
  %.02839.us = phi i32 [ %8, %7 ], [ 0, %.lr.ph43.split.us.preheader ]
  %.02938.us = phi ptr [ %spec.select.us, %7 ], [ %3, %.lr.ph43.split.us.preheader ]
  %4 = getelementptr inbounds i8, ptr %.02641.us, i64 44
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = shl nuw i32 1, %5
  %.not49 = icmp eq i32 %5, 31
  br i1 %.not49, label %._crit_edge.split.us.us, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph43.split.us
  %smax52 = tail call i32 @llvm.smax.i32(i32 %6, i32 1)
  br label %.lr.ph.us

._crit_edge.split.us.us.loopexit:                 ; preds = %16
  %.0..0..0..0..us.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %._crit_edge.split.us.us

._crit_edge.split.us.us:                          ; preds = %._crit_edge.split.us.us.loopexit, %.lr.ph43.split.us
  %.0..0..0..us = phi ptr [ %.0..0..0..us55, %.lr.ph43.split.us ], [ %.0..0..0..0..us.pre, %._crit_edge.split.us.us.loopexit ]
  %.1.lcssa.us = phi ptr [ %.02938.us, %.lr.ph43.split.us ], [ %.2.us.us, %._crit_edge.split.us.us.loopexit ]
  %.not31.us = icmp eq ptr %.0..0..0..us, null
  br i1 %.not31.us, label %.lr.ph43.split.preheader.1, label %7

7:                                                ; preds = %._crit_edge.split.us.us
  %8 = add nsw i32 %6, %.02839.us
  %9 = load ptr, ptr %.0..0..0..us, align 8, !tbaa !14
  store ptr %9, ptr %3, align 8, !tbaa !5
  %.not32.us = icmp eq ptr %9, null
  %spec.select.us = select i1 %.not32.us, ptr %.1.lcssa.us, ptr %3
  %10 = getelementptr inbounds i8, ptr %.0..0..0..us, i64 60
  store i32 %8, ptr %10, align 4, !tbaa !15
  br label %.lr.ph43.split.us, !llvm.loop !16

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %16
  %.02736.us.us = phi i32 [ %17, %16 ], [ 0, %.lr.ph.us.preheader ]
  %.135.us.us = phi ptr [ %.2.us.us, %16 ], [ %.02938.us, %.lr.ph.us.preheader ]
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = tail call ptr @huff_decode(ptr noundef nonnull %.02641.us, i32 noundef %.02736.us.us, i32 noundef %11)
  %13 = tail call i32 @is_leaf(ptr noundef %12)
  %.not34.us.us = icmp eq i32 %13, 0
  br i1 %.not34.us.us, label %14, label %16

14:                                               ; preds = %.lr.ph.us
  %15 = getelementptr inbounds i8, ptr %12, i64 56
  store i32 %.02839.us, ptr %15, align 8, !tbaa !18
  store ptr %12, ptr %.135.us.us, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %14, %.lr.ph.us
  %.2.us.us = phi ptr [ %.135.us.us, %.lr.ph.us ], [ %12, %14 ]
  %17 = add nuw nsw i32 %.02736.us.us, 1
  %exitcond53.not = icmp eq i32 %17, %smax52
  br i1 %exitcond53.not, label %._crit_edge.split.us.us.loopexit, label %.lr.ph.us, !llvm.loop !19

.lr.ph43.split.preheader.1:                       ; preds = %._crit_edge.split.us.us
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3)
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %.lr.ph43.split.1

.lr.ph43.split.1:                                 ; preds = %31, %.lr.ph43.split.preheader.1
  %.0..0..0..158 = phi ptr [ %33, %31 ], [ null, %.lr.ph43.split.preheader.1 ]
  %.02641.1 = phi ptr [ %.0..0..0..1, %31 ], [ %0, %.lr.ph43.split.preheader.1 ]
  %.02839.1 = phi i32 [ %32, %31 ], [ 0, %.lr.ph43.split.preheader.1 ]
  %.02938.1 = phi ptr [ %spec.select.1, %31 ], [ %3, %.lr.ph43.split.preheader.1 ]
  %18 = getelementptr inbounds i8, ptr %.02641.1, i64 44
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = shl nuw i32 1, %19
  %.not48.1 = icmp eq i32 %19, 31
  br i1 %.not48.1, label %._crit_edge.split.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph43.split.1
  %21 = getelementptr inbounds i8, ptr %.02641.1, i64 32
  %smax.1 = tail call i32 @llvm.smax.i32(i32 %20, i32 1)
  br label %22

22:                                               ; preds = %29, %.lr.ph.1
  %.02736.1 = phi i32 [ 0, %.lr.ph.1 ], [ %30, %29 ]
  %.135.1 = phi ptr [ %.02938.1, %.lr.ph.1 ], [ %.2.1, %29 ]
  %23 = load i32, ptr %18, align 4, !tbaa !9
  %24 = tail call ptr @huff_decode(ptr noundef nonnull %.02641.1, i32 noundef %.02736.1, i32 noundef %23)
  %25 = load i32, ptr %21, align 8, !tbaa !20
  tail call void @huff_print_one(ptr noundef %24, ptr noundef %1, i32 noundef %25, i32 noundef 0)
  %26 = tail call i32 @is_leaf(ptr noundef %24)
  %.not34.1 = icmp eq i32 %26, 0
  br i1 %.not34.1, label %27, label %29

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %24, i64 56
  store i32 %.02839.1, ptr %28, align 8, !tbaa !18
  store ptr %24, ptr %.135.1, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %27, %22
  %.2.1 = phi ptr [ %.135.1, %22 ], [ %24, %27 ]
  %30 = add nuw nsw i32 %.02736.1, 1
  %exitcond.1.not = icmp eq i32 %30, %smax.1
  br i1 %exitcond.1.not, label %._crit_edge.split.loopexit.1, label %22, !llvm.loop !19

._crit_edge.split.loopexit.1:                     ; preds = %29
  %.0..0..0..0..1.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %._crit_edge.split.1

._crit_edge.split.1:                              ; preds = %._crit_edge.split.loopexit.1, %.lr.ph43.split.1
  %.0..0..0..1 = phi ptr [ %.0..0..0..158, %.lr.ph43.split.1 ], [ %.0..0..0..0..1.pre, %._crit_edge.split.loopexit.1 ]
  %.1.lcssa.1 = phi ptr [ %.02938.1, %.lr.ph43.split.1 ], [ %.2.1, %._crit_edge.split.loopexit.1 ]
  %.not31.1 = icmp eq ptr %.0..0..0..1, null
  br i1 %.not31.1, label %._crit_edge44.1, label %31

31:                                               ; preds = %._crit_edge.split.1
  %32 = add nsw i32 %20, %.02839.1
  %33 = load ptr, ptr %.0..0..0..1, align 8, !tbaa !14
  store ptr %33, ptr %3, align 8, !tbaa !5
  %.not32.1 = icmp eq ptr %33, null
  %spec.select.1 = select i1 %.not32.1, ptr %.1.lcssa.1, ptr %3
  %34 = getelementptr inbounds i8, ptr %.0..0..0..1, i64 60
  store i32 %32, ptr %34, align 4, !tbaa !15
  br label %.lr.ph43.split.1, !llvm.loop !16

._crit_edge44.1:                                  ; preds = %._crit_edge.split.1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3)
  br label %.split47.us

.split47.us:                                      ; preds = %._crit_edge44.1, %.split.us.preheader
  ret void
}

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

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

!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 44}
!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, !6, i64 0}
!15 = !{!10, !11, i64 60}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 56}
!19 = distinct !{!19, !17}
!20 = !{!10, !11, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass