; LLVM IR from AlgoGenesis/C :: Miscellaneous Algorithms/Suffix Atomation (Suffix)

; 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.State = type { i32, i32, [26 x i32] }

@stateCount = external dso_local global i32, align 4
@lastState = external dso_local global i32, align 4
@states = external dso_local global [2000 x %struct.State], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @initState(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @extend(i8 noundef signext %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = load i32, ptr @stateCount, align 4, !tbaa !8
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @stateCount, align 4, !tbaa !8
  store i32 %7, ptr %3, align 4, !tbaa !8
  %9 = load i32, ptr %3, align 4, !tbaa !8
  call void @initState(i32 noundef %9)
  %10 = load i32, ptr @lastState, align 4, !tbaa !8
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.State, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 16, !tbaa !10
  %15 = add nsw i32 %14, 1
  %16 = load i32, ptr %3, align 4, !tbaa !8
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.State, ptr %18, i32 0, i32 0
  store i32 %15, ptr %19, align 16, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %20 = load i32, ptr @lastState, align 4, !tbaa !8
  store i32 %20, ptr %4, align 4, !tbaa !8
  br label %21

21:                                               ; preds = %38, %1
  %22 = load i32, ptr %4, align 4, !tbaa !8
  %23 = icmp ne i32 %22, -1
  br i1 %23, label %24, label %36

24:                                               ; preds = %21
  %25 = load i32, ptr %4, align 4, !tbaa !8
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.State, ptr %27, i32 0, i32 2
  %29 = load i8, ptr %2, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = sub nsw i32 %30, 97
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [26 x i32], ptr %28, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !8
  %35 = icmp eq i32 %34, -1
  br label %36

36:                                               ; preds = %24, %21
  %37 = phi i1 [ false, %21 ], [ %35, %24 ]
  br i1 %37, label %38, label %54

38:                                               ; preds = %36
  %39 = load i32, ptr %3, align 4, !tbaa !8
  %40 = load i32, ptr %4, align 4, !tbaa !8
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.State, ptr %42, i32 0, i32 2
  %44 = load i8, ptr %2, align 1, !tbaa !5
  %45 = sext i8 %44 to i32
  %46 = sub nsw i32 %45, 97
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [26 x i32], ptr %43, i64 0, i64 %47
  store i32 %39, ptr %48, align 4, !tbaa !8
  %49 = load i32, ptr %4, align 4, !tbaa !8
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.State, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !12
  store i32 %53, ptr %4, align 4, !tbaa !8
  br label %21, !llvm.loop !13

54:                                               ; preds = %36
  %55 = load i32, ptr %4, align 4, !tbaa !8
  %56 = icmp eq i32 %55, -1
  br i1 %56, label %57, label %62

57:                                               ; preds = %54
  %58 = load i32, ptr %3, align 4, !tbaa !8
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.State, ptr %60, i32 0, i32 1
  store i32 0, ptr %61, align 4, !tbaa !12
  br label %155

62:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %63 = load i32, ptr %4, align 4, !tbaa !8
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.State, ptr %65, i32 0, i32 2
  %67 = load i8, ptr %2, align 1, !tbaa !5
  %68 = sext i8 %67 to i32
  %69 = sub nsw i32 %68, 97
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [26 x i32], ptr %66, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !8
  store i32 %72, ptr %5, align 4, !tbaa !8
  %73 = load i32, ptr %4, align 4, !tbaa !8
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.State, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 16, !tbaa !10
  %78 = add nsw i32 %77, 1
  %79 = load i32, ptr %5, align 4, !tbaa !8
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.State, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 16, !tbaa !10
  %84 = icmp eq i32 %78, %83
  br i1 %84, label %85, label %91

85:                                               ; preds = %62
  %86 = load i32, ptr %5, align 4, !tbaa !8
  %87 = load i32, ptr %3, align 4, !tbaa !8
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %88
  %90 = getelementptr inbounds %struct.State, ptr %89, i32 0, i32 1
  store i32 %86, ptr %90, align 4, !tbaa !12
  br label %154

91:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %92 = load i32, ptr @stateCount, align 4, !tbaa !8
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr @stateCount, align 4, !tbaa !8
  store i32 %92, ptr %6, align 4, !tbaa !8
  %94 = load i32, ptr %6, align 4, !tbaa !8
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %95
  %97 = load i32, ptr %5, align 4, !tbaa !8
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %98
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %96, ptr align 16 %99, i64 112, i1 false), !tbaa.struct !15
  %100 = load i32, ptr %4, align 4, !tbaa !8
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %101
  %103 = getelementptr inbounds %struct.State, ptr %102, i32 0, i32 0
  %104 = load i32, ptr %103, align 16, !tbaa !10
  %105 = add nsw i32 %104, 1
  %106 = load i32, ptr %6, align 4, !tbaa !8
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %107
  %109 = getelementptr inbounds %struct.State, ptr %108, i32 0, i32 0
  store i32 %105, ptr %109, align 16, !tbaa !10
  br label %110

110:                                              ; preds = %128, %91
  %111 = load i32, ptr %4, align 4, !tbaa !8
  %112 = icmp ne i32 %111, -1
  br i1 %112, label %113, label %126

113:                                              ; preds = %110
  %114 = load i32, ptr %4, align 4, !tbaa !8
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %115
  %117 = getelementptr inbounds %struct.State, ptr %116, i32 0, i32 2
  %118 = load i8, ptr %2, align 1, !tbaa !5
  %119 = sext i8 %118 to i32
  %120 = sub nsw i32 %119, 97
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [26 x i32], ptr %117, i64 0, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !8
  %124 = load i32, ptr %5, align 4, !tbaa !8
  %125 = icmp eq i32 %123, %124
  br label %126

126:                                              ; preds = %113, %110
  %127 = phi i1 [ false, %110 ], [ %125, %113 ]
  br i1 %127, label %128, label %144

128:                                              ; preds = %126
  %129 = load i32, ptr %6, align 4, !tbaa !8
  %130 = load i32, ptr %4, align 4, !tbaa !8
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %131
  %133 = getelementptr inbounds %struct.State, ptr %132, i32 0, i32 2
  %134 = load i8, ptr %2, align 1, !tbaa !5
  %135 = sext i8 %134 to i32
  %136 = sub nsw i32 %135, 97
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds [26 x i32], ptr %133, i64 0, i64 %137
  store i32 %129, ptr %138, align 4, !tbaa !8
  %139 = load i32, ptr %4, align 4, !tbaa !8
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %140
  %142 = getelementptr inbounds %struct.State, ptr %141, i32 0, i32 1
  %143 = load i32, ptr %142, align 4, !tbaa !12
  store i32 %143, ptr %4, align 4, !tbaa !8
  br label %110, !llvm.loop !16

144:                                              ; preds = %126
  %145 = load i32, ptr %6, align 4, !tbaa !8
  %146 = load i32, ptr %3, align 4, !tbaa !8
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %147
  %149 = getelementptr inbounds %struct.State, ptr %148, i32 0, i32 1
  store i32 %145, ptr %149, align 4, !tbaa !12
  %150 = load i32, ptr %5, align 4, !tbaa !8
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %151
  %153 = getelementptr inbounds %struct.State, ptr %152, i32 0, i32 1
  store i32 %145, ptr %153, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %154

154:                                              ; preds = %144, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %155

155:                                              ; preds = %154, %57
  %156 = load i32, ptr %3, align 4, !tbaa !8
  store i32 %156, ptr @lastState, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"State", !9, i64 0, !9, i64 4, !6, i64 8}
