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

; 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
@a = external dso_local global [1000002 x i32], align 16
@cnt = external dso_local global i64, align 8
@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 i64, align 8
  %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 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %33, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp slt 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 %36

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @a, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15)
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %24
  store i32 %20, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = load i64, ptr @cnt, align 8, !tbaa !9
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr @cnt, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %12
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !11

36:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %37 = load i64, ptr @cnt, align 8, !tbaa !9
  store i64 %37, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %38 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %38, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %80, %36
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = shl i32 %41, 1
  %43 = icmp slt i32 %40, %42
  br i1 %43, label %45, label %44

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

45:                                               ; preds = %39
  br label %46

46:                                               ; preds = %57, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %55

50:                                               ; preds = %46
  %51 = load i64, ptr %3, align 8, !tbaa !9
  %52 = load i64, ptr @cnt, align 8, !tbaa !9
  %53 = ashr i64 %52, 1
  %54 = icmp sgt i64 %51, %53
  br label %55

55:                                               ; preds = %50, %46
  %56 = phi i1 [ false, %46 ], [ %54, %50 ]
  br i1 %56, label %57, label %66

57:                                               ; preds = %55
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %58 to i64
  %61 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = load i64, ptr %3, align 8, !tbaa !9
  %65 = sub nsw i64 %64, %63
  store i64 %65, ptr %3, align 8, !tbaa !9
  br label %46, !llvm.loop !13

66:                                               ; preds = %55
  %67 = load i64, ptr @ans, align 8, !tbaa !9
  %68 = load i64, ptr %3, align 8, !tbaa !9
  %69 = icmp slt i64 %67, %68
  br i1 %69, label %70, label %72

70:                                               ; preds = %66
  %71 = load i64, ptr %3, align 8, !tbaa !9
  store i64 %71, ptr @ans, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %70, %66
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = load i64, ptr %3, align 8, !tbaa !9
  %79 = add nsw i64 %78, %77
  store i64 %79, ptr %3, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %72
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %4, align 4, !tbaa !5
  br label %39, !llvm.loop !14

83:                                               ; preds = %44
  %84 = load i64, ptr @ans, align 8, !tbaa !9
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  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 = !{!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}


; 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
@a = external dso_local global [1000002 x i32], align 16
@cnt = external dso_local local_unnamed_addr global i64, align 8
@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
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %2, %0 ], [ %12, %.lr.ph ]
  %4 = shl i32 %.lcssa, 1
  %5 = icmp slt i32 %.lcssa, %4
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge35

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %6 = load i64, ptr @cnt, align 8
  %7 = ashr i64 %6, 1
  %8 = sext i32 %.lcssa to i64
  %wide.trip.count = sext i32 %4 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %9 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %9)
  %11 = load i32, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  %14 = add nsw i32 %12, %13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %15
  store i32 %11, ptr %16, align 4, !tbaa !5
  %17 = sext i32 %11 to i64
  %18 = load i64, ptr @cnt, align 8, !tbaa !9
  %19 = add nsw i64 %18, %17
  store i64 %19, ptr @cnt, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = sext i32 %12 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.lr.ph, %38
  %indvars.iv43 = phi i64 [ %8, %.preheader.lr.ph ], [ %indvars.iv.next44, %38 ]
  %.034 = phi i32 [ 0, %.preheader.lr.ph ], [ %.1.lcssa, %38 ]
  %.01832 = phi i64 [ %6, %.preheader.lr.ph ], [ %42, %38 ]
  %.119.lcssa3031 = phi i64 [ %ans.promoted, %.preheader.lr.ph ], [ %.119.lcssa29, %38 ]
  %22 = sext i32 %.034 to i64
  %23 = icmp sgt i64 %indvars.iv43, %22
  %24 = icmp sgt i64 %.01832, %7
  %25 = select i1 %23, i1 %24, i1 false
  br i1 %25, label %.lr.ph25, label %._crit_edge26

._crit_edge35:                                    ; preds = %38, %._crit_edge
  %26 = phi i64 [ %ans.promoted, %._crit_edge ], [ %.119.lcssa29, %38 ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %26)
  ret i32 0

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.lr.ph25 ], [ %22, %.preheader ]
  %.11923 = phi i64 [ %31, %.lr.ph25 ], [ %.01832, %.preheader ]
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, 1
  %28 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %indvars.iv40
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = sub nsw i64 %.11923, %30
  %32 = icmp slt i64 %indvars.iv.next41, %indvars.iv43
  %33 = icmp sgt i64 %31, %7
  %34 = select i1 %32, i1 %33, i1 false
  br i1 %34, label %.lr.ph25, label %._crit_edge26.loopexit, !llvm.loop !13

._crit_edge26.loopexit:                           ; preds = %.lr.ph25
  %35 = trunc nsw i64 %indvars.iv.next41 to i32
  br label %._crit_edge26

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit, %.preheader
  %.119.lcssa = phi i64 [ %.01832, %.preheader ], [ %31, %._crit_edge26.loopexit ]
  %.1.lcssa = phi i32 [ %.034, %.preheader ], [ %35, %._crit_edge26.loopexit ]
  %36 = icmp slt i64 %.119.lcssa3031, %.119.lcssa
  br i1 %36, label %37, label %38

37:                                               ; preds = %._crit_edge26
  store i64 %.119.lcssa, ptr @ans, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %37, %._crit_edge26
  %.119.lcssa29 = phi i64 [ %.119.lcssa, %37 ], [ %.119.lcssa3031, %._crit_edge26 ]
  %39 = getelementptr inbounds [1000002 x i32], ptr @a, i64 0, i64 %indvars.iv43
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %.119.lcssa, %41
  %indvars.iv.next44 = add nsw i64 %indvars.iv43, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge35, 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 = !{!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,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass