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

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

; 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

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

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

24:                                               ; preds = %19, %5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = call i32 @arrayListGetLength(ptr noundef %25)
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  br label %118

30:                                               ; preds = %24
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TrieNode, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %45

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !14
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %45

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

45:                                               ; preds = %40, %35, %30
  br label %46

46:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !14
  %49 = call signext i8 @toLowerCase(i8 noundef signext %48)
  %50 = sext i8 %49 to i32
  %51 = sub nsw i32 %50, 97
  store i32 %51, ptr %12, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i8, ptr %52, align 1, !tbaa !14
  %54 = sext i8 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %78

56:                                               ; preds = %46
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TrieNode, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %59, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %78

65:                                               ; preds = %56
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TrieNode, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 1
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  call void @trieAutoCompletionR(ptr noundef %72, ptr noundef %74, i32 noundef %75, ptr noundef %76, ptr noundef %77)
  br label %108

78:                                               ; preds = %56, %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %104, %78
  %80 = load i32, ptr %13, align 4, !tbaa !9
  %81 = icmp slt i32 %80, 26
  br i1 %81, label %83, label %82

82:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %107

83:                                               ; preds = %79
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.TrieNode, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds ptr, ptr %86, i64 %88
  %90 = load ptr, ptr %89, align 8, !tbaa !5
  %91 = icmp ne ptr %90, null
  br i1 %91, label %92, label %103

92:                                               ; preds = %83
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.TrieNode, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !15
  %96 = load i32, ptr %13, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds ptr, ptr %95, i64 %97
  %99 = load ptr, ptr %98, align 8, !tbaa !5
  %100 = load i32, ptr %8, align 4, !tbaa !9
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  call void @trieAutoCompletionR(ptr noundef %99, ptr noundef @.str.7, i32 noundef %100, ptr noundef %101, ptr noundef %102)
  br label %103

103:                                              ; preds = %92, %83
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %13, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %13, align 4, !tbaa !9
  br label %79, !llvm.loop !16

107:                                              ; preds = %82
  br label %108

108:                                              ; preds = %107, %65
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  %110 = call i32 @stringGetLength(ptr noundef %109)
  %111 = icmp ne i32 %110, 0
  br i1 %111, label %112, label %117

112:                                              ; preds = %108
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = load ptr, ptr %9, align 8, !tbaa !5
  %115 = call i32 @stringGetLength(ptr noundef %114)
  %116 = sub nsw i32 %115, 1
  call void @stringRemove(ptr noundef %113, i32 noundef %116)
  br label %117

117:                                              ; preds = %112, %108
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %118

118:                                              ; preds = %117, %29
  ret void
}

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

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 }

!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 = !{!12, !10, i64 12}
!14 = !{!7, !7, i64 0}
!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"

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

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

; Function Attrs: nounwind uwtable
define dso_local void @trieAutoCompletionR(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3, ptr 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 %3, i8 noundef signext %7) #2
  br label %9

9:                                                ; preds = %8, %5
  %10 = tail call i32 @arrayListGetLength(ptr noundef %4) #2
  %11 = icmp eq i32 %10, %2
  br i1 %11, label %40, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %.not34 = icmp ne i32 %14, 0
  %.pre41 = load i8, ptr %1, align 1, !tbaa !12
  %15 = icmp eq i8 %.pre41, 0
  %or.cond = select i1 %.not34, i1 %15, i1 false
  br i1 %or.cond, label %16, label %18

16:                                               ; preds = %12
  %17 = tail call ptr @stringToCharArray(ptr noundef %3) #2
  tail call void @arrayListAdd(ptr noundef %4, ptr noundef %17) #2
  %.pre = load i8, ptr %1, align 1, !tbaa !12
  br label %18

18:                                               ; preds = %12, %16
  %19 = phi i8 [ %.pre41, %12 ], [ %.pre, %16 ]
  %20 = tail call signext i8 @toLowerCase(i8 noundef signext %19)
  %21 = load i8, ptr %1, align 1, !tbaa !12
  %.not35 = icmp eq i8 %21, 0
  br i1 %.not35, label %.preheader, label %22

.preheader:                                       ; preds = %22, %18
  br label %30

22:                                               ; preds = %18
  %23 = sext i8 %20 to i64
  %24 = load ptr, ptr %0, align 8, !tbaa !13
  %25 = getelementptr ptr, ptr %24, i64 %23
  %26 = getelementptr i8, ptr %25, i64 -776
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %.not36 = icmp eq ptr %27, null
  br i1 %.not36, label %.preheader, label %28

28:                                               ; preds = %22
  %29 = getelementptr inbounds i8, ptr %1, i64 1
  tail call void @trieAutoCompletionR(ptr noundef nonnull %27, ptr noundef nonnull %29, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  br label %.loopexit

30:                                               ; preds = %.preheader, %35
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ 0, %.preheader ]
  %31 = load ptr, ptr %0, align 8, !tbaa !13
  %32 = getelementptr inbounds ptr, ptr %31, i64 %indvars.iv
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %.not37 = icmp eq ptr %33, null
  br i1 %.not37, label %35, label %34

34:                                               ; preds = %30
  tail call void @trieAutoCompletionR(ptr noundef nonnull %33, ptr noundef nonnull @.str.7, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  br label %35

35:                                               ; preds = %30, %34
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 26
  br i1 %exitcond.not, label %.loopexit, label %30, !llvm.loop !15

.loopexit:                                        ; preds = %35, %28
  %36 = tail call i32 @stringGetLength(ptr noundef %3) #2
  %.not38 = icmp eq i32 %36, 0
  br i1 %.not38, label %40, label %37

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

40:                                               ; preds = %.loopexit, %37, %9
  ret void
}

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

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


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