; LLVM IR from sbshah97/DS-Algo-Handbook :: Data-Structures/Tries (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"

@__const.main.keys = external hidden unnamed_addr constant [8 x [8 x i8]], align 16
@__const.main.output = external hidden unnamed_addr constant [2 x [32 x i8]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6insertP8TrieNodePKc(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca [8 x [8 x i8]], align 16
  %3 = alloca [2 x [32 x i8]], align 16
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.keys, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.output, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %6 = call noundef ptr @_Z7getNodev()
  store ptr %6, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %17, %0
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = icmp ult i64 %9, 8
  br i1 %10, label %11, label %20

11:                                               ; preds = %7
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [8 x [8 x i8]], ptr %2, i64 0, i64 %14
  %16 = getelementptr inbounds [8 x i8], ptr %15, i64 0, i64 0
  call void @_Z6insertP8TrieNodePKc(ptr noundef %12, ptr noundef %16)
  br label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !11

20:                                               ; preds = %7
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %21, ptr noundef @.str.1)
  %23 = zext i1 %22 to i64
  %24 = getelementptr inbounds [2 x [32 x i8]], ptr %3, i64 0, i64 %23
  %25 = getelementptr inbounds [32 x i8], ptr %24, i64 0, i64 0
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %27, ptr noundef @.str.2)
  %29 = zext i1 %28 to i64
  %30 = getelementptr inbounds [2 x [32 x i8]], ptr %3, i64 0, i64 %29
  %31 = getelementptr inbounds [32 x i8], ptr %30, i64 0, i64 0
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.2, ptr noundef %31)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %33, ptr noundef @.str.3)
  %35 = zext i1 %34 to i64
  %36 = getelementptr inbounds [2 x [32 x i8]], ptr %3, i64 0, i64 %35
  %37 = getelementptr inbounds [32 x i8], ptr %36, i64 0, i64 0
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.3, ptr noundef %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %39, ptr noundef @.str.4)
  %41 = zext i1 %40 to i64
  %42 = getelementptr inbounds [2 x [32 x i8]], ptr %3, i64 0, i64 %41
  %43 = getelementptr inbounds [32 x i8], ptr %42, i64 0, i64 0
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.4, ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %2) #5
  ret i32 0
}

; 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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 = { 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 = !{!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"

@__const.main.keys = external hidden unnamed_addr constant [8 x [8 x i8]], align 16
@__const.main.output = external hidden unnamed_addr constant [2 x [32 x i8]], align 16
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

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

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6insertP8TrieNodePKc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca [8 x [8 x i8]], align 16
  %2 = alloca [2 x [32 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %1, ptr noundef nonnull align 16 dereferenceable(64) @__const.main.keys, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %2, ptr noundef nonnull align 16 dereferenceable(64) @__const.main.output, i64 64, i1 false)
  %3 = tail call noundef ptr @_Z7getNodev()
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %1)
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %4)
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %5)
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %6)
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %7)
  %8 = getelementptr inbounds i8, ptr %1, i64 40
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %8)
  %9 = getelementptr inbounds i8, ptr %1, i64 48
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %9)
  %10 = getelementptr inbounds i8, ptr %1, i64 56
  call void @_Z6insertP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull %10)
  %11 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull @.str.1)
  %12 = zext i1 %11 to i64
  %13 = getelementptr inbounds [2 x [32 x i8]], ptr %2, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull %13)
  %15 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull @.str.2)
  %16 = zext i1 %15 to i64
  %17 = getelementptr inbounds [2 x [32 x i8]], ptr %2, i64 0, i64 %16
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.2, ptr noundef nonnull %17)
  %19 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull @.str.3)
  %20 = zext i1 %19 to i64
  %21 = getelementptr inbounds [2 x [32 x i8]], ptr %2, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.3, ptr noundef nonnull %21)
  %23 = call noundef zeroext i1 @_Z6searchP8TrieNodePKc(ptr noundef %3, ptr noundef nonnull @.str.4)
  %24 = zext i1 %23 to i64
  %25 = getelementptr inbounds [2 x [32 x i8]], ptr %2, i64 0, i64 %24
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.4, ptr noundef nonnull %25)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: mustprogress 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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)"}


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