; LLVM IR from BartoszMilewski/Okasaki :: trie.ll/Z4findP9trie_nodeNSt7 (cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb)

; 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.trie_node = type { i8, i8, %"class.std::map" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<char, std::pair<const char, trie_node *>, std::_Select1st<std::pair<const char, trie_node *>>, std::less<char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<char, std::pair<const char, trie_node *>, std::_Select1st<std::pair<const char, trie_node *>>, 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 }

; 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: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 1 dereferenceable(1)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4findP9trie_nodeNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %14 = zext i1 %2 to i8
  store i8 %14, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 1, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %48, %3
  %17 = load i32, ptr %10, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %11, align 4
  br label %51

22:                                               ; preds = %16
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.trie_node, ptr %23, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %25 = load i32, ptr %10, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %26)
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i32
  %30 = sub nsw i32 %29, 97
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %12, align 1, !tbaa !13
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48) %24, ptr noundef nonnull align 1 dereferenceable(1) %12)
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  br i1 %34, label %35, label %36

35:                                               ; preds = %22
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %51

36:                                               ; preds = %22
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.trie_node, ptr %37, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  %39 = load i32, ptr %10, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %40)
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = sub nsw i32 %43, 97
  %45 = trunc i32 %44 to i8
  store i8 %45, ptr %13, align 1, !tbaa !13
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48) %38, ptr noundef nonnull align 1 dereferenceable(1) %13)
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  store ptr %47, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  br label %48

48:                                               ; preds = %36
  %49 = load i32, ptr %10, align 4, !tbaa !11
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %10, align 4, !tbaa !11
  br label %16, !llvm.loop !14

51:                                               ; preds = %35, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %52 = load i32, ptr %11, align 4
  switch i32 %52, label %64 [
    i32 2, label %53
  ]

53:                                               ; preds = %51
  %54 = load i8, ptr %7, align 1, !tbaa !9, !range !16, !noundef !17
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  br label %62

57:                                               ; preds = %53
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.trie_node, ptr %58, i32 0, i32 1
  %60 = load i8, ptr %59, align 1, !tbaa !18, !range !16, !noundef !17
  %61 = trunc i8 %60 to i1
  br label %62

62:                                               ; preds = %57, %56
  %63 = phi i1 [ true, %56 ], [ %61, %57 ]
  store i1 %63, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %64

64:                                               ; preds = %62, %51
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %65 = load i1, ptr %4, align 1
  ret i1 %65
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !10, i64 1}
!19 = !{!"_ZTS9trie_node", !7, i64 0, !10, i64 1, !20, i64 8}
!20 = !{!"_ZTSSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEE", !21, i64 0}
!21 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcP9trie_nodeESt10_Select1stIS4_ESt4lessIcESaIS4_EE", !22, i64 0}
!22 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcP9trie_nodeESt10_Select1stIS4_ESt4lessIcESaIS4_EE13_Rb_tree_implIS8_Lb1EEE", !23, i64 0, !25, i64 8}
!23 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !24, i64 0}
!24 = !{!"_ZTSSt4lessIcE"}
!25 = !{!"_ZTSSt15_Rb_tree_header", !26, i64 0, !28, i64 32}
!26 = !{!"_ZTSSt18_Rb_tree_node_base", !27, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!27 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!28 = !{!"long", !7, i64 0}


; 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: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4findP9trie_nodeNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb(ptr noundef %0, ptr noundef nonnull %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %.not15.not = icmp eq i64 %6, 0
  br i1 %.not15.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %14
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ 0, %3 ]
  %.01216 = phi ptr [ %19, %14 ], [ %0, %3 ]
  %7 = getelementptr inbounds i8, ptr %.01216, i64 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %8 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %indvars.iv)
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = add i8 %9, -97
  store i8 %10, ptr %4, align 1, !tbaa !5
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48) %7, ptr noundef nonnull align 1 dereferenceable(1) %4)
  %12 = load ptr, ptr %11, align 8, !tbaa !8
  %13 = icmp eq ptr %12, null
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %indvars.iv)
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = add i8 %16, -97
  store i8 %17, ptr %5, align 1, !tbaa !5
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEEixEOc(ptr noundef nonnull align 8 dereferenceable(48) %7, ptr noundef nonnull align 1 dereferenceable(1) %5)
  %19 = load ptr, ptr %18, align 8, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %.not = icmp ugt i64 %20, %indvars.iv.next
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %14, %3
  %.012.lcssa = phi ptr [ %0, %3 ], [ %19, %14 ]
  br i1 %2, label %.loopexit, label %21

21:                                               ; preds = %.critedge
  %22 = getelementptr inbounds i8, ptr %.012.lcssa, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !12, !range !24, !noundef !25
  %24 = trunc nuw i8 %23 to i1
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %21, %.critedge
  %.1 = phi i1 [ %24, %21 ], [ true, %.critedge ], [ false, %.lr.ph ]
  ret i1 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 1}
!13 = !{!"_ZTS9trie_node", !6, i64 0, !14, i64 1, !15, i64 8}
!14 = !{!"bool", !6, i64 0}
!15 = !{!"_ZTSSt3mapIcP9trie_nodeSt4lessIcESaISt4pairIKcS1_EEE", !16, i64 0}
!16 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcP9trie_nodeESt10_Select1stIS4_ESt4lessIcESaIS4_EE", !17, i64 0}
!17 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcP9trie_nodeESt10_Select1stIS4_ESt4lessIcESaIS4_EE13_Rb_tree_implIS8_Lb1EEE", !18, i64 0, !20, i64 8}
!18 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !19, i64 0}
!19 = !{!"_ZTSSt4lessIcE"}
!20 = !{!"_ZTSSt15_Rb_tree_header", !21, i64 0, !23, i64 32}
!21 = !{!"_ZTSSt18_Rb_tree_node_base", !22, i64 0, !9, i64 8, !9, i64 16, !9, i64 24}
!22 = !{!"_ZTSSt14_Rb_tree_color", !6, i64 0}
!23 = !{!"long", !6, i64 0}
!24 = !{i8 0, i8 2}
!25 = !{}


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