; LLVM IR from lzyrapx/Competitive-Programming :: 51Nod/1089（manacher）.ll (Z8manacherv)

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

@l = external dso_local global i32, align 4
@p = external dso_local global [2000010 x i32], align 16
@S = external dso_local global [2000010 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

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

6:                                                ; preds = %109, %0
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr @l, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %112

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = add nsw i32 %12, %13
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %17, label %34

17:                                               ; preds = %11
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = mul nsw i32 %18, 2
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sub nsw i32 %19, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sub nsw i32 %26, %27
  store i32 %28, ptr %5, align 4, !tbaa !5
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %23, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %32
  store i32 %30, ptr %33, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %34

34:                                               ; preds = %17, %11
  br label %35

35:                                               ; preds = %80, %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sub nsw i32 %36, %40
  %42 = sub nsw i32 %41, 1
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %44, label %78

44:                                               ; preds = %35
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %45, %49
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr @l, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %54, label %78

54:                                               ; preds = %44
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sub nsw i32 %55, %59
  %61 = sub nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2000010 x i8], ptr @S, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !9
  %65 = sext i8 %64 to i32
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = add nsw i32 %66, %70
  %72 = add nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [2000010 x i8], ptr @S, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !9
  %76 = sext i8 %75 to i32
  %77 = icmp eq i32 %65, %76
  br label %78

78:                                               ; preds = %54, %44, %35
  %79 = phi i1 [ false, %44 ], [ false, %35 ], [ %77, %54 ]
  br i1 %79, label %80, label %86

80:                                               ; preds = %78
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %83, align 4, !tbaa !5
  br label %35, !llvm.loop !10

86:                                               ; preds = %78
  %87 = load i32, ptr %2, align 4, !tbaa !5
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = add nsw i32 %90, %94
  %96 = icmp slt i32 %89, %95
  br i1 %96, label %97, label %103

97:                                               ; preds = %86
  %98 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %98, ptr %2, align 4, !tbaa !5
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  store i32 %102, ptr %3, align 4, !tbaa !5
  br label %103

103:                                              ; preds = %97, %86
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %105
  %107 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %106)
  %108 = load i32, ptr %107, align 4, !tbaa !5
  store i32 %108, ptr %1, align 4, !tbaa !5
  br label %109

109:                                              ; preds = %103
  %110 = load i32, ptr %4, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %4, align 4, !tbaa !5
  br label %6, !llvm.loop !12

112:                                              ; preds = %10
  %113 = load i32, ptr %1, align 4, !tbaa !5
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %113)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@l = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local global [2000010 x i32], align 16
@S = external dso_local local_unnamed_addr global [2000010 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8manacherv() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  %3 = load i32, ptr @l, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 1
  br i1 %4, label %.lr.ph45, label %._crit_edge

._crit_edge:                                      ; preds = %.critedge, %0
  %5 = phi i32 [ 0, %0 ], [ %46, %.critedge ]
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void

.lr.ph45:                                         ; preds = %0, %.critedge
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %.critedge ], [ 1, %0 ]
  %.02743 = phi i32 [ %spec.select33, %.critedge ], [ -1, %0 ]
  %.02842 = phi i32 [ %spec.select, %.critedge ], [ 0, %0 ]
  %indvars49 = trunc i64 %indvars.iv47 to i32
  %7 = add nsw i32 %.02743, %.02842
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %indvars.iv47, %8
  br i1 %9, label %10, label %.lr.ph45._crit_edge

.lr.ph45._crit_edge:                              ; preds = %.lr.ph45
  %.phi.trans.insert = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %indvars.iv47
  %.promoted.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %19

10:                                               ; preds = %.lr.ph45
  %11 = shl nsw i32 %.02842, 1
  %12 = sext i32 %11 to i64
  %13 = sub nsw i64 %12, %indvars.iv47
  %14 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %15 = sub nsw i32 %7, %indvars49
  store i32 %15, ptr %2, align 4, !tbaa !5
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %indvars.iv47
  store i32 %17, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %19

19:                                               ; preds = %.lr.ph45._crit_edge, %10
  %.promoted = phi i32 [ %.promoted.pre, %.lr.ph45._crit_edge ], [ %17, %10 ]
  %20 = getelementptr inbounds [2000010 x i32], ptr @p, i64 0, i64 %indvars.iv47
  %21 = xor i32 %.promoted, -1
  %22 = add i32 %indvars49, %21
  %23 = icmp sgt i32 %22, -1
  br i1 %23, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %19
  %24 = load i32, ptr @l, align 4, !tbaa !5
  %25 = sext i32 %.promoted to i64
  %26 = sext i32 %24 to i64
  br label %27

27:                                               ; preds = %.lr.ph, %39
  %indvars.iv = phi i64 [ %25, %.lr.ph ], [ %indvars.iv.next, %39 ]
  %28 = phi i32 [ %22, %.lr.ph ], [ %41, %39 ]
  %29 = add nsw i64 %indvars.iv, %indvars.iv47
  %.not.not = icmp slt i64 %29, %26
  %30 = trunc nsw i64 %indvars.iv to i32
  br i1 %.not.not, label %31, label %.critedge

31:                                               ; preds = %27
  %32 = add nsw i64 %29, 1
  %33 = zext nneg i32 %28 to i64
  %34 = getelementptr inbounds [2000010 x i8], ptr @S, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = getelementptr inbounds [2000010 x i8], ptr @S, i64 0, i64 %32
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = icmp eq i8 %35, %37
  br i1 %38, label %39, label %.critedge

39:                                               ; preds = %31
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %40 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %40, ptr %20, align 4, !tbaa !5
  %reass.sub = sub i32 %indvars49, %30
  %41 = add i32 %reass.sub, -2
  %42 = icmp sgt i32 %41, -1
  br i1 %42, label %27, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %31, %39, %27, %19
  %.lcssa = phi i32 [ %.promoted, %19 ], [ %30, %27 ], [ %indvars49, %39 ], [ %30, %31 ]
  %43 = add nsw i32 %.lcssa, %indvars49
  %44 = icmp slt i32 %7, %43
  %spec.select = select i1 %44, i32 %indvars49, i32 %.02842
  %spec.select33 = select i1 %44, i32 %.lcssa, i32 %.02743
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %20)
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %1, align 4, !tbaa !5
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %47 = load i32, ptr @l, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = icmp slt i64 %indvars.iv.next48, %48
  br i1 %49, label %.lr.ph45, label %._crit_edge, !llvm.loop !12
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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 = { inlinehint 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass