; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Searching/Trie-Search/Trie_Search.ll (Z8deletionPP4TriePc)

; 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 = type { i32, [26 x ptr] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z12haveChildrenP4Trie(ptr noundef) #0

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

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %61

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %60

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Trie, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = sub nsw i32 %24, 97
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [26 x ptr], ptr %21, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %60

30:                                               ; preds = %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Trie, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = sub nsw i32 %36, 97
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [26 x ptr], ptr %33, i64 0, i64 %38
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 1
  %42 = call noundef i32 @_Z8deletionPP4TriePc(ptr noundef %39, ptr noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %60

44:                                               ; preds = %30
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Trie, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !10
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %60

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = call noundef i32 @_Z12haveChildrenP4Trie(ptr noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %59, label %55

55:                                               ; preds = %50
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  call void @free(ptr noundef %57) #3
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %58, align 8, !tbaa !5
  store i32 1, ptr %3, align 4
  br label %86

59:                                               ; preds = %50
  store i32 0, ptr %3, align 4
  br label %86

60:                                               ; preds = %44, %30, %18, %14
  br label %61

61:                                               ; preds = %60, %10
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i8, ptr %62, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %85

66:                                               ; preds = %61
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Trie, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !10
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %85

72:                                               ; preds = %66
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = call noundef i32 @_Z12haveChildrenP4Trie(ptr noundef %74)
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %81, label %77

77:                                               ; preds = %72
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  call void @free(ptr noundef %79) #3
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr null, ptr %80, align 8, !tbaa !5
  store i32 1, ptr %3, align 4
  br label %86

81:                                               ; preds = %72
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Trie, ptr %83, i32 0, i32 0
  store i32 0, ptr %84, align 8, !tbaa !10
  store i32 0, ptr %3, align 4
  br label %86

85:                                               ; preds = %66, %61
  store i32 0, ptr %3, align 4
  br label %86

86:                                               ; preds = %85, %81, %77, %59, %55, %9
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS4Trie", !12, i64 0, !7, i64 8}
!12 = !{!"int", !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 nounwind uwtable
declare dso_local noundef i32 @_Z12haveChildrenP4Trie(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z8deletionPP4TriePc(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %33, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr %1, align 1, !tbaa !9
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %.thread, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  %9 = sext i8 %6 to i64
  %10 = add nsw i64 %9, -97
  %11 = getelementptr inbounds [26 x ptr], ptr %8, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not20 = icmp eq ptr %12, null
  br i1 %.not20, label %24, label %13

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %1, i64 1
  %15 = tail call noundef i32 @_Z8deletionPP4TriePc(ptr noundef nonnull %11, ptr noundef nonnull %14)
  %.not21 = icmp eq i32 %15, 0
  br i1 %.not21, label %24, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 8, !tbaa !10
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = tail call noundef i32 @_Z12haveChildrenP4Trie(ptr noundef nonnull %17)
  %.not24 = icmp eq i32 %21, 0
  br i1 %.not24, label %22, label %33

22:                                               ; preds = %20
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @free(ptr noundef %23) #2
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %33

24:                                               ; preds = %7, %13, %16
  %.pr = load i8, ptr %1, align 1, !tbaa !9
  %25 = icmp eq i8 %.pr, 0
  br i1 %25, label %..thread_crit_edge, label %33

..thread_crit_edge:                               ; preds = %24
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %5
  %26 = phi ptr [ %.pre, %..thread_crit_edge ], [ %3, %5 ]
  %27 = load i32, ptr %26, align 8, !tbaa !10
  %.not22 = icmp eq i32 %27, 0
  br i1 %.not22, label %33, label %28

28:                                               ; preds = %.thread
  %29 = tail call noundef i32 @_Z12haveChildrenP4Trie(ptr noundef nonnull %26)
  %.not23 = icmp eq i32 %29, 0
  %30 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %.not23, label %31, label %32

31:                                               ; preds = %28
  tail call void @free(ptr noundef %30) #2
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %33

32:                                               ; preds = %28
  store i32 0, ptr %30, align 8, !tbaa !10
  br label %33

33:                                               ; preds = %24, %.thread, %20, %2, %32, %31, %22
  %.0 = phi i32 [ 1, %22 ], [ 0, %32 ], [ 1, %31 ], [ 0, %2 ], [ 0, %20 ], [ 0, %.thread ], [ 0, %24 ]
  ret i32 %.0
}

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

attributes #0 = { 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 #1 = { 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS4Trie", !12, i64 0, !7, i64 8}
!12 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass