; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法 (双端回文自动机)

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

@ans = external dso_local global i64, align 8
@tree = external dso_local global %struct.Palindromic_Tree, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  br label %6

6:                                                ; preds = %44, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %45

9:                                                ; preds = %6
  call void @_ZN16Palindromic_Tree4initEv(ptr noundef nonnull align 4 dereferenceable(37201260) @tree)
  store i64 0, ptr @ans, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %43, %9
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %2, align 4, !tbaa !9
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %44

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %23

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %20 = load i8, ptr %4, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = sub nsw i32 %21, 97
  call void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260) @tree, i32 noundef %22, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  br label %43

23:                                               ; preds = %14
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %28 = load i8, ptr %5, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = sub nsw i32 %29, 97
  call void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260) @tree, i32 noundef %30, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  br label %42

31:                                               ; preds = %23
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 3
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = load i32, ptr getelementptr inbounds (%struct.Palindromic_Tree, ptr @tree, i32 0, i32 7), align 4, !tbaa !12
  %36 = sub nsw i32 %35, 1
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %36)
  br label %41

38:                                               ; preds = %31
  %39 = load i64, ptr @ans, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %39)
  br label %41

41:                                               ; preds = %38, %34
  br label %42

42:                                               ; preds = %41, %26
  br label %43

43:                                               ; preds = %42, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %10, !llvm.loop !14

44:                                               ; preds = %10
  br label %6, !llvm.loop !16

45:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %46 = load i32, ptr %1, align 4
  ret i32 %46
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16Palindromic_Tree4initEv(ptr noundef nonnull align 4 dereferenceable(37201260)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260), i32 noundef, i32 noundef) #4 align 2

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { mustprogress 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 37201248}
!13 = !{!"_ZTS16Palindromic_Tree", !7, i64 0, !7, i64 31201040, !7, i64 32401080, !7, i64 33601120, !7, i64 34801160, !7, i64 36001200, !7, i64 37201240, !10, i64 37201248, !10, i64 37201252, !10, i64 37201256}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@ans = external dso_local local_unnamed_addr global i64, align 8
@tree = external dso_local global %struct.Palindromic_Tree, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %.lr.ph2, label %._crit_edge

.loopexit:                                        ; preds = %30, %.lr.ph2
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %.lr.ph2, label %._crit_edge, !llvm.loop !5

.lr.ph2:                                          ; preds = %0, %.loopexit
  call void @_ZN16Palindromic_Tree4initEv(ptr noundef nonnull align 4 dereferenceable(37201260) @tree)
  store i64 0, ptr @ans, align 8, !tbaa !7
  %9 = load i32, ptr %1, align 4, !tbaa !11
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %1, align 4, !tbaa !11
  %.not1 = icmp eq i32 %9, 0
  br i1 %.not1, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph2, %30
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %12 = load i32, ptr %2, align 4, !tbaa !11
  switch i32 %12, label %27 [
    i32 1, label %13
    i32 2, label %18
    i32 3, label %23
  ]

13:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %15 = load i8, ptr %3, align 1, !tbaa !13
  %16 = sext i8 %15 to i32
  %17 = add nsw i32 %16, -97
  call void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260) @tree, i32 noundef %17, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  br label %30

18:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #5
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4)
  %20 = load i8, ptr %4, align 1, !tbaa !13
  %21 = sext i8 %20 to i32
  %22 = add nsw i32 %21, -97
  call void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260) @tree, i32 noundef %22, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #5
  br label %30

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @tree, i64 37201248), align 4, !tbaa !14
  %25 = add nsw i32 %24, -1
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %25)
  br label %30

27:                                               ; preds = %.lr.ph
  %28 = load i64, ptr @ans, align 8, !tbaa !7
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %28)
  br label %30

30:                                               ; preds = %18, %27, %23, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %31 = load i32, ptr %1, align 4, !tbaa !11
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %1, align 4, !tbaa !11
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16Palindromic_Tree4initEv(ptr noundef nonnull align 4 dereferenceable(37201260)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN16Palindromic_Tree6insertEii(ptr noundef nonnull align 4 dereferenceable(37201260), i32 noundef, i32 noundef) local_unnamed_addr #4 align 2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { mustprogress 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !12, i64 37201248}
!15 = !{!"_ZTS16Palindromic_Tree", !9, i64 0, !9, i64 31201040, !9, i64 32401080, !9, i64 33601120, !9, i64 34801160, !9, i64 36001200, !9, i64 37201240, !12, i64 37201248, !12, i64 37201252, !12, i64 37201256}
!16 = distinct !{!16, !6}


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