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

; 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
@seq = external dso_local global [80002 x i32], align 16
@stack = external dso_local global [80002 x i32], align 16
@top = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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)
  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 = %15, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sle 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 %18

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %9
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %21
  store i32 2147483647, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr @top, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @top, align 4, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %27
  store i32 %24, ptr %28, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %29 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %29, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %74, %18
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp sge i32 %31, 1
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %77

34:                                               ; preds = %30
  br label %35

35:                                               ; preds = %54, %34
  %36 = load i32, ptr @top, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %52

38:                                               ; preds = %35
  %39 = load i32, ptr @top, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp slt i32 %46, %50
  br label %52

52:                                               ; preds = %38, %35
  %53 = phi i1 [ false, %35 ], [ %51, %38 ]
  br i1 %53, label %54, label %57

54:                                               ; preds = %52
  %55 = load i32, ptr @top, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr @top, align 4, !tbaa !5
  br label %35, !llvm.loop !11

57:                                               ; preds = %52
  %58 = load i32, ptr @top, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sub nsw i32 %62, %63
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr @ans, align 8, !tbaa !12
  %68 = add nsw i64 %67, %66
  store i64 %68, ptr @ans, align 8, !tbaa !12
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = load i32, ptr @top, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr @top, align 4, !tbaa !5
  %72 = sext i32 %70 to i64
  %73 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %57
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !14

77:                                               ; preds = %33
  %78 = load i64, ptr @ans, align 8, !tbaa !12
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %78)
  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 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!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
@seq = external dso_local global [80002 x i32], align 16
@stack = external dso_local local_unnamed_addr global [80002 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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, !tbaa !5
  %.not13 = icmp slt i32 %2, 1
  br i1 %.not13, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa12 = phi i32 [ %2, %0 ], [ %14, %.lr.ph ]
  %3 = add nsw i32 %.lcssa12, 1
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %4
  store i32 2147483647, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @top, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @top, align 4, !tbaa !5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %8
  store i32 %3, ptr %9, align 4, !tbaa !5
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  %10 = icmp sgt i32 %.lcssa12, 0
  br i1 %10, label %thread-pre-split.preheader, label %16

thread-pre-split.preheader:                       ; preds = %._crit_edge
  %11 = zext nneg i32 %.lcssa12 to i64
  br label %thread-pre-split

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %12 = getelementptr inbounds i32, ptr @seq, i64 %indvars.iv
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %.not.not = icmp slt i64 %indvars.iv, %15
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge23:                                    ; preds = %.critedge
  store i32 %41, ptr @top, align 4, !tbaa !5
  store i64 %40, ptr @ans, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %._crit_edge23, %._crit_edge
  %17 = phi i64 [ %40, %._crit_edge23 ], [ %ans.promoted, %._crit_edge ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %17)
  ret i32 0

thread-pre-split:                                 ; preds = %thread-pre-split.preheader, %.critedge
  %indvars.iv33 = phi i64 [ %11, %thread-pre-split.preheader ], [ %indvars.iv.next34, %.critedge ]
  %.pr2021 = phi i32 [ %7, %thread-pre-split.preheader ], [ %41, %.critedge ]
  %19 = phi i64 [ %ans.promoted, %thread-pre-split.preheader ], [ %40, %.critedge ]
  %.not1115 = icmp eq i32 %.pr2021, 0
  br i1 %.not1115, label %.critedge, label %.lr.ph16

.lr.ph16:                                         ; preds = %thread-pre-split
  %20 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %indvars.iv33
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %.pr2021 to i64
  br label %23

23:                                               ; preds = %.lr.ph16, %30
  %indvars.iv30 = phi i64 [ %22, %.lr.ph16 ], [ %indvars.iv.next31, %30 ]
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, -1
  %24 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %indvars.iv.next31
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [80002 x i32], ptr @seq, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp slt i32 %28, %21
  br i1 %29, label %30, label %.critedge.loopexit.split.loop.exit39

30:                                               ; preds = %23
  %.not11 = icmp eq i64 %indvars.iv.next31, 0
  br i1 %.not11, label %.critedge, label %23, !llvm.loop !13

.critedge.loopexit.split.loop.exit39:             ; preds = %23
  %31 = trunc nsw i64 %indvars.iv30 to i32
  br label %.critedge

.critedge:                                        ; preds = %30, %.critedge.loopexit.split.loop.exit39, %thread-pre-split
  %.lcssa = phi i32 [ 0, %thread-pre-split ], [ %31, %.critedge.loopexit.split.loop.exit39 ], [ 0, %30 ]
  %32 = add nsw i32 %.lcssa, -1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = trunc nuw nsw i64 %indvars.iv33 to i32
  %37 = xor i32 %36, -1
  %38 = add i32 %35, %37
  %39 = sext i32 %38 to i64
  %40 = add nsw i64 %19, %39
  %41 = add nsw i32 %.lcssa, 1
  %42 = sext i32 %.lcssa to i64
  %43 = getelementptr inbounds [80002 x i32], ptr @stack, i64 0, i64 %42
  store i32 %36, ptr %43, align 4, !tbaa !5
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %44 = icmp sgt i64 %indvars.iv33, 1
  br i1 %44, label %thread-pre-split, label %._crit_edge23, !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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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