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

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

@_ZN14PalindromeTree3totE = 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
@_ZN14PalindromeTree3cntE = external dso_local global [300003 x i32], align 16
@_ZZN14PalindromeTree5solveEvE3str = external hidden global [300003 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN14PalindromeTree4initEv() #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
declare dso_local void @_ZN14PalindromeTree6appendEc(i8 noundef signext) #0

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

6:                                                ; preds = %18, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [300003 x i8], ptr @_ZZN14PalindromeTree5solveEvE3str, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  br label %21

13:                                               ; preds = %6
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [300003 x i8], ptr @_ZZN14PalindromeTree5solveEvE3str, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  call void @_ZN14PalindromeTree6appendEc(i8 noundef signext %17)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !10

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 0, ptr %2, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %22 = load i32, ptr @_ZN14PalindromeTree3totE, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %53, %21
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %56

27:                                               ; preds = %23
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, %31
  store i32 %39, ptr %37, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %44, %49
  store i64 %50, ptr %4, align 8, !tbaa !12
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %52 = load i64, ptr %51, align 8, !tbaa !12
  store i64 %52, ptr %2, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %53

53:                                               ; preds = %27
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !14

56:                                               ; preds = %26
  %57 = load i64, ptr %2, align 8, !tbaa !12
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %57)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  ret void
}

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

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

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { 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 #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 = !{!"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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !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"

@_ZN14PalindromeTree3totE = 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
@_ZN14PalindromeTree3cntE = external dso_local local_unnamed_addr global [300003 x i32], align 16
@_ZZN14PalindromeTree5solveEvE3str = external hidden global [300003 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN14PalindromeTree4initEv() local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN14PalindromeTree6appendEc(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14PalindromeTree5solveEv() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @_ZZN14PalindromeTree5solveEvE3str)
  tail call void @_ZN14PalindromeTree4initEv()
  %4 = load i8, ptr @_ZZN14PalindromeTree5solveEvE3str, align 16, !tbaa !5
  %.not12 = icmp eq i8 %4, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store i64 0, ptr %1, align 8, !tbaa !8
  %5 = load i32, ptr @_ZN14PalindromeTree3totE, align 4, !tbaa !10
  %.not1114 = icmp eq i32 %5, 0
  br i1 %.not1114, label %._crit_edge18, label %.lr.ph17.preheader

.lr.ph17.preheader:                               ; preds = %._crit_edge
  %6 = sext i32 %5 to i64
  br label %.lr.ph17

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %7 = phi i8 [ %9, %.lr.ph ], [ %4, %0 ]
  tail call void @_ZN14PalindromeTree6appendEc(i8 noundef signext %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds [300003 x i8], ptr @_ZZN14PalindromeTree5solveEvE3str, i64 0, i64 %indvars.iv.next
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge
  %10 = phi i64 [ 0, %._crit_edge ], [ %27, %.lr.ph17 ]
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %.lr.ph17
  %indvars.iv19 = phi i64 [ %6, %.lr.ph17.preheader ], [ %indvars.iv.next20, %.lr.ph17 ]
  %12 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %indvars.iv19
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree4failE, i64 0, i64 %indvars.iv19
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3cntE, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !10
  %19 = add nsw i32 %18, %13
  store i32 %19, ptr %17, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %20 = getelementptr inbounds [300003 x i32], ptr @_ZN14PalindromeTree3lenE, i64 0, i64 %indvars.iv19
  %21 = load i32, ptr %20, align 4, !tbaa !10
  %22 = sext i32 %21 to i64
  %23 = load i32, ptr %12, align 4, !tbaa !10
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %24, %22
  store i64 %25, ptr %2, align 8, !tbaa !8
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %27 = load i64, ptr %26, align 8, !tbaa !8
  store i64 %27, ptr %1, align 8, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %indvars.iv.next20 = add nsw i64 %indvars.iv19, -1
  %.not11 = icmp eq i64 %indvars.iv.next20, 0
  br i1 %.not11, label %._crit_edge18, label %.lr.ph17, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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

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


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