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

@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

; 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @huff_set_links_dfs_recursion(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.huff_t, ptr %12, i32 0, i32 6
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = shl i32 1, %15
  store i32 %16, ptr %10, align 4, !tbaa !9
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.huff_t, ptr %19, i32 0, i32 8
  store i32 %18, ptr %20, align 4, !tbaa !15
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = add nsw i32 %23, %21
  store i32 %24, ptr %22, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %51, %4
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br label %32

32:                                               ; preds = %28, %25
  %33 = phi i1 [ false, %25 ], [ %31, %28 ]
  br i1 %33, label %34, label %54

34:                                               ; preds = %32
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.huff_t, ptr %37, i32 0, i32 6
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = call ptr @huff_decode(ptr noundef %35, i32 noundef %36, i32 noundef %40)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.huff_t, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = icmp eq i32 %47, %48
  %50 = zext i1 %49 to i32
  call void @huff_print_one(ptr noundef %41, ptr noundef %42, i32 noundef %45, i32 noundef %50)
  br label %51

51:                                               ; preds = %34
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %9, align 4, !tbaa !9
  br label %25, !llvm.loop !17

54:                                               ; preds = %32
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %82, %54
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %59, label %85

59:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.huff_t, ptr %62, i32 0, i32 6
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = call ptr @huff_decode(ptr noundef %60, i32 noundef %61, i32 noundef %65)
  store ptr %66, ptr %11, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = call i32 @is_leaf(ptr noundef %67)
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %81, label %70

70:                                               ; preds = %59
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %76

73:                                               ; preds = %70
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.11) #3
  br label %76

76:                                               ; preds = %73, %70
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  call void @huff_set_links_dfs_recursion(ptr noundef %77, ptr noundef %78, i32 noundef %79, ptr noundef %80)
  br label %81

81:                                               ; preds = %76, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %82

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

85:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  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 "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, !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 60}
!16 = !{!12, !10, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !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"

@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @huff_set_links_dfs_recursion(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = shl nuw i32 1, %6
  %8 = load i32, ptr %3, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %8, ptr %9, align 4, !tbaa !14
  %10 = add nsw i32 %8, %7
  store i32 %10, ptr %3, align 4, !tbaa !13
  %11 = icmp ne i32 %2, 0
  %12 = icmp ne i32 %6, 31
  %13 = select i1 %11, i1 %12, i1 false
  br i1 %13, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %smax = tail call i32 @llvm.smax.i32(i32 %7, i32 1)
  br label %21

.preheader:                                       ; preds = %4
  %.not35 = icmp eq i32 %6, 31
  br i1 %.not35, label %._crit_edge, label %.lr.ph34

.preheader.thread:                                ; preds = %21
  %.not3542 = icmp eq i32 %6, 31
  br i1 %.not3542, label %._crit_edge, label %.lr.ph34.split.us.preheader

.lr.ph34:                                         ; preds = %.preheader
  br i1 %11, label %.lr.ph34.split.us.preheader, label %.lr.ph34.split.preheader

.lr.ph34.split.preheader:                         ; preds = %.lr.ph34
  %smax37 = tail call i32 @llvm.smax.i32(i32 %7, i32 1)
  br label %.lr.ph34.split

.lr.ph34.split.us.preheader:                      ; preds = %.preheader.thread, %.lr.ph34
  %smax39 = tail call i32 @llvm.smax.i32(i32 %7, i32 1)
  br label %.lr.ph34.split.us

.lr.ph34.split.us:                                ; preds = %.lr.ph34.split.us.preheader, %19
  %.133.us = phi i32 [ %20, %19 ], [ 0, %.lr.ph34.split.us.preheader ]
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = tail call ptr @huff_decode(ptr noundef nonnull %0, i32 noundef %.133.us, i32 noundef %15)
  %17 = tail call i32 @is_leaf(ptr noundef %16)
  %.not.us = icmp eq i32 %17, 0
  br i1 %.not.us, label %.split29.us, label %19

.split29.us:                                      ; preds = %.lr.ph34.split.us
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.11) #3
  tail call void @huff_set_links_dfs_recursion(ptr noundef %16, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %3)
  br label %19

19:                                               ; preds = %.split29.us, %.lr.ph34.split.us
  %20 = add nuw nsw i32 %.133.us, 1
  %exitcond40.not = icmp eq i32 %20, %smax39
  br i1 %exitcond40.not, label %._crit_edge, label %.lr.ph34.split.us, !llvm.loop !15

21:                                               ; preds = %.lr.ph, %21
  %.032 = phi i32 [ 0, %.lr.ph ], [ %25, %21 ]
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = tail call ptr @huff_decode(ptr noundef nonnull %0, i32 noundef %.032, i32 noundef %22)
  %24 = load i32, ptr %14, align 8, !tbaa !17
  %25 = add nuw nsw i32 %.032, 1
  %26 = icmp eq i32 %25, %7
  %27 = zext i1 %26 to i32
  tail call void @huff_print_one(ptr noundef %23, ptr noundef %1, i32 noundef %24, i32 noundef %27)
  %exitcond.not = icmp eq i32 %25, %smax
  br i1 %exitcond.not, label %.preheader.thread, label %21, !llvm.loop !18

.lr.ph34.split:                                   ; preds = %.lr.ph34.split.preheader, %31
  %.133 = phi i32 [ %32, %31 ], [ 0, %.lr.ph34.split.preheader ]
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = tail call ptr @huff_decode(ptr noundef nonnull %0, i32 noundef %.133, i32 noundef %28)
  %30 = tail call i32 @is_leaf(ptr noundef %29)
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %.split, label %31

.split:                                           ; preds = %.lr.ph34.split
  tail call void @huff_set_links_dfs_recursion(ptr noundef %29, ptr noundef %1, i32 noundef 0, ptr noundef nonnull %3)
  br label %31

31:                                               ; preds = %.split, %.lr.ph34.split
  %32 = add nuw nsw i32 %.133, 1
  %exitcond38.not = icmp eq i32 %32, %smax37
  br i1 %exitcond38.not, label %._crit_edge, label %.lr.ph34.split, !llvm.loop !15

._crit_edge:                                      ; preds = %31, %19, %.preheader.thread, %.preheader
  ret void
}

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


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