; LLVM IR from sp-nitech/SPTK :: src/compression/huffman_decoding.ll (ZN4sptk15HuffmanDecoding3GetEbPiPb)

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

%"class.sptk::HuffmanDecoding" = type { ptr, i8, ptr, ptr }
%"struct.sptk::HuffmanDecoding::Node" = type { ptr, ptr, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4sptk15HuffmanDecoding3GetEbPiPb(ptr noundef nonnull align 8 dereferenceable(32) %0, i1 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8
  %12 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 1
  %13 = load i8, ptr %12, align 8, !tbaa !11, !range !13, !noundef !14
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %25

15:                                               ; preds = %4
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %25, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %25, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %18, %15, %4
  store i1 false, ptr %5, align 1
  br label %77

26:                                               ; preds = %21
  %27 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %34

29:                                               ; preds = %26
  %30 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %"struct.sptk::HuffmanDecoding::Node", ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  br label %39

34:                                               ; preds = %26
  %35 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds %"struct.sptk::HuffmanDecoding::Node", ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  br label %39

39:                                               ; preds = %34, %29
  %40 = phi ptr [ %33, %29 ], [ %38, %34 ]
  %41 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  store ptr %40, ptr %41, align 8, !tbaa !15
  %42 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = icmp eq ptr null, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  store i1 false, ptr %5, align 1
  br label %77

46:                                               ; preds = %39
  %47 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = getelementptr inbounds %"struct.sptk::HuffmanDecoding::Node", ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = icmp eq ptr null, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %46
  %53 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds %"struct.sptk::HuffmanDecoding::Node", ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = icmp eq ptr null, %56
  br label %58

58:                                               ; preds = %52, %46
  %59 = phi i1 [ false, %46 ], [ %57, %52 ]
  %60 = zext i1 %59 to i64
  %61 = select i1 %59, i1 true, i1 false
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = zext i1 %61 to i8
  store i8 %63, ptr %62, align 1, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !9, !range !13, !noundef !14
  %66 = trunc i8 %65 to i1
  br i1 %66, label %67, label %76

67:                                               ; preds = %58
  %68 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = getelementptr inbounds %"struct.sptk::HuffmanDecoding::Node", ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !20
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %71, ptr %72, align 4, !tbaa !21
  %73 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !22
  %75 = getelementptr inbounds %"class.sptk::HuffmanDecoding", ptr %11, i32 0, i32 3
  store ptr %74, ptr %75, align 8, !tbaa !15
  br label %76

76:                                               ; preds = %67, %58
  store i1 true, ptr %5, align 1
  br label %77

77:                                               ; preds = %76, %45, %25
  %78 = load i1, ptr %5, align 1
  ret i1 %78
}

attributes #0 = { mustprogress 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN4sptk15HuffmanDecodingE", !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !6, i64 8}
!17 = !{!"_ZTSN4sptk15HuffmanDecoding4NodeE", !6, i64 0, !6, i64 8, !18, i64 16}
!18 = !{!"int", !7, i64 0}
!19 = !{!17, !6, i64 0}
!20 = !{!17, !18, i64 16}
!21 = !{!18, !18, i64 0}
!22 = !{!12, !6, i64 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_ZN4sptk15HuffmanDecoding3GetEbPiPb(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i1 noundef zeroext %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  %.not = xor i1 %7, true
  %8 = icmp eq ptr %2, null
  %or.cond = or i1 %8, %.not
  %9 = icmp eq ptr %3, null
  %or.cond3 = or i1 %9, %or.cond
  br i1 %or.cond3, label %30, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = icmp eq ptr %12, null
  br i1 %13, label %30, label %14

14:                                               ; preds = %10
  %.in.idx = select i1 %1, i64 8, i64 0
  %.in = getelementptr inbounds i8, ptr %12, i64 %.in.idx
  %15 = load ptr, ptr %.in, align 8, !tbaa !14
  store ptr %15, ptr %11, align 8, !tbaa !13
  %16 = icmp eq ptr %15, null
  br i1 %16, label %30, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %15, align 8, !tbaa !15
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %.critedge

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %15, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = icmp eq ptr %22, null
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %3, align 1, !tbaa !19
  br i1 %23, label %25, label %30

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %15, i64 16
  %27 = load i32, ptr %26, align 8, !tbaa !20
  store i32 %27, ptr %2, align 4, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  store ptr %29, ptr %11, align 8, !tbaa !13
  br label %30

.critedge:                                        ; preds = %17
  store i8 0, ptr %3, align 1, !tbaa !19
  br label %30

30:                                               ; preds = %20, %25, %.critedge, %14, %4, %10
  %.0 = phi i1 [ false, %10 ], [ false, %4 ], [ false, %14 ], [ true, %.critedge ], [ true, %25 ], [ true, %20 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 8}
!6 = !{!"_ZTSN4sptk15HuffmanDecodingE", !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!6, !10, i64 24}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN4sptk15HuffmanDecoding4NodeE", !10, i64 0, !10, i64 8, !17, i64 16}
!17 = !{!"int", !8, i64 0}
!18 = !{!16, !10, i64 8}
!19 = !{!7, !7, i64 0}
!20 = !{!16, !17, i64 16}
!21 = !{!17, !17, i64 0}
!22 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass