; LLVM IR from AlgoGenesis/C :: String Algorithms/Aho-Corasick Algorithm (Program)

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @createNode() #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, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %8, ptr %7, align 8, !tbaa !5
  br label %9

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

13:                                               ; preds = %9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TrieNode, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = sext i8 %17 to i64
  %19 = getelementptr inbounds [256 x ptr], ptr %15, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %30

22:                                               ; preds = %13
  %23 = call ptr @createNode()
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TrieNode, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i64
  %29 = getelementptr inbounds [256 x ptr], ptr %25, i64 0, i64 %28
  store ptr %23, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %22, %13
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TrieNode, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i64
  %36 = getelementptr inbounds [256 x ptr], ptr %32, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %9, !llvm.loop !12

40:                                               ; preds = %9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TrieNode, ptr %41, i32 0, i32 4
  store i32 1, ptr %42, align 4, !tbaa !14
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TrieNode, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TrieNode, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !17
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = mul i64 %50, 4
  %52 = call ptr @realloc(ptr noundef %45, i64 noundef %51) #4
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TrieNode, ptr %53, i32 0, i32 2
  store ptr %52, ptr %54, align 8, !tbaa !16
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TrieNode, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TrieNode, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 8, !tbaa !17
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds i32, ptr %58, i64 %63
  store i32 %55, ptr %64, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 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 allocsize(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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(1) }

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


; 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() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @insert(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i8, ptr %1, align 1, !tbaa !5
  %.not17 = icmp eq i8 %4, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %15
  %5 = phi i8 [ %18, %15 ], [ %4, %3 ]
  %.019 = phi ptr [ %16, %15 ], [ %0, %3 ]
  %.01518 = phi ptr [ %17, %15 ], [ %1, %3 ]
  %6 = sext i8 %5 to i64
  %7 = getelementptr inbounds [256 x ptr], ptr %.019, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %.lr.ph
  %11 = tail call ptr @createNode()
  %12 = load i8, ptr %.01518, align 1, !tbaa !5
  %13 = sext i8 %12 to i64
  %14 = getelementptr inbounds [256 x ptr], ptr %.019, i64 0, i64 %13
  store ptr %11, ptr %14, align 8, !tbaa !8
  %.pre = load i8, ptr %.01518, align 1, !tbaa !5
  %.phi.trans.insert = sext i8 %.pre to i64
  %.phi.trans.insert20 = getelementptr inbounds [256 x ptr], ptr %.019, i64 0, i64 %.phi.trans.insert
  %.pre21 = load ptr, ptr %.phi.trans.insert20, align 8, !tbaa !8
  br label %15

15:                                               ; preds = %10, %.lr.ph
  %16 = phi ptr [ %.pre21, %10 ], [ %8, %.lr.ph ]
  %17 = getelementptr inbounds i8, ptr %.01518, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %15, %3
  %.0.lcssa = phi ptr [ %0, %3 ], [ %16, %15 ]
  %19 = getelementptr inbounds i8, ptr %.0.lcssa, i64 2068
  store i32 1, ptr %19, align 4, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %.0.lcssa, i64 2056
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.0.lcssa, i64 2064
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = shl nsw i64 %25, 2
  %27 = tail call ptr @realloc(ptr noundef %21, i64 noundef %26) #2
  store ptr %27, ptr %20, align 8, !tbaa !15
  %28 = load i32, ptr %22, align 8, !tbaa !16
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %22, align 8, !tbaa !16
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds i32, ptr %27, i64 %30
  store i32 %2, ptr %31, align 4, !tbaa !17
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 allocsize(1) }

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


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