!12 = !{!11, !9, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 4, !8, i64 4, i64 4, !8, i64 8, i64 104, !5}
!16 = distinct !{!16, !14}


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

%struct.State = type { i32, i32, [26 x i32] }

@stateCount = external dso_local local_unnamed_addr global i32, align 4
@lastState = external dso_local local_unnamed_addr global i32, align 4
@states = external dso_local local_unnamed_addr global [2000 x %struct.State], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @initState(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @extend(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @stateCount, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @stateCount, align 4, !tbaa !5
  tail call void @initState(i32 noundef %2)
  %4 = load i32, ptr @lastState, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %5
  %7 = load i32, ptr %6, align 16, !tbaa !9
  %8 = add nsw i32 %7, 1
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %9
  store i32 %8, ptr %10, align 16, !tbaa !9
  %cond40 = icmp eq i32 %4, -1
  br i1 %cond40, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %11 = sext i8 %0 to i64
  %12 = add nsw i64 %11, -97
  br label %13

13:                                               ; preds = %.lr.ph, %20
  %.041 = phi i32 [ %4, %.lr.ph ], [ %.0, %20 ]
  %14 = sext i32 %.041 to i64
  %15 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = getelementptr inbounds [26 x i32], ptr %16, i64 0, i64 %12
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %.critedge

20:                                               ; preds = %13
  store i32 %2, ptr %17, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %15, i64 4
  %.0 = load i32, ptr %21, align 4, !tbaa !5
  %cond = icmp eq i32 %.0, -1
  br i1 %cond, label %._crit_edge, label %13, !llvm.loop !11

.critedge:                                        ; preds = %13
  %22 = load i32, ptr %15, align 16, !tbaa !9
  %23 = add nsw i32 %22, 1
  %24 = sext i32 %18 to i64
  %25 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %24
  %26 = load i32, ptr %25, align 16, !tbaa !9
  %27 = icmp eq i32 %23, %26
  br i1 %27, label %._crit_edge, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %.critedge
  %28 = load i32, ptr @stateCount, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @stateCount, align 4, !tbaa !5
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %30
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(112) %31, ptr noundef nonnull align 16 dereferenceable(112) %25, i64 112, i1 false), !tbaa.struct !13
  %32 = load i32, ptr %15, align 16, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 16, !tbaa !9
  br label %.lr.ph45

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %40
  %.143 = phi i32 [ %42, %40 ], [ %.041, %.lr.ph45.preheader ]
  %34 = sext i32 %.143 to i64
  %35 = getelementptr inbounds [2000 x %struct.State], ptr @states, i64 0, i64 %34
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = getelementptr inbounds [26 x i32], ptr %36, i64 0, i64 %12
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp eq i32 %38, %18
  br i1 %39, label %40, label %.critedge2

40:                                               ; preds = %.lr.ph45
  store i32 %28, ptr %37, align 4, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %35, i64 4
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %.not35 = icmp eq i32 %42, -1
  br i1 %.not35, label %.critedge2, label %.lr.ph45, !llvm.loop !16

.critedge2:                                       ; preds = %.lr.ph45, %40
  %43 = getelementptr inbounds i8, ptr %10, i64 4
  store i32 %28, ptr %43, align 4, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %20, %.critedge, %1, %.critedge2
  %.sink55 = phi ptr [ %25, %.critedge2 ], [ %10, %1 ], [ %10, %.critedge ], [ %10, %20 ]
  %.lcssa.sink = phi i32 [ %28, %.critedge2 ], [ 0, %1 ], [ %18, %.critedge ], [ 0, %20 ]
  %44 = getelementptr inbounds i8, ptr %.sink55, i64 4
  store i32 %.lcssa.sink, ptr %44, align 4, !tbaa !15
  store i32 %2, ptr @lastState, align 4, !tbaa !5
  ret void
}

; 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) #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }

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


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