; LLVM IR from tangjz/acm-icpc :: codeforces/complete (313C)

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

9:                                                ; preds = %25, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %16
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17)
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load i64, ptr @ans, align 8, !tbaa !9
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr @ans, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %14
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !11

28:                                               ; preds = %13
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i64, ptr @num, i64 %30
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @num, ptr noundef %31)
  br label %32

32:                                               ; preds = %38, %28
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = mul nsw i32 2, %33
  %35 = shl i32 1, %34
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %32
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %2, align 4, !tbaa !5
  br label %32, !llvm.loop !13

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %69, %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 7, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %72

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = mul nsw i32 2, %48
  %50 = shl i32 1, %49
  store i32 %50, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %65, %47
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 10, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %68

56:                                               ; preds = %51
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = sub nsw i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = load i64, ptr @ans, align 8, !tbaa !9
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr @ans, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %56
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !5
  br label %51, !llvm.loop !14

68:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %42, !llvm.loop !15

72:                                               ; preds = %46
  %73 = load i64, ptr @ans, align 8, !tbaa !9
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %73)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %75 = load i32, ptr %1, align 4
  ret i32 %75
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 = !{!"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}
!15 = distinct !{!15, !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
@num = external dso_local global [2000001 x i64], align 16
@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
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse 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

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %12, %.lr.ph ]
  %4 = getelementptr inbounds i64, ptr @num, i64 %.pre-phi
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @num, ptr noundef nonnull %4)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  br label %14

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %indvars.iv
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %8 = load i64, ptr %6, align 8, !tbaa !9
  %9 = load i64, ptr @ans, align 8, !tbaa !9
  %10 = add nsw i64 %9, %8
  store i64 %10, ptr @ans, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11

14:                                               ; preds = %14, %._crit_edge
  %.017 = phi i32 [ 0, %._crit_edge ], [ %18, %14 ]
  %15 = shl nuw nsw i32 %.017, 1
  %16 = shl nuw i32 1, %15
  %17 = icmp slt i32 %16, %5
  %18 = add nuw nsw i32 %.017, 1
  br i1 %17, label %14, label %.preheader, !llvm.loop !13

.preheader:                                       ; preds = %14
  %ans.promoted23 = load i64, ptr @ans, align 8, !tbaa !9
  %.not29 = icmp eq i32 %.017, 0
  br i1 %.not29, label %28, label %.lr.ph27.preheader

.lr.ph27.preheader:                               ; preds = %.preheader
  %19 = sext i32 %5 to i64
  %xtraiter = and i32 %.017, 1
  %20 = icmp eq i32 %.017, 1
  br i1 %20, label %._crit_edge28.unr-lcssa, label %.lr.ph27.preheader.new

.lr.ph27.preheader.new:                           ; preds = %.lr.ph27.preheader
  %unroll_iter = and i32 %.017, 2147483646
  br label %.lr.ph27

._crit_edge28.unr-lcssa.loopexit:                 ; preds = %41
  %21 = shl nuw nsw i32 %42, 1
  br label %._crit_edge28.unr-lcssa

