; LLVM IR from tangjz/acm-icpc :: lydsy (1355)

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

@n = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i32], align 16
@s = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @s)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %5

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

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

10:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %3, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %32, %10
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %30

18:                                               ; preds = %15
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %23, %28
  br label %30

30:                                               ; preds = %18, %15
  %31 = phi i1 [ false, %15 ], [ %29, %18 ]
  br i1 %31, label %32, label %37

32:                                               ; preds = %30
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4, !tbaa !5
  br label %15, !llvm.loop !10

37:                                               ; preds = %30
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %42, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %37
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !5
  br label %56

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

57:                                               ; preds = %56
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !12

60:                                               ; preds = %9
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = sub nsw i32 %61, %65
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %66)
  ret i32 0
}

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

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

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

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

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 = { "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 #2 = { nocallback nofree nosync 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 = !{!"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"

@n = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@s = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @s)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %2 to i64
  %.pre16 = load i8, ptr @s, align 16
  br label %.lr.ph

._crit_edge:                                      ; preds = %19, %0
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sub nsw i32 %2, %6
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %7)
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.pre-phi, %19 ]
  %9 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %indvars.iv
  %.pre.pre = load i8, ptr %9, align 1, !tbaa !9
  br label %10

10:                                               ; preds = %11, %.lr.ph
  %.pn = phi i64 [ %indvars.iv, %.lr.ph ], [ %12, %11 ]
  %.0.in = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %.pn
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.critedge, label %11

11:                                               ; preds = %10
  %12 = sext i32 %.0 to i64
  %13 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not13 = icmp eq i8 %.pre.pre, %14
  br i1 %.not13, label %.critedge.thread, label %10, !llvm.loop !10

.critedge:                                        ; preds = %10
  %15 = icmp eq i8 %.pre.pre, %.pre16
  br i1 %15, label %.critedge.thread, label %.critedge._crit_edge

.critedge._crit_edge:                             ; preds = %.critedge
  %.pre = add nuw nsw i64 %indvars.iv, 1
  br label %19

.critedge.thread:                                 ; preds = %11, %.critedge
  %16 = add nsw i32 %.0, 1
  %17 = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %17
  store i32 %16, ptr %18, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.critedge._crit_edge, %.critedge.thread
  %indvars.iv.next.pre-phi = phi i64 [ %.pre, %.critedge._crit_edge ], [ %17, %.critedge.thread ]
  %exitcond.not = icmp eq i64 %indvars.iv.next.pre-phi, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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" }

!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,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass