; LLVM IR from tangjz/acm-icpc :: luogu (2305)

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

7:                                                ; preds = %17, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i64, ptr @a, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15)
  br label %17

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %21

21:                                               ; preds = %83, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %45, %26
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = icmp sgt i64 %33, %37
  br i1 %38, label %39, label %43

39:                                               ; preds = %29
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = icmp sle i32 %40, %41
  br label %43

43:                                               ; preds = %39, %29
  %44 = phi i1 [ false, %29 ], [ %42, %39 ]
  br i1 %44, label %45, label %58

45:                                               ; preds = %43
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = add nsw i64 %54, %50
  store i64 %55, ptr %53, align 8, !tbaa !11
  %56 = load i32, ptr @ans, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr @ans, align 4, !tbaa !5
  br label %29, !llvm.loop !13

58:                                               ; preds = %43
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !11
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = icmp sgt i64 %62, %66
  br i1 %67, label %68, label %80

68:                                               ; preds = %58
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !11
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !11
  %77 = add nsw i64 %76, %72
  store i64 %77, ptr %75, align 8, !tbaa !11
  %78 = load i32, ptr @ans, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr @ans, align 4, !tbaa !5
  br label %82

80:                                               ; preds = %58
  %81 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %81, ptr %4, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %80, %68
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %84, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !14

85:                                               ; preds = %25
  %86 = load i32, ptr @ans, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %86)
  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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; 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
@ans = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [200010 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = 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)
  %2 = load i32, ptr @n, align 4
  %.not28 = icmp slt i32 %2, 1
  br i1 %.not28, label %.preheader23.thread, label %.lr.ph

.preheader23.thread:                              ; preds = %0
  %ans.promoted4060 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge48

.preheader23:                                     ; preds = %.lr.ph
  %ans.promoted40 = load i32, ptr @ans, align 4, !tbaa !5
  %.not2244 = icmp slt i32 %6, 1
  br i1 %.not2244, label %._crit_edge48, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader23
  %3 = zext nneg i32 %6 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %4 = getelementptr inbounds i64, ptr @a, i64 %indvars.iv
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i32, ptr @n, align 4
  %7 = sext i32 %6 to i64
  %.not.not = icmp slt i64 %indvars.iv, %7
  br i1 %.not.not, label %.lr.ph, label %.preheader23, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %35
  %.01647 = phi i32 [ %.1, %35 ], [ 0, %.preheader.preheader ]
  %.01746 = phi i32 [ %.0.lcssa63, %35 ], [ 1, %.preheader.preheader ]
  %.lcssa394345 = phi i32 [ %.lcssa3941, %35 ], [ %ans.promoted40, %.preheader.preheader ]
  %8 = sext i32 %.01647 to i64
  %9 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %8
  %10 = sext i32 %.01746 to i64
  %11 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %10
  %12 = load i64, ptr %9, align 8, !tbaa !11
  %13 = load i64, ptr %11, align 8, !tbaa !11
  %14 = icmp sgt i64 %12, %13
  %15 = icmp slt i32 %.01746, %6
  %16 = and i1 %14, %15
  br i1 %16, label %.lr.ph33.preheader, label %31

.lr.ph33.preheader:                               ; preds = %.preheader
  %17 = add nsw i64 %10, 1
  br label %.lr.ph33

._crit_edge48:                                    ; preds = %35, %.preheader23.thread, %.preheader23
  %18 = phi i32 [ %ans.promoted40, %.preheader23 ], [ %ans.promoted4060, %.preheader23.thread ], [ %.lcssa3941, %35 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %18)
  ret i32 0

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %indvars.iv56 = phi i64 [ %17, %.lr.ph33.preheader ], [ %indvars.iv.next57, %.lr.ph33 ]
  %20 = phi i64 [ %13, %.lr.ph33.preheader ], [ %24, %.lr.ph33 ]
  %21 = phi i32 [ %.lcssa394345, %.lr.ph33.preheader ], [ %25, %.lr.ph33 ]
  %22 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %indvars.iv56
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = add nsw i64 %23, %20
  store i64 %24, ptr %11, align 8, !tbaa !11
  %25 = add nsw i32 %21, 1
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, 1
  %26 = load i64, ptr %9, align 8, !tbaa !11
  %27 = icmp sgt i64 %26, %24
  %28 = icmp slt i64 %indvars.iv56, %3
  %29 = and i1 %27, %28
  br i1 %29, label %.lr.ph33, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph33
  %30 = trunc nsw i64 %indvars.iv.next57 to i32
  store i32 %25, ptr @ans, align 4, !tbaa !5
  br i1 %27, label %32, label %35

31:                                               ; preds = %.preheader
  %.031 = add nsw i32 %.01746, 1
  br i1 %14, label %32, label %35

32:                                               ; preds = %._crit_edge, %31
  %.lcssa2466 = phi i64 [ %24, %._crit_edge ], [ %13, %31 ]
  %.lcssa2565 = phi i64 [ %26, %._crit_edge ], [ %12, %31 ]
  %.0.lcssa64 = phi i32 [ %30, %._crit_edge ], [ %.031, %31 ]
  %.lcssa394262 = phi i32 [ %25, %._crit_edge ], [ %.lcssa394345, %31 ]
  %33 = add nsw i64 %.lcssa2466, %.lcssa2565
  store i64 %33, ptr %9, align 8, !tbaa !11
  %34 = add nsw i32 %.lcssa394262, 1
  store i32 %34, ptr @ans, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %._crit_edge, %31, %32
  %.0.lcssa63 = phi i32 [ %.0.lcssa64, %32 ], [ %.031, %31 ], [ %30, %._crit_edge ]
  %.lcssa3941 = phi i32 [ %34, %32 ], [ %.lcssa394345, %31 ], [ %25, %._crit_edge ]
  %.1 = phi i32 [ %.01647, %32 ], [ %.01746, %31 ], [ %.01746, %._crit_edge ]
  %.not22 = icmp sgt i32 %.0.lcssa63, %6
  br i1 %.not22, label %._crit_edge48, label %.preheader, !llvm.loop !14
}

; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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