; LLVM IR from tangjz/acm-icpc :: lydsy/3676.ll (ZN14PalindromeTree6appendEc)

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

@_ZN14PalindromeTree1nE = external dso_local global i32, align 4
@_ZN14PalindromeTree4lastE = external dso_local global i32, align 4
@_ZN14PalindromeTree3lenE = external dso_local global [300003 x i32], align 16
@_ZN14PalindromeTree4failE = external dso_local global [300003 x i32], align 16
@_ZN14PalindromeTree3nxtE = external dso_local global [300003 x [26 x i32]], align 16
@_ZN14PalindromeTree3cntE = external dso_local global [300003 x i32], align 16
@_ZN14PalindromeTree3bufE = external dso_local global [300003 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN14PalindromeTree7newNodeEii(i32 noundef, i32 noundef) #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: mustprogress nounwind uwtable
define dso_local void @_ZN14PalindromeTree6appendEc(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
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %6 = load i8, ptr %2, align 1, !tbaa !5
  %7 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %9
  store i8 %6, ptr %10, align 1, !tbaa !5
  %11 = sext i8 %6 to i32
  %12 = sub nsw i32 %11, 97
  store i32 %12, ptr %3, align 4, !tbaa !8
  br label %13

13:                                               ; preds = %32, %1
  %14 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %15 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !8
  %19 = sub nsw i32 %14, %18
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = sext i8 %23 to i32
  %25 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %24, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %13
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !8
  store i32 %36, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  br label %13, !llvm.loop !10

37:                                               ; preds = %13
  %38 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %39
  %41 = load i32, ptr %3, align 4, !tbaa !8
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [26 x i32], ptr %40, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !8
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %99, label %46

46:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %47 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !8
  %51 = add nsw i32 %50, 2
  %52 = call noundef i32 @_ZN14PalindromeTree7newNodeEii(i32 noundef %51, i32 noundef 0)
  store i32 %52, ptr %4, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %53 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !8
  store i32 %56, ptr %5, align 4, !tbaa !8
  br label %57

57:                                               ; preds = %76, %46
  %58 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %59 = load i32, ptr %5, align 4, !tbaa !8
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !8
  %63 = sub nsw i32 %58, %62
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !5
  %68 = sext i8 %67 to i32
  %69 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !8
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !5
  %73 = sext i8 %72 to i32
  %74 = icmp ne i32 %68, %73
  br i1 %74, label %75, label %81

75:                                               ; preds = %57
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %5, align 4, !tbaa !8
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !8
  store i32 %80, ptr %5, align 4, !tbaa !8
  br label %57, !llvm.loop !12

81:                                               ; preds = %57
  %82 = load i32, ptr %5, align 4, !tbaa !8
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %83
  %85 = load i32, ptr %3, align 4, !tbaa !8
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [26 x i32], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !8
  %89 = load i32, ptr %4, align 4, !tbaa !8
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %90
  store i32 %88, ptr %91, align 4, !tbaa !8
  %92 = load i32, ptr %4, align 4, !tbaa !8
  %93 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %94
  %96 = load i32, ptr %3, align 4, !tbaa !8
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [26 x i32], ptr %95, i64 0, i64 %97
  store i32 %92, ptr %98, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %99

99:                                               ; preds = %81, %37
  %100 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %101
  %103 = load i32, ptr %3, align 4, !tbaa !8
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [26 x i32], ptr %102, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !8
  store i32 %106, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %107 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !8
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !8
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %109, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, 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"

@_ZN14PalindromeTree1nE = external dso_local local_unnamed_addr global i32, align 4
@_ZN14PalindromeTree4lastE = external dso_local local_unnamed_addr global i32, align 4
@_ZN14PalindromeTree3lenE = external dso_local local_unnamed_addr global [300003 x i32], align 16
@_ZN14PalindromeTree4failE = external dso_local local_unnamed_addr global [300003 x i32], align 16
@_ZN14PalindromeTree3nxtE = external dso_local local_unnamed_addr global [300003 x [26 x i32]], align 16
@_ZN14PalindromeTree3cntE = external dso_local local_unnamed_addr global [300003 x i32], align 16
@_ZN14PalindromeTree3bufE = external dso_local local_unnamed_addr global [300003 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN14PalindromeTree7newNodeEii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14PalindromeTree6appendEc(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %4
  store i8 %0, ptr %5, align 1, !tbaa !9
  %6 = sext i8 %0 to i64
  %7 = add nsw i64 %6, -97
  %_ZN14PalindromeTree4lastE.promoted = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !5
  %8 = sext i32 %_ZN14PalindromeTree4lastE.promoted to i64
  %9 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sub i32 %2, %10
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not14 = icmp eq i8 %14, %0
  br i1 %.not14, label %25, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %15 = phi i64 [ %18, %.lr.ph ], [ %8, %1 ]
  %16 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sub i32 %2, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %.not = icmp eq i8 %24, %0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph
  store i32 %17, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %._crit_edge, %1
  %26 = phi i32 [ %17, %._crit_edge ], [ %_ZN14PalindromeTree4lastE.promoted, %1 ]
  %.lcssa13 = phi i64 [ %18, %._crit_edge ], [ %8, %1 ]
  %.lcssa12 = phi i32 [ %20, %._crit_edge ], [ %10, %1 ]
  %27 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %.lcssa13, i64 %7
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %.not10 = icmp eq i32 %28, 0
  br i1 %.not10, label %29, label %._crit_edge20

._crit_edge20:                                    ; preds = %25
  %.phi.trans.insert = sext i32 %26 to i64
  %.phi.trans.insert21 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %.phi.trans.insert, i64 %7
  %.pre = load i32, ptr %.phi.trans.insert21, align 4, !tbaa !5
  %.pre22 = sext i32 %.pre to i64
  br label %53

29:                                               ; preds = %25
  %30 = add nsw i32 %.lcssa12, 2
  %31 = tail call noundef i32 @_ZN14PalindromeTree7newNodeEii(i32 noundef %30, i32 noundef 0)
  %32 = load i32, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = load i32, ptr @_ZN14PalindromeTree1nE, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  br label %38

38:                                               ; preds = %38, %29
  %.pn = phi i64 [ %33, %29 ], [ %39, %38 ]
  %.0.in = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %.pn
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !5
  %39 = sext i32 %.0 to i64
  %40 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = xor i32 %41, -1
  %43 = add i32 %34, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [300003 x i8], ptr @_ZN14PalindromeTree3bufE, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %.not11 = icmp eq i8 %46, %37
  br i1 %.not11, label %47, label %38, !llvm.loop !12

47:                                               ; preds = %38
  %48 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %39, i64 %7
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %31 to i64
  %51 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %50
  store i32 %49, ptr %51, align 4, !tbaa !5
  %52 = getelementptr inbounds [300003 x [26 x i32]], ptr @_ZN14PalindromeTree3nxtE, i64 0, i64 %33, i64 %7
  store i32 %31, ptr %52, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %._crit_edge20, %47
  %.pre-phi = phi i64 [ %.pre22, %._crit_edge20 ], [ %50, %47 ]
  %54 = phi i32 [ %.pre, %._crit_edge20 ], [ %31, %47 ]
  store i32 %54, ptr @_ZN14PalindromeTree4lastE, align 4, !tbaa !5
  %55 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %.pre-phi
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !5
  ret void
}

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

!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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass