; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (5777)

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

7:                                                ; preds = %64, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr %2, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %72

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %23, %11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %21)
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !9

26:                                               ; preds = %17
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @n, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @a, i64 %30
  %32 = getelementptr inbounds i32, ptr %31, i64 1
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds (i32, ptr @a, i64 1), ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %61, %26
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %64

38:                                               ; preds = %33
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i64, ptr %4, align 8, !tbaa !11
  %45 = add nsw i64 %44, %43
  store i64 %45, ptr %4, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %48 = load i32, ptr @k, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = add nsw i32 %49, 1
  %51 = icmp sgt i32 %46, %50
  br i1 %51, label %52, label %60

52:                                               ; preds = %38
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i64, ptr %4, align 8, !tbaa !11
  %59 = sub nsw i64 %58, %57
  store i64 %59, ptr %4, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %52, %38
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !13

64:                                               ; preds = %37
  %65 = load i64, ptr %4, align 8, !tbaa !11
  %66 = load i32, ptr @n, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = add nsw i64 %65, %67
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %4, align 8, !tbaa !11
  %70 = load i64, ptr %4, align 8, !tbaa !11
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %7, !llvm.loop !14

72:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

; 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 @_ZSt4sortIPiEvT_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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!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
@k = external dso_local global i32, align 4
@a = external dso_local global [100010 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr %1, align 4, !tbaa !5
  %.not28 = icmp eq i32 %3, 0
  br i1 %.not28, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %0, %._crit_edge25
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph30
  %.lcssa = phi i32 [ %6, %.lr.ph30 ], [ %19, %.lr.ph ]
  %8 = add nsw i32 %.lcssa, -1
  store i32 %8, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), i64 %9
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 4), ptr noundef nonnull %gep)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %.not1720 = icmp slt i32 %10, 1
  br i1 %.not1720, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %._crit_edge
  %11 = load i32, ptr @k, align 4, !tbaa !5
  %12 = add nuw i32 %10, 1
  %13 = sub i32 %12, %11
  %14 = sext i32 %13 to i64
  %15 = zext nneg i32 %10 to i64
  %xtraiter = and i64 %15, 3
  %16 = icmp ult i32 %10, 4
  br i1 %16, label %._crit_edge25.loopexit.unr-lcssa, label %.lr.ph24.new

.lr.ph24.new:                                     ; preds = %.lr.ph24
  %unroll_iter = and i64 %15, 2147483644
  br label %33

.lr.ph:                                           ; preds = %.lr.ph30, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.lr.ph30 ]
  %17 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge25.loopexit.unr-lcssa:                 ; preds = %33, %.lr.ph24
  %spec.select.lcssa.ph = phi i64 [ poison, %.lr.ph24 ], [ %spec.select.3, %33 ]
  %indvars.iv34.unr = phi i64 [ 1, %.lr.ph24 ], [ %indvars.iv.next35.3, %33 ]
  %.01221.unr = phi i64 [ 0, %.lr.ph24 ], [ %spec.select.3, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge25, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge25.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv34.epil = phi i64 [ %indvars.iv.next35.epil, %.epil.preheader ], [ %indvars.iv34.unr, %._crit_edge25.loopexit.unr-lcssa ]
  %.01221.epil = phi i64 [ %spec.select.epil, %.epil.preheader ], [ %.01221.unr, %._crit_edge25.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge25.loopexit.unr-lcssa ]
  %22 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv34.epil
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp sgt i64 %indvars.iv34.epil, %14
  %25 = sext i32 %23 to i64
  %26 = select i1 %24, i64 0, i64 %25
  %spec.select.epil = add nsw i64 %.01221.epil, %26
  %indvars.iv.next35.epil = add nuw nsw i64 %indvars.iv34.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge25, label %.epil.preheader, !llvm.loop !11

._crit_edge25:                                    ; preds = %._crit_edge25.loopexit.unr-lcssa, %.epil.preheader, %._crit_edge
  %.012.lcssa = phi i64 [ 0, %._crit_edge ], [ %spec.select.lcssa.ph, %._crit_edge25.loopexit.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %27 = sext i32 %10 to i64
  %28 = add i64 %.012.lcssa, 1
  %29 = add i64 %28, %27
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %29)
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !13

33:                                               ; preds = %33, %.lr.ph24.new
  %indvars.iv34 = phi i64 [ 1, %.lr.ph24.new ], [ %indvars.iv.next35.3, %33 ]
  %.01221 = phi i64 [ 0, %.lr.ph24.new ], [ %spec.select.3, %33 ]
  %niter = phi i64 [ 0, %.lr.ph24.new ], [ %niter.next.3, %33 ]
  %34 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv34
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp sgt i64 %indvars.iv34, %14
  %37 = sext i32 %35 to i64
  %38 = select i1 %36, i64 0, i64 %37
  %spec.select = add nsw i64 %.01221, %38
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %39 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv.next35
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not41 = icmp slt i64 %indvars.iv34, %14
  %41 = sext i32 %40 to i64
  %42 = select i1 %.not41, i64 %41, i64 0
  %spec.select.1 = add nsw i64 %spec.select, %42
  %indvars.iv.next35.1 = add nuw nsw i64 %indvars.iv34, 2
  %43 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv.next35.1
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sgt i64 %indvars.iv.next35.1, %14
  %46 = sext i32 %44 to i64
  %47 = select i1 %45, i64 0, i64 %46
  %spec.select.2 = add nsw i64 %spec.select.1, %47
  %indvars.iv.next35.2 = add nuw nsw i64 %indvars.iv34, 3
  %48 = getelementptr inbounds [100010 x i32], ptr @a, i64 0, i64 %indvars.iv.next35.2
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp sgt i64 %indvars.iv.next35.2, %14
  %51 = sext i32 %49 to i64
  %52 = select i1 %50, i64 0, i64 %51
  %spec.select.3 = add nsw i64 %spec.select.2, %52
  %indvars.iv.next35.3 = add nuw nsw i64 %indvars.iv34, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge25.loopexit.unr-lcssa, label %33, !llvm.loop !14

._crit_edge31:                                    ; preds = %._crit_edge25, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress 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 @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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