; LLVM IR from xtaci/algorithms :: src (trie_demo)

; 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.alg::Trie" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@__const.main.strs = external hidden unnamed_addr constant [13 x ptr], align 16
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.alg::Trie", align 8
  %3 = alloca [13 x ptr], align 16
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  call void @_ZN3alg4TrieC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.start.p0(i64 104, ptr %3) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.strs, i64 104, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %22, %0
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = icmp ult i64 %10, 13
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %29

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [13 x ptr], ptr %3, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call noalias ptr @strdup(ptr noundef %17) #7
  store ptr %18, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef %19)
          to label %20 unwind label %25

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %21) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  br label %22

22:                                               ; preds = %20
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = add i32 %23, 1
  store i32 %24, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !11

25:                                               ; preds = %13
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %6, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %43

29:                                               ; preds = %12
  %30 = invoke noundef i32 @_ZN3alg4Trie5CountEPKc(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef @.str.1)
          to label %31 unwind label %39

31:                                               ; preds = %29
  %32 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef %30)
          to label %33 unwind label %39

33:                                               ; preds = %31
  %34 = invoke noundef i32 @_ZN3alg4Trie11CountPrefixEPKc(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef @.str.12)
          to label %35 unwind label %39

35:                                               ; preds = %33
  %36 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.11, ptr noundef @.str.12, i32 noundef %34)
          to label %37 unwind label %39

37:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 104, ptr %3) #7
  call void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  %38 = load i32, ptr %1, align 4
  ret i32 %38

39:                                               ; preds = %35, %33, %31, %29
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %6, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %7, align 4
  br label %43

43:                                               ; preds = %39, %25
  call void @llvm.lifetime.end.p0(i64 104, ptr %3) #7
  call void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %6, align 8
  %46 = load i32, ptr %7, align 4
  %47 = insertvalue { ptr, i32 } poison, ptr %45, 0
  %48 = insertvalue { ptr, i32 } %47, i32 %46, 1
  resume { ptr, i32 } %48
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3alg4TrieC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #4

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #6 align 2

attributes #0 = { mustprogress norecurse 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = { 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 #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

%"class.alg::Trie" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@__const.main.strs = external hidden unnamed_addr constant [13 x ptr], align 16
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.alg::Trie", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #7
  call void @_ZN3alg4TrieC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %2 = load ptr, ptr @__const.main.strs, align 16, !tbaa !5
  %3 = call noalias ptr @strdup(ptr noundef %2) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %3)
          to label %4 unwind label %42

4:                                                ; preds = %0
  call void @free(ptr noundef %3) #7
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 8), align 8, !tbaa !5
  %6 = call noalias ptr @strdup(ptr noundef %5) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %6)
          to label %7 unwind label %42

7:                                                ; preds = %4
  call void @free(ptr noundef %6) #7
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 16), align 16, !tbaa !5
  %9 = call noalias ptr @strdup(ptr noundef %8) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %9)
          to label %10 unwind label %42

10:                                               ; preds = %7
  call void @free(ptr noundef %9) #7
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 24), align 8, !tbaa !5
  %12 = call noalias ptr @strdup(ptr noundef %11) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %12)
          to label %13 unwind label %42

13:                                               ; preds = %10
  call void @free(ptr noundef %12) #7
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 32), align 16, !tbaa !5
  %15 = call noalias ptr @strdup(ptr noundef %14) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %15)
          to label %16 unwind label %42

16:                                               ; preds = %13
  call void @free(ptr noundef %15) #7
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 40), align 8, !tbaa !5
  %18 = call noalias ptr @strdup(ptr noundef %17) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %18)
          to label %19 unwind label %42

19:                                               ; preds = %16
  call void @free(ptr noundef %18) #7
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 48), align 16, !tbaa !5
  %21 = call noalias ptr @strdup(ptr noundef %20) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %21)
          to label %22 unwind label %42

22:                                               ; preds = %19
  call void @free(ptr noundef %21) #7
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 56), align 8, !tbaa !5
  %24 = call noalias ptr @strdup(ptr noundef %23) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %24)
          to label %25 unwind label %42

25:                                               ; preds = %22
  call void @free(ptr noundef %24) #7
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 64), align 16, !tbaa !5
  %27 = call noalias ptr @strdup(ptr noundef %26) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %27)
          to label %28 unwind label %42

28:                                               ; preds = %25
  call void @free(ptr noundef %27) #7
  %29 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 72), align 8, !tbaa !5
  %30 = call noalias ptr @strdup(ptr noundef %29) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %30)
          to label %31 unwind label %42

31:                                               ; preds = %28
  call void @free(ptr noundef %30) #7
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 80), align 16, !tbaa !5
  %33 = call noalias ptr @strdup(ptr noundef %32) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %33)
          to label %34 unwind label %42

34:                                               ; preds = %31
  call void @free(ptr noundef %33) #7
  %35 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 88), align 8, !tbaa !5
  %36 = call noalias ptr @strdup(ptr noundef %35) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %36)
          to label %37 unwind label %42

37:                                               ; preds = %34
  call void @free(ptr noundef %36) #7
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @__const.main.strs, i64 96), align 16, !tbaa !5
  %39 = call noalias ptr @strdup(ptr noundef %38) #7
  invoke void @_ZN3alg4Trie3AddEPc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %39)
          to label %40 unwind label %42

40:                                               ; preds = %37
  call void @free(ptr noundef %39) #7
  %41 = invoke noundef i32 @_ZN3alg4Trie5CountEPKc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull @.str.1)
          to label %44 unwind label %49

42:                                               ; preds = %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4, %0
  %43 = landingpad { ptr, i32 }
          cleanup
  br label %51

44:                                               ; preds = %40
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef nonnull @.str.1, i32 noundef %41)
  %46 = invoke noundef i32 @_ZN3alg4Trie11CountPrefixEPKc(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull @.str.12)
          to label %47 unwind label %49

47:                                               ; preds = %44
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, ptr noundef nonnull @.str.12, i32 noundef %46)
  call void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #7
  ret i32 0

49:                                               ; preds = %44, %40
  %50 = landingpad { ptr, i32 }
          cleanup
  br label %51

51:                                               ; preds = %49, %42
  %.pn = phi { ptr, i32 } [ %43, %42 ], [ %50, %49 ]
  call void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %1) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #7
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3alg4TrieC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3alg4TrieD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #6 align 2

attributes #0 = { mustprogress norecurse 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, 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 #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #5 = { 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 #6 = { 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 #7 = { 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass