; LLVM IR from nonstriater/Learn-Algorithms :: 4 Tree/4-字典树Trie (trie)

; 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.node = type { i32, i8, [26 x 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: nounwind uwtable
define dso_local i32 @trie_query(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %77

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.node, ptr %16, i32 0, i32 2
  %18 = getelementptr inbounds [26 x ptr], ptr %17, i64 0, i64 0
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

21:                                               ; preds = %13
  br label %22

22:                                               ; preds = %55, %21
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %68

27:                                               ; preds = %22
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = sub nsw i32 %32, 97
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [26 x ptr], ptr %29, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %67

38:                                               ; preds = %27
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = sub nsw i32 %43, 97
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [26 x ptr], ptr %40, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 1
  %49 = load i8, ptr %48, align 4, !tbaa !12
  %50 = sext i8 %49 to i32
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = icmp eq i32 %50, %53
  br i1 %54, label %55, label %67

55:                                               ; preds = %38
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = sext i8 %59 to i32
  %61 = sub nsw i32 %60, 97
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [26 x ptr], ptr %57, i64 0, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i32 1
  store ptr %66, ptr %6, align 8, !tbaa !5
  br label %22, !llvm.loop !14

67:                                               ; preds = %38, %27
  br label %68

68:                                               ; preds = %67, %22
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i8, ptr %69, align 1, !tbaa !11
  %71 = sext i8 %70 to i32
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %68
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %73, %68
  %75 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %75, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

76:                                               ; preds = %74, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %77

77:                                               ; preds = %76, %12
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 4}
!13 = !{!"node", !10, i64 0, !7, i64 4, !7, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @trie_query(ptr noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %2
  %4 = load i8, ptr %1, align 1, !tbaa !5
  %.not22 = icmp eq i8 %4, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %14
  %6 = getelementptr inbounds i8, ptr %.01623, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

.lr.ph:                                           ; preds = %.preheader, %5
  %8 = phi i8 [ %7, %5 ], [ %4, %.preheader ]
  %.01524 = phi ptr [ %13, %5 ], [ %0, %.preheader ]
  %.01623 = phi ptr [ %6, %5 ], [ %1, %.preheader ]
  %9 = sext i8 %8 to i64
  %10 = getelementptr inbounds i8, ptr %.01524, i64 8
  %11 = add nsw i64 %9, -97
  %12 = getelementptr inbounds [26 x ptr], ptr %10, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %.not21 = icmp eq ptr %13, null
  br i1 %.not21, label %._crit_edge, label %14

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %13, i64 4
  %16 = load i8, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i8 %16, %8
  br i1 %17, label %5, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %14, %5, %.preheader, %2
  %.1 = phi i32 [ 0, %2 ], [ 1, %.preheader ], [ 0, %.lr.ph ], [ 0, %14 ], [ 1, %5 ]
  ret i32 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !6, i64 4}
!13 = !{!"node", !14, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!"int", !6, i64 0}


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