; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Trees/Sources (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.TrieNode = type { ptr, i8, i32 }

; 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
declare dso_local signext i8 @toLowerCase(i8 noundef signext) #1

declare void @stringAppendChar(ptr noundef, i8 noundef signext) #2

declare i32 @arrayListGetLength(ptr noundef) #2

declare ptr @stringToCharArray(ptr noundef) #2

declare void @arrayListAdd(ptr noundef, ptr noundef) #2

declare i32 @stringGetLength(ptr noundef) #2

declare void @stringRemove(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @trieSuggestionR(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TrieNode, ptr %15, i32 0, i32 1
  %17 = load i8, ptr %16, align 8, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TrieNode, ptr %22, i32 0, i32 1
  %24 = load i8, ptr %23, align 8, !tbaa !11
  call void @stringAppendChar(ptr noundef %21, i8 noundef signext %24)
  br label %25

25:                                               ; preds = %20, %5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %48

30:                                               ; preds = %25
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call i32 @arrayListGetLength(ptr noundef %31)
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  br label %115

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TrieNode, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call ptr @stringToCharArray(ptr noundef %42)
  store ptr %43, ptr %11, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  call void @arrayListAdd(ptr noundef %44, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %46

46:                                               ; preds = %41, %36
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47, %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i8, ptr %49, align 1, !tbaa !13
  %51 = call signext i8 @toLowerCase(i8 noundef signext %50)
  %52 = call ptr @generateIndices(i8 noundef signext %51)
  store ptr %52, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store i32 1, ptr %13, align 4
  br label %113

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %99, %56
  %58 = load i32, ptr %14, align 4, !tbaa !9
  %59 = icmp slt i32 %58, 26
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %102

61:                                               ; preds = %57
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.TrieNode, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %64, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %98

74:                                               ; preds = %61
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TrieNode, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %78, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds ptr, ptr %77, i64 %83
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load i8, ptr %87, align 1, !tbaa !13
  %89 = sext i8 %88 to i32
  %90 = icmp eq i32 %89, 0
  %91 = zext i1 %90 to i64
  %92 = select i1 %90, i32 0, i32 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i8, ptr %86, i64 %93
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load i32, ptr %10, align 4, !tbaa !9
  call void @trieSuggestionR(ptr noundef %85, ptr noundef %94, ptr noundef %95, ptr noundef %96, i32 noundef %97)
  br label %98

98:                                               ; preds = %74, %61
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %14, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %14, align 4, !tbaa !9
  br label %57, !llvm.loop !16

102:                                              ; preds = %60
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %103) #4
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = call i32 @stringGetLength(ptr noundef %104)
  %106 = icmp ne i32 %105, 0
  br i1 %106, label %107, label %112

107:                                              ; preds = %102
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = call i32 @stringGetLength(ptr noundef %109)
  %111 = sub nsw i32 %110, 1
  call void @stringRemove(ptr noundef %108, i32 noundef %111)
  br label %112

112:                                              ; preds = %107, %102
  store i32 0, ptr %13, align 4
  br label %113

113:                                              ; preds = %112, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %114 = load i32, ptr %13, align 4
  switch i32 %114, label %116 [
    i32 0, label %115
    i32 1, label %115
  ]

115:                                              ; preds = %113, %113, %35
  ret void

116:                                              ; preds = %113
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @generateIndices(i8 noundef signext) #1

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

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 = { "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 "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 = { 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 = !{!12, !7, i64 8}
!12 = !{!"TrieNode", !6, i64 0, !7, i64 8, !10, i64 12}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !10, i64 12}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind uwtable
declare dso_local signext i8 @toLowerCase(i8 noundef signext) local_unnamed_addr #0

declare void @stringAppendChar(ptr noundef, i8 noundef signext) local_unnamed_addr #1

declare i32 @arrayListGetLength(ptr noundef) local_unnamed_addr #1

declare ptr @stringToCharArray(ptr noundef) local_unnamed_addr #1

declare void @arrayListAdd(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @stringGetLength(ptr noundef) local_unnamed_addr #1

declare void @stringRemove(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @trieSuggestionR(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i8, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %5
  tail call void @stringAppendChar(ptr noundef %2, i8 noundef signext %7) #3
  br label %9

9:                                                ; preds = %8, %5
  %10 = load i8, ptr %1, align 1, !tbaa !11
  %11 = icmp eq i8 %10, 0
  br i1 %11, label %12, label %20

12:                                               ; preds = %9
  %13 = tail call i32 @arrayListGetLength(ptr noundef %3) #3
  %14 = icmp eq i32 %13, %4
  br i1 %14, label %42, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %.not30 = icmp eq i32 %17, 0
  br i1 %.not30, label %20, label %18

18:                                               ; preds = %15
  %19 = tail call ptr @stringToCharArray(ptr noundef %2) #3
  tail call void @arrayListAdd(ptr noundef %3, ptr noundef %19) #3
  br label %20

20:                                               ; preds = %18, %15, %9
  %21 = load i8, ptr %1, align 1, !tbaa !11
  %22 = tail call signext i8 @toLowerCase(i8 noundef signext %21)
  %23 = tail call ptr @generateIndices(i8 noundef signext %22)
  %24 = icmp eq ptr %23, null
  br i1 %24, label %42, label %.preheader

25:                                               ; preds = %38
  tail call void @free(ptr noundef nonnull %23) #3
  %26 = tail call i32 @stringGetLength(ptr noundef %2) #3
  %.not31 = icmp eq i32 %26, 0
  br i1 %.not31, label %42, label %39

.preheader:                                       ; preds = %20, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 0, %20 ]
  %27 = load ptr, ptr %0, align 8, !tbaa !13
  %28 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %27, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %.not32 = icmp eq ptr %32, null
  br i1 %.not32, label %38, label %33

33:                                               ; preds = %.preheader
  %34 = load i8, ptr %1, align 1, !tbaa !11
  %35 = icmp ne i8 %34, 0
  %36 = zext i1 %35 to i64
  %37 = getelementptr inbounds i8, ptr %1, i64 %36
  tail call void @trieSuggestionR(ptr noundef nonnull %32, ptr noundef nonnull %37, ptr noundef %2, ptr noundef %3, i32 noundef %4)
  br label %38

38:                                               ; preds = %.preheader, %33
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 26
  br i1 %exitcond.not, label %25, label %.preheader, !llvm.loop !16

39:                                               ; preds = %25
  %40 = tail call i32 @stringGetLength(ptr noundef %2) #3
  %41 = add nsw i32 %40, -1
  tail call void @stringRemove(ptr noundef %2, i32 noundef %41) #3
  br label %42

42:                                               ; preds = %20, %39, %25, %12
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @generateIndices(i8 noundef signext) local_unnamed_addr #0

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

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 = { "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 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 #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, !8, i64 8}
!6 = !{!"TrieNode", !7, i64 0, !8, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !10, i64 12}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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