; LLVM IR from tangjz/acm-icpc :: uvalive (6906)

; 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"

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

7:                                                ; preds = %60, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %63

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

14:                                               ; preds = %24, %12
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %27

19:                                               ; preds = %14
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr @a, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  br label %24

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

27:                                               ; preds = %18
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr @a, i64 %29
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %30)
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %53, %27
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %56

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sub nsw i32 %40, %45
  %47 = load i32, ptr @k, align 4, !tbaa !5
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %52

49:                                               ; preds = %36
  %50 = load i32, ptr @ans, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr @ans, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %49, %36
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !11

56:                                               ; preds = %35
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = load i32, ptr @ans, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %57, i32 noundef %58)
  br label %60

60:                                               ; preds = %56
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !12

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@a = external dso_local global [101 x i32], align 16
@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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not18 = icmp slt i32 %2, 1
  br i1 %.not18, label %._crit_edge22, label %.lr.ph21

._crit_edge22:                                    ; preds = %._crit_edge17, %0
  ret i32 0

.lr.ph21:                                         ; preds = %0, %._crit_edge17
  %.01119 = phi i32 [ %25, %._crit_edge17 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.lr.ph21.._crit_edge_crit_edge

.lr.ph21.._crit_edge_crit_edge:                   ; preds = %.lr.ph21
  %.pre28 = sext i32 %4 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph21.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre28, %.lr.ph21.._crit_edge_crit_edge ], [ %15, %.lr.ph ]
  %6 = getelementptr inbounds i32, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %6)
  store i32 1, ptr @ans, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 1
  br i1 %8, label %.lr.ph16, label %._crit_edge17

.lr.ph16:                                         ; preds = %._crit_edge
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %7 to i64
  %.pre = load i32, ptr @a, align 16, !tbaa !5
  %10 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %10, 1
  %11 = icmp eq i32 %7, 2
  br i1 %11, label %._crit_edge17.loopexit.unr-lcssa, label %.lr.ph16.new

.lr.ph16.new:                                     ; preds = %.lr.ph16
  %unroll_iter = and i64 %10, -2
  br label %27

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

._crit_edge17.loopexit.unr-lcssa:                 ; preds = %44, %.lr.ph16
  %.lcssa31.ph = phi i32 [ poison, %.lr.ph16 ], [ %45, %44 ]
  %.unr = phi i32 [ %.pre, %.lr.ph16 ], [ %39, %44 ]
  %indvars.iv25.unr = phi i64 [ 1, %.lr.ph16 ], [ %indvars.iv.next26.1, %44 ]
  %.unr32 = phi i32 [ 1, %.lr.ph16 ], [ %45, %44 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge17, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge17.loopexit.unr-lcssa
  %17 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv25.unr
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sub nsw i32 %18, %.unr
  %20 = icmp sgt i32 %19, %9
  br i1 %20, label %21, label %._crit_edge17

21:                                               ; preds = %.epil.preheader
  %22 = add nsw i32 %.unr32, 1
  store i32 %22, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %._crit_edge17.loopexit.unr-lcssa, %21, %.epil.preheader, %._crit_edge
  %23 = phi i32 [ 1, %._crit_edge ], [ %.lcssa31.ph, %._crit_edge17.loopexit.unr-lcssa ], [ %.unr32, %.epil.preheader ], [ %22, %21 ]
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.01119, i32 noundef %23)
  %25 = add nuw nsw i32 %.01119, 1
  %26 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01119, %26
  br i1 %.not.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !11

27:                                               ; preds = %44, %.lr.ph16.new
  %28 = phi i32 [ %.pre, %.lr.ph16.new ], [ %39, %44 ]
  %indvars.iv25 = phi i64 [ 1, %.lr.ph16.new ], [ %indvars.iv.next26.1, %44 ]
  %29 = phi i32 [ 1, %.lr.ph16.new ], [ %45, %44 ]
  %niter = phi i64 [ 0, %.lr.ph16.new ], [ %niter.next.1, %44 ]
  %30 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv25
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sub nsw i32 %31, %28
  %33 = icmp sgt i32 %32, %9
  br i1 %33, label %34, label %36

34:                                               ; preds = %27
  %35 = add nsw i32 %29, 1
  store i32 %35, ptr @ans, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %27, %34
  %37 = phi i32 [ %29, %27 ], [ %35, %34 ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %38 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next26
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sub nsw i32 %39, %31
  %41 = icmp sgt i32 %40, %9
  br i1 %41, label %42, label %44

42:                                               ; preds = %36
  %43 = add nsw i32 %37, 1
  store i32 %43, ptr @ans, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42, %36
  %45 = phi i32 [ %37, %36 ], [ %43, %42 ]
  %indvars.iv.next26.1 = add nuw nsw i64 %indvars.iv25, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge17.loopexit.unr-lcssa, label %27, !llvm.loop !12
}

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


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