; LLVM IR from gzc/CLRS :: C16-Greedy-Algorithms/huffman/HUFFMAN.ll (ZN7HUFFMAN8readTrieEv)

; 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.HUFFMAN = type { ptr, %"class.std::map", ptr, ptr }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<char, std::pair<const char, std::vector<bool>>, std::_Select1st<std::pair<const char, std::vector<bool>>>, std::less<char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<char, std::pair<const char, std::vector<bool>>, std::_Select1st<std::pair<const char, std::vector<bool>>>, std::less<char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21), ptr noundef, ptr noundef, i32 noundef, i8 noundef signext) unnamed_addr #2 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #4 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #6
  %9 = getelementptr inbounds %class.HUFFMAN, ptr %8, i32 0, i32 3
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call noundef zeroext i1 @_ZN11BinaryStdIn8readBoolEv(ptr noundef nonnull align 8 dereferenceable(528) %10)
  %12 = zext i1 %11 to i8
  store i8 %12, ptr %4, align 1, !tbaa !20
  %13 = load i8, ptr %4, align 1, !tbaa !20, !range !22, !noundef !23
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %26

15:                                               ; preds = %1
  %16 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #7
  %17 = getelementptr inbounds %class.HUFFMAN, ptr %8, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = invoke noundef signext i8 @_ZN11BinaryStdIn8readCharEv(ptr noundef nonnull align 8 dereferenceable(528) %18)
          to label %20 unwind label %22

20:                                               ; preds = %15
  invoke void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21) %16, ptr noundef null, ptr noundef null, i32 noundef -1, i8 noundef signext %19)
          to label %21 unwind label %22

21:                                               ; preds = %20
  store ptr %16, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %37

22:                                               ; preds = %20, %15
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %5, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %16, i64 noundef 24) #8
  br label %39

26:                                               ; preds = %1
  %27 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #7
  %28 = invoke noundef ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %8)
          to label %29 unwind label %33

29:                                               ; preds = %26
  %30 = invoke noundef ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %8)
          to label %31 unwind label %33

31:                                               ; preds = %29
  invoke void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21) %27, ptr noundef %28, ptr noundef %30, i32 noundef -1, i8 noundef signext 0)
          to label %32 unwind label %33

32:                                               ; preds = %31
  store ptr %27, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %37

33:                                               ; preds = %31, %29, %26
  %34 = landingpad { ptr, i32 }
          cleanup
  %35 = extractvalue { ptr, i32 } %34, 0
  store ptr %35, ptr %5, align 8
  %36 = extractvalue { ptr, i32 } %34, 1
  store i32 %36, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 24) #8
  br label %39

37:                                               ; preds = %32, %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #6
  %38 = load ptr, ptr %2, align 8
  ret ptr %38

39:                                               ; preds = %33, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #6
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %5, align 8
  %42 = load i32, ptr %6, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44
}

declare noundef zeroext i1 @_ZN11BinaryStdIn8readBoolEv(ptr noundef nonnull align 8 dereferenceable(528)) #5

declare noundef signext i8 @_ZN11BinaryStdIn8readCharEv(ptr noundef nonnull align 8 dereferenceable(528)) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { 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" }
attributes #3 = { nobuiltin 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 #4 = { mustprogress 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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++ TBAA"}
!9 = !{!10, !6, i64 64}
!10 = !{!"_ZTS7HUFFMAN", !6, i64 0, !11, i64 8, !6, i64 56, !6, i64 64}
!11 = !{!"_ZTSSt3mapIcSt6vectorIbSaIbEESt4lessIcESaISt4pairIKcS2_EEE", !12, i64 0}
!12 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcSt6vectorIbSaIbEEESt10_Select1stIS5_ESt4lessIcESaIS5_EE", !13, i64 0}
!13 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcSt6vectorIbSaIbEEESt10_Select1stIS5_ESt4lessIcESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !14, i64 0, !16, i64 8}
!14 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !15, i64 0}
!15 = !{!"_ZTSSt4lessIcE"}
!16 = !{!"_ZTSSt15_Rb_tree_header", !17, i64 0, !19, i64 32}
!17 = !{!"_ZTSSt18_Rb_tree_node_base", !18, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21), ptr noundef, ptr noundef, i32 noundef, i8 noundef signext) unnamed_addr #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %0) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call noundef zeroext i1 @_ZN11BinaryStdIn8readBoolEv(ptr noundef nonnull align 8 dereferenceable(528) %3)
  %5 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #5
  br i1 %4, label %6, label %12

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = invoke noundef signext i8 @_ZN11BinaryStdIn8readCharEv(ptr noundef nonnull align 8 dereferenceable(528) %7)
          to label %9 unwind label %10

9:                                                ; preds = %6
  tail call void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21) %5, ptr noundef null, ptr noundef null, i32 noundef -1, i8 noundef signext %8)
  br label %19

10:                                               ; preds = %6
  %11 = landingpad { ptr, i32 }
          cleanup
  br label %20

12:                                               ; preds = %1
  %13 = invoke noundef ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
          to label %14 unwind label %17

14:                                               ; preds = %12
  %15 = invoke noundef ptr @_ZN7HUFFMAN8readTrieEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
          to label %16 unwind label %17

16:                                               ; preds = %14
  tail call void @_ZN5HtreeC2EPS_S0_ic(ptr noundef nonnull align 8 dereferenceable(21) %5, ptr noundef nonnull %13, ptr noundef nonnull %15, i32 noundef -1, i8 noundef signext 0)
  br label %19

17:                                               ; preds = %14, %12
  %18 = landingpad { ptr, i32 }
          cleanup
  br label %20

19:                                               ; preds = %16, %9
  ret ptr %5

20:                                               ; preds = %17, %10
  %.pn = phi { ptr, i32 } [ %11, %10 ], [ %18, %17 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %5, i64 noundef 24) #6
  resume { ptr, i32 } %.pn
}

declare noundef zeroext i1 @_ZN11BinaryStdIn8readBoolEv(ptr noundef nonnull align 8 dereferenceable(528)) local_unnamed_addr #4

declare noundef signext i8 @_ZN11BinaryStdIn8readCharEv(ptr noundef nonnull align 8 dereferenceable(528)) local_unnamed_addr #4

attributes #0 = { nobuiltin allocsize(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 = { 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" }
attributes #2 = { nobuiltin 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 = { mustprogress 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 #4 = { "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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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, !7, i64 64}
!6 = !{!"_ZTS7HUFFMAN", !7, i64 0, !10, i64 8, !7, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt3mapIcSt6vectorIbSaIbEESt4lessIcESaISt4pairIKcS2_EEE", !11, i64 0}
!11 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcSt6vectorIbSaIbEEESt10_Select1stIS5_ESt4lessIcESaIS5_EE", !12, i64 0}
!12 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcSt6vectorIbSaIbEEESt10_Select1stIS5_ESt4lessIcESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !13, i64 0, !15, i64 8}
!13 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !14, i64 0}
!14 = !{!"_ZTSSt4lessIcE"}
!15 = !{!"_ZTSSt15_Rb_tree_header", !16, i64 0, !18, i64 32}
!16 = !{!"_ZTSSt18_Rb_tree_node_base", !17, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!17 = !{!"_ZTSSt14_Rb_tree_color", !8, i64 0}
!18 = !{!"long", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass