; LLVM IR from tangjz/acm-icpc :: codeforces/complete (797B)

; 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 [100001 x i32], align 16
@tp = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %4

4:                                                ; preds = %36, %0
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @n, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %37

8:                                                ; preds = %4
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i32, ptr @a, i64 %10
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %11)
  %13 = load i32, ptr @m, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = and i32 %16, 1
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %8
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @m, align 4, !tbaa !5
  br label %36

22:                                               ; preds = %8
  %23 = load i32, ptr @m, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  %29 = load i32, ptr @m, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr @tp, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr @tp, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %28, %22
  br label %36

36:                                               ; preds = %35, %19
  br label %4, !llvm.loop !9

37:                                               ; preds = %4
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr @a, i64 %39
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %40)
  store i32 -2000000000, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %63, %37
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = icmp sge i32 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %66

47:                                               ; preds = %43
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr @tp, align 4, !tbaa !5
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr @tp, align 4, !tbaa !5
  %54 = and i32 %53, 1
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %62

56:                                               ; preds = %47
  %57 = load i32, ptr @ans, align 4, !tbaa !5
  %58 = load i32, ptr @tp, align 4, !tbaa !5
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %56
  %61 = load i32, ptr @tp, align 4, !tbaa !5
  store i32 %61, ptr @ans, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %60, %56, %47
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = add nsw i32 %64, -1
  store i32 %65, ptr %2, align 4, !tbaa !5
  br label %43, !llvm.loop !11

66:                                               ; preds = %46
  %67 = load i32, ptr @ans, align 4, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %67)
  ret i32 0
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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
@m = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@tp = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not8 = icmp eq i32 %2, 0
  %.pre15 = load i32, ptr @m, align 4, !tbaa !5
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %20
  %4 = phi i32 [ %21, %20 ], [ %.pre15, %0 ]
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i32, ptr @a, i64 %5
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = and i32 %11, 1
  %.not6 = icmp eq i32 %12, 0
  br i1 %.not6, label %15, label %13

13:                                               ; preds = %.lr.ph
  %14 = add nsw i32 %8, 1
  store i32 %14, ptr @m, align 4, !tbaa !5
  br label %20

15:                                               ; preds = %.lr.ph
  %16 = icmp sgt i32 %11, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = load i32, ptr @tp, align 4, !tbaa !5
  %19 = add nsw i32 %18, %11
  store i32 %19, ptr @tp, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %15, %17, %13
  %21 = phi i32 [ %8, %15 ], [ %8, %17 ], [ %14, %13 ]
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %20, %0
  %24 = phi i32 [ %.pre15, %0 ], [ %21, %20 ]
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr @a, i64 %25
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %26)
  store i32 -2000000000, ptr @ans, align 4, !tbaa !5
  %27 = load i32, ptr @m, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph12.preheader, label %37

.lr.ph12.preheader:                               ; preds = %._crit_edge
  %tp.promoted = load i32, ptr @tp, align 4, !tbaa !5
  %29 = zext nneg i32 %27 to i64
  %xtraiter = and i64 %29, 1
  %30 = icmp eq i32 %27, 1
  br i1 %30, label %._crit_edge13.unr-lcssa, label %.lr.ph12.preheader.new

.lr.ph12.preheader.new:                           ; preds = %.lr.ph12.preheader
  %unroll_iter = and i64 %29, 2147483646
  br label %.lr.ph12

._crit_edge13.unr-lcssa:                          ; preds = %55, %.lr.ph12.preheader
  %.lcssa20.ph = phi i32 [ poison, %.lr.ph12.preheader ], [ %56, %55 ]
  %.lcssa.ph = phi i32 [ poison, %.lr.ph12.preheader ], [ %51, %55 ]
  %indvars.iv.unr = phi i64 [ %29, %.lr.ph12.preheader ], [ %indvars.iv.next.1, %55 ]
  %.unr = phi i32 [ %tp.promoted, %.lr.ph12.preheader ], [ %51, %55 ]
  %.unr22 = phi i32 [ -2000000000, %.lr.ph12.preheader ], [ %56, %55 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge13, label %.lr.ph12.epil

.lr.ph12.epil:                                    ; preds = %._crit_edge13.unr-lcssa
  %indvars.iv.next.epil = add nsw i64 %indvars.iv.unr, -1
  %31 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next.epil
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %.unr, %32
  %34 = and i32 %33, 1
  %.not5.epil = icmp ne i32 %34, 0
  %35 = icmp slt i32 %.unr22, %33
  %or.cond.epil = select i1 %.not5.epil, i1 %35, i1 false
  br i1 %or.cond.epil, label %36, label %._crit_edge13

36:                                               ; preds = %.lr.ph12.epil
  store i32 %33, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge13

._crit_edge13:                                    ; preds = %.lr.ph12.epil, %36, %._crit_edge13.unr-lcssa
  %.lcssa20 = phi i32 [ %.lcssa20.ph, %._crit_edge13.unr-lcssa ], [ %.unr22, %.lr.ph12.epil ], [ %33, %36 ]
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge13.unr-lcssa ], [ %33, %36 ], [ %33, %.lr.ph12.epil ]
  store i32 %.lcssa, ptr @tp, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %._crit_edge13, %._crit_edge
  %38 = phi i32 [ %.lcssa20, %._crit_edge13 ], [ -2000000000, %._crit_edge ]
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  ret i32 0

.lr.ph12:                                         ; preds = %55, %.lr.ph12.preheader.new
  %indvars.iv = phi i64 [ %29, %.lr.ph12.preheader.new ], [ %indvars.iv.next.1, %55 ]
  %40 = phi i32 [ %tp.promoted, %.lr.ph12.preheader.new ], [ %51, %55 ]
  %41 = phi i32 [ -2000000000, %.lr.ph12.preheader.new ], [ %56, %55 ]
  %niter = phi i64 [ 0, %.lr.ph12.preheader.new ], [ %niter.next.1, %55 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %42 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %40, %43
  %45 = and i32 %44, 1
  %.not5 = icmp ne i32 %45, 0
  %46 = icmp slt i32 %41, %44
  %or.cond = select i1 %.not5, i1 %46, i1 false
  br i1 %or.cond, label %47, label %.lr.ph12.1

47:                                               ; preds = %.lr.ph12
  store i32 %44, ptr @ans, align 4, !tbaa !5
  br label %.lr.ph12.1

.lr.ph12.1:                                       ; preds = %.lr.ph12, %47
  %48 = phi i32 [ %41, %.lr.ph12 ], [ %44, %47 ]
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %49 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next.1
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nsw i32 %44, %50
  %52 = and i32 %51, 1
  %.not5.1 = icmp ne i32 %52, 0
  %53 = icmp slt i32 %48, %51
  %or.cond.1 = select i1 %.not5.1, i1 %53, i1 false
  br i1 %or.cond.1, label %54, label %55

54:                                               ; preds = %.lr.ph12.1
  store i32 %51, ptr @ans, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %54, %.lr.ph12.1
  %56 = phi i32 [ %48, %.lr.ph12.1 ], [ %51, %54 ]
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge13.unr-lcssa, label %.lr.ph12, !llvm.loop !11
}

; 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 @_ZSt4sortIPiEvT_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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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