._crit_edge28.unr-lcssa:                          ; preds = %._crit_edge28.unr-lcssa.loopexit, %.lr.ph27.preheader
  %.lcssa.lcssa.ph = phi i64 [ poison, %.lr.ph27.preheader ], [ %39, %._crit_edge28.unr-lcssa.loopexit ]
  %.01526.unr = phi i32 [ 0, %.lr.ph27.preheader ], [ %21, %._crit_edge28.unr-lcssa.loopexit ]
  %.lcssa212425.unr = phi i64 [ %ans.promoted23, %.lr.ph27.preheader ], [ %39, %._crit_edge28.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge28, label %.lr.ph27.epil

.lr.ph27.epil:                                    ; preds = %._crit_edge28.unr-lcssa, %.lr.ph27.epil
  %indvars.iv32.epil = phi i64 [ %indvars.iv.next33.epil, %.lr.ph27.epil ], [ 1, %._crit_edge28.unr-lcssa ]
  %22 = phi i64 [ %26, %.lr.ph27.epil ], [ %.lcssa212425.unr, %._crit_edge28.unr-lcssa ]
  %23 = sub nsw i64 %19, %indvars.iv32.epil
  %24 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = add nsw i64 %22, %25
  %indvars.iv.next33.epil = add nuw nsw i64 %indvars.iv32.epil, 1
  %27 = trunc nuw nsw i64 %indvars.iv32.epil to i32
  %.022.highbits.epil = lshr i32 %27, %.01526.unr
  %.not.not.epil = icmp eq i32 %.022.highbits.epil, 0
  br i1 %.not.not.epil, label %.lr.ph27.epil, label %._crit_edge28, !llvm.loop !14

._crit_edge28:                                    ; preds = %.lr.ph27.epil, %._crit_edge28.unr-lcssa
  %.lcssa.lcssa = phi i64 [ %.lcssa.lcssa.ph, %._crit_edge28.unr-lcssa ], [ %26, %.lr.ph27.epil ]
  store i64 %.lcssa.lcssa, ptr @ans, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %._crit_edge28, %.preheader
  %29 = phi i64 [ %.lcssa.lcssa, %._crit_edge28 ], [ %ans.promoted23, %.preheader ]
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %29)
  ret i32 0

.lr.ph27:                                         ; preds = %41, %.lr.ph27.preheader.new
  %.01526 = phi i32 [ 0, %.lr.ph27.preheader.new ], [ %42, %41 ]
  %.lcssa212425 = phi i64 [ %ans.promoted23, %.lr.ph27.preheader.new ], [ %39, %41 ]
  %niter = phi i32 [ 0, %.lr.ph27.preheader.new ], [ %niter.next.1, %41 ]
  %31 = shl nuw nsw i32 %.01526, 1
  br label %43

.lr.ph27.1:                                       ; preds = %43
  %32 = shl nuw i32 %.01526, 1
  %33 = or disjoint i32 %32, 2
  br label %34

34:                                               ; preds = %34, %.lr.ph27.1
  %indvars.iv32.1 = phi i64 [ 1, %.lr.ph27.1 ], [ %indvars.iv.next33.1, %34 ]
  %35 = phi i64 [ %48, %.lr.ph27.1 ], [ %39, %34 ]
  %36 = sub nsw i64 %19, %indvars.iv32.1
  %37 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = add nsw i64 %35, %38
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32.1, 1
  %40 = trunc nuw nsw i64 %indvars.iv32.1 to i32
  %.022.highbits.1 = lshr i32 %40, %33
  %.not.not.1 = icmp eq i32 %.022.highbits.1, 0
  br i1 %.not.not.1, label %34, label %41, !llvm.loop !14

41:                                               ; preds = %34
  %42 = add nuw nsw i32 %.01526, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge28.unr-lcssa.loopexit, label %.lr.ph27, !llvm.loop !15

43:                                               ; preds = %.lr.ph27, %43
  %indvars.iv32 = phi i64 [ 1, %.lr.ph27 ], [ %indvars.iv.next33, %43 ]
  %44 = phi i64 [ %.lcssa212425, %.lr.ph27 ], [ %48, %43 ]
  %45 = sub nsw i64 %19, %indvars.iv32
  %46 = getelementptr inbounds [2000001 x i64], ptr @num, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = add nsw i64 %44, %47
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %49 = trunc nuw nsw i64 %indvars.iv32 to i32
  %.022.highbits = lshr i32 %49, %31
  %.not.not = icmp eq i32 %.022.highbits, 0
  br i1 %.not.not, label %43, label %.lr.ph27.1, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #2 = { inlinehint 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" }

!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}
!15 = distinct !{!15, !12}


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