; 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] }

@.str = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @trie_create(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr null, %5
  br i1 %6, label %7, label %31

7:                                                ; preds = %1
  %8 = call noalias ptr @malloc(i64 noundef 216) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %7
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %15

15:                                               ; preds = %13, %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %27, %15
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 26
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %30

20:                                               ; preds = %16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [26 x ptr], ptr %23, i64 0, i64 %25
  store ptr null, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %20
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !9
  br label %16, !llvm.loop !11

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30, %1
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  ret ptr %33
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

declare i32 @printf(ptr noundef, ...) #2

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

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

attributes #0 = { 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 #1 = { nounwind 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

@.str = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local ptr @trie_create(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %.loopexit

4:                                                ; preds = %1
  %5 = tail call noalias dereferenceable_or_null(216) ptr @malloc(i64 noundef 216) #3
  store ptr %5, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %.loopexit.loopexit

7:                                                ; preds = %4
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %7, %4
  %9 = phi ptr [ %.pre, %7 ], [ %5, %4 ]
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr null, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr null, ptr %12, align 8, !tbaa !5
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 32
  store ptr null, ptr %16, align 8, !tbaa !5
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 40
  store ptr null, ptr %18, align 8, !tbaa !5
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 48
  store ptr null, ptr %20, align 8, !tbaa !5
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 56
  store ptr null, ptr %22, align 8, !tbaa !5
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 64
  store ptr null, ptr %24, align 8, !tbaa !5
  %25 = load ptr, ptr %0, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 72
  store ptr null, ptr %26, align 8, !tbaa !5
  %27 = load ptr, ptr %0, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 80
  store ptr null, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 88
  store ptr null, ptr %30, align 8, !tbaa !5
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 96
  store ptr null, ptr %32, align 8, !tbaa !5
  %33 = load ptr, ptr %0, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 104
  store ptr null, ptr %34, align 8, !tbaa !5
  %35 = load ptr, ptr %0, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 112
  store ptr null, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %0, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 120
  store ptr null, ptr %38, align 8, !tbaa !5
  %39 = load ptr, ptr %0, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 128
  store ptr null, ptr %40, align 8, !tbaa !5
  %41 = load ptr, ptr %0, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 136
  store ptr null, ptr %42, align 8, !tbaa !5
  %43 = load ptr, ptr %0, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 144
  store ptr null, ptr %44, align 8, !tbaa !5
  %45 = load ptr, ptr %0, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 152
  store ptr null, ptr %46, align 8, !tbaa !5
  %47 = load ptr, ptr %0, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 160
  store ptr null, ptr %48, align 8, !tbaa !5
  %49 = load ptr, ptr %0, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 168
  store ptr null, ptr %50, align 8, !tbaa !5
  %51 = load ptr, ptr %0, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 176
  store ptr null, ptr %52, align 8, !tbaa !5
  %53 = load ptr, ptr %0, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 184
  store ptr null, ptr %54, align 8, !tbaa !5
  %55 = load ptr, ptr %0, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 192
  store ptr null, ptr %56, align 8, !tbaa !5
  %57 = load ptr, ptr %0, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 200
  store ptr null, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %0, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 208
  store ptr null, ptr %60, align 8, !tbaa !5
  %.pre9 = load ptr, ptr %0, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %1
  %61 = phi ptr [ %.pre9, %.loopexit.loopexit ], [ %2, %1 ]
  ret ptr %61
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { nofree 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 #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree 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 = { nounwind allocsize(0) }

!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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass