; LLVM IR from tangjz/acm-icpc :: codeforces/complete (1175D)

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

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

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %29

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

26:                                               ; preds = %11
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

29:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %47, %29
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %50

36:                                               ; preds = %32
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = add nsw i64 %45, %40
  store i64 %46, ptr %44, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %36
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %3, align 4, !tbaa !5
  br label %32, !llvm.loop !13

50:                                               ; preds = %35
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i64, ptr @a, i64 %52
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef getelementptr inbounds (i64, ptr @a, i64 1), ptr noundef %53)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %68, %50
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = sub nsw i32 %56, %57
  %59 = icmp sle i32 %55, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %71

61:                                               ; preds = %54
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !9
  %66 = load i64, ptr @ans, align 8, !tbaa !9
  %67 = sub nsw i64 %66, %65
  store i64 %67, ptr @ans, align 8, !tbaa !9
  br label %68

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

71:                                               ; preds = %60
  %72 = load i64, ptr @ans, align 8, !tbaa !9
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %72)
  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

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

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 = { 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}


; 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
@m = external dso_local global i32, align 4
@a = external dso_local global [300001 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i32 %13, 1
  br i1 %4, label %.lr.ph17.preheader, label %._crit_edge

.lr.ph17.preheader:                               ; preds = %.preheader
  %5 = zext nneg i32 %13 to i64
  %6 = shl nuw nsw i64 %5, 3
  %scevgep = getelementptr i8, ptr getelementptr (i8, ptr @a, i64 -8), i64 %6
  %load_initial = load i64, ptr %scevgep, align 8
  br label %.lr.ph17

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

._crit_edge:                                      ; preds = %.lr.ph17, %0, %.preheader
  %.lcssa34 = phi i32 [ %13, %.preheader ], [ %2, %0 ], [ %13, %.lr.ph17 ]
  %16 = sext i32 %.lcssa34 to i64
  %17 = getelementptr inbounds i64, ptr @a, i64 %16
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 8), ptr noundef nonnull %17)
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  %.not18.not = icmp sgt i32 %18, %19
  br i1 %.not18.not, label %.lr.ph21.preheader, label %35

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %20 = add i32 %18, 1
  %21 = sub i32 %20, %19
  %wide.trip.count = zext i32 %21 to i64
  %22 = add nsw i64 %wide.trip.count, -1
  %min.iters.check = icmp ult i64 %22, 4
  br i1 %min.iters.check, label %.lr.ph21.preheader39, label %vector.ph

.lr.ph21.preheader39:                             ; preds = %middle.block, %.lr.ph21.preheader
  %indvars.iv30.ph = phi i64 [ 1, %.lr.ph21.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i64 [ %ans.promoted, %.lr.ph21.preheader ], [ %29, %middle.block ]
  br label %.lr.ph21

vector.ph:                                        ; preds = %.lr.ph21.preheader
  %n.vec = and i64 %22, -4
  %ind.end = or disjoint i64 %n.vec, 1
  %23 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %ans.promoted, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %23, %vector.ph ], [ %26, %vector.body ]
  %vec.phi37 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %27, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %24 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %offset.idx
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <2 x i64>, ptr %24, align 8, !tbaa !9
  %wide.load38 = load <2 x i64>, ptr %25, align 8, !tbaa !9
  %26 = sub <2 x i64> %vec.phi, %wide.load
  %27 = sub <2 x i64> %vec.phi37, %wide.load38
  %index.next = add nuw i64 %index, 4
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %27, %26
  %29 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %22, %n.vec
  br i1 %cmp.n, label %._crit_edge22, label %.lr.ph21.preheader39

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %.lr.ph17
  %store_forwarded = phi i64 [ %load_initial, %.lr.ph17.preheader ], [ %33, %.lr.ph17 ]
  %indvars.iv27 = phi i64 [ %5, %.lr.ph17.preheader ], [ %indvars.iv.next28, %.lr.ph17 ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %30 = add nsw i64 %indvars.iv27, -2
  %31 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = add nsw i64 %32, %store_forwarded
  store i64 %33, ptr %31, align 8, !tbaa !9
  %34 = icmp ugt i64 %indvars.iv27, 2
  br i1 %34, label %.lr.ph17, label %._crit_edge, !llvm.loop !16

._crit_edge22:                                    ; preds = %.lr.ph21, %middle.block
  %.lcssa = phi i64 [ %29, %middle.block ], [ %41, %.lr.ph21 ]
  store i64 %.lcssa, ptr @ans, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %._crit_edge22, %._crit_edge
  %36 = phi i64 [ %.lcssa, %._crit_edge22 ], [ %ans.promoted, %._crit_edge ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %36)
  ret i32 0

.lr.ph21:                                         ; preds = %.lr.ph21.preheader39, %.lr.ph21
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.lr.ph21 ], [ %indvars.iv30.ph, %.lr.ph21.preheader39 ]
  %38 = phi i64 [ %41, %.lr.ph21 ], [ %.ph, %.lr.ph21.preheader39 ]
  %39 = getelementptr inbounds [300001 x i64], ptr @a, i64 0, i64 %indvars.iv30
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = sub nsw i64 %38, %40
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !17
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12, !15, !14}


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