; LLVM IR from Nigh/Basic-Compression-Library :: src (huffman)

; 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_decodenode_struct = type { ptr, ptr, i32 }
%struct.huff_bitstream_t = type { ptr, i32 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden void @_Huffman_InitBitstream(ptr noundef, ptr noundef) #1

; 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 void @Huffman_Uncompress(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [511 x %struct.huff_decodenode_struct], align 16
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.huff_bitstream_t, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  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 i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 12264, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ult i32 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i32 1, ptr %16, align 4
  br label %59

20:                                               ; preds = %4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_Huffman_InitBitstream(ptr noundef %12, ptr noundef %21)
  store i32 0, ptr %14, align 4, !tbaa !9
  %22 = getelementptr inbounds [511 x %struct.huff_decodenode_struct], ptr %9, i64 0, i64 0
  %23 = call ptr @_Huffman_RecoverTree(ptr noundef %22, ptr noundef %12, ptr noundef %14)
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %24, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %55, %20
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp ult i32 %26, %27
  br i1 %28, label %29, label %58

29:                                               ; preds = %25
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %30, ptr %11, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %47, %29
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.huff_decodenode_struct, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %48

36:                                               ; preds = %31
  %37 = call i32 @_Huffman_ReadBit(ptr noundef %12)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %36
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.huff_decodenode_struct, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  store ptr %42, ptr %11, align 8, !tbaa !5
  br label %47

43:                                               ; preds = %36
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.huff_decodenode_struct, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43, %39
  br label %31, !llvm.loop !15

48:                                               ; preds = %31
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.huff_decodenode_struct, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %15, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %15, align 8, !tbaa !5
  store i8 %52, ptr %53, align 1, !tbaa !17
  br label %55

55:                                               ; preds = %48
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %13, align 4, !tbaa !9
  br label %25, !llvm.loop !18

58:                                               ; preds = %25
  store i32 0, ptr %16, align 4
  br label %59

59:                                               ; preds = %58, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 12264, ptr %9) #2
  %60 = load i32, ptr %16, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden ptr @_Huffman_RecoverTree(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @_Huffman_ReadBit(ptr noundef) #1

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


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

%struct.huff_decodenode_struct = type { ptr, ptr, i32 }
%struct.huff_bitstream_t = type { ptr, i32 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden void @_Huffman_InitBitstream(ptr noundef, ptr noundef) local_unnamed_addr #1

; 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
define dso_local void @Huffman_Uncompress(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [511 x %struct.huff_decodenode_struct], align 16
  %6 = alloca %struct.huff_bitstream_t, align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 12264, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #2
  %8 = icmp eq i32 %2, 0
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %4
  call void @_Huffman_InitBitstream(ptr noundef nonnull %6, ptr noundef %0)
  store i32 0, ptr %7, align 4, !tbaa !5
  %10 = call ptr @_Huffman_RecoverTree(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not17 = icmp eq i32 %3, 0
  br i1 %.not17, label %.loopexit, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %9
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.016 = phi ptr [ %1, %.preheader.lr.ph ], [ %19, %._crit_edge ]
  %.01115 = phi i32 [ 0, %.preheader.lr.ph ], [ %20, %._crit_edge ]
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01214 = phi ptr [ %.1, %.lr.ph ], [ %10, %.preheader ]
  %14 = call i32 @_Huffman_ReadBit(ptr noundef nonnull %6)
  %.not = icmp eq i32 %14, 0
  %.1.in.idx = select i1 %.not, i64 0, i64 8
  %.1.in = getelementptr inbounds i8, ptr %.01214, i64 %.1.in.idx
  %.1 = load ptr, ptr %.1.in, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %.1, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %12, %.preheader ], [ %16, %.lr.ph ]
  %18 = trunc i32 %.lcssa to i8
  %19 = getelementptr inbounds i8, ptr %.016, i64 1
  store i8 %18, ptr %.016, align 1, !tbaa !15
  %20 = add nuw i32 %.01115, 1
  %exitcond.not = icmp eq i32 %20, %3
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %._crit_edge, %9, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 12264, ptr nonnull %5) #2
  ret void
}

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

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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"huff_decodenode_struct", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


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