; LLVM IR from AlgoGenesis/C :: Trie/LongestCommonPrefix (LongestCommonPrefix)

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @createNode(i8 noundef signext) #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: nounwind uwtable
define dso_local void @insert(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i64 @strlen(ptr noundef %8) #3
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TrieNode, ptr %12, i32 0, i32 2
  store i8 1, ptr %13, align 8, !tbaa !9
  br label %52

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !13
  store i8 %17, ptr %5, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %18 = load i8, ptr %5, align 1, !tbaa !13
  %19 = sext i8 %18 to i32
  %20 = sub nsw i32 %19, 97
  store i32 %20, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TrieNode, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %6, align 4, !tbaa !14
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [26 x ptr], ptr %22, i64 0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %14
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TrieNode, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %6, align 4, !tbaa !14
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [26 x ptr], ptr %30, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %48

35:                                               ; preds = %14
  %36 = load i8, ptr %5, align 1, !tbaa !13
  %37 = call ptr @createNode(i8 noundef signext %36)
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TrieNode, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 4, !tbaa !15
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 4, !tbaa !15
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TrieNode, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %6, align 4, !tbaa !14
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [26 x ptr], ptr %44, i64 0, i64 %46
  store ptr %42, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %35, %28
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 1
  call void @insert(ptr noundef %49, ptr noundef %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %52

52:                                               ; preds = %48, %11
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 willreturn memory(read) }
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, !11, i64 216}
!10 = !{!"TrieNode", !7, i64 0, !7, i64 8, !11, i64 216, !12, i64 220}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 220}


; 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 ptr @createNode(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @insert(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %char016 = load i8, ptr %1, align 1
  %3 = icmp eq i8 %char016, 0
  br i1 %3, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %.tr.lcssa = phi ptr [ %0, %2 ], [ %.0, %tailrecurse ]
  %4 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 216
  store i8 1, ptr %4, align 8, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %2, %tailrecurse
  %char019 = phi i8 [ %char0, %tailrecurse ], [ %char016, %2 ]
  %.tr1518 = phi ptr [ %15, %tailrecurse ], [ %1, %2 ]
  %.tr17 = phi ptr [ %.0, %tailrecurse ], [ %0, %2 ]
  %5 = sext i8 %char019 to i64
  %6 = add nsw i64 %5, -97
  %7 = getelementptr inbounds i8, ptr %.tr17, i64 8
  %8 = getelementptr inbounds [26 x ptr], ptr %7, i64 0, i64 %6
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %tailrecurse

10:                                               ; preds = %.lr.ph
  %11 = tail call ptr @createNode(i8 noundef signext %char019)
  %12 = getelementptr inbounds i8, ptr %.tr17, i64 220
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !13
  store ptr %11, ptr %8, align 8, !tbaa !11
  br label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph, %10
  %.0 = phi ptr [ %11, %10 ], [ %9, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %.tr1518, i64 1
  %char0 = load i8, ptr %15, align 1
  %16 = icmp eq i8 %char0, 0
  br i1 %16, label %tailrecurse._crit_edge, label %.lr.ph
}

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

!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, !9, i64 216}
!6 = !{!"TrieNode", !7, i64 0, !7, i64 8, !9, i64 216, !10, i64 220}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"_Bool", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!6, !10, i64 220}


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