; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1127)

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

7:                                                ; preds = %50, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = icmp sle i32 %8, 100
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %13
  %15 = getelementptr inbounds [101 x i64], ptr %14, i64 0, i64 0
  store i64 1, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %46, %11
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [101 x i64], ptr %25, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [101 x i64], ptr %33, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %29, %38
  %40 = load i32, ptr %2, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %41
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [101 x i64], ptr %42, i64 0, i64 %44
  store i64 %39, ptr %45, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %21
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %4, align 4, !tbaa !9
  br label %16, !llvm.loop !11

49:                                               ; preds = %20
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %2, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !13

53:                                               ; preds = %10
  br label %54

54:                                               ; preds = %88, %53
  %55 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  %56 = icmp eq i32 %55, 2
  br i1 %56, label %57, label %89

57:                                               ; preds = %54
  br label %58

58:                                               ; preds = %87, %57
  %59 = load i32, ptr @k, align 4, !tbaa !9
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr @k, align 4, !tbaa !9
  %61 = icmp ne i32 %59, 0
  br i1 %61, label %62, label %88

62:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %63 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5, ptr noundef %6)
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = icmp sge i32 %64, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %62
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = load i32, ptr @n, align 4, !tbaa !9
  %70 = icmp sle i32 %68, %69
  br i1 %70, label %71, label %85

71:                                               ; preds = %67
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = icmp sgt i32 %72, 0
  br i1 %73, label %74, label %85

74:                                               ; preds = %71
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = sub nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %77
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = sub nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [101 x i64], ptr %78, i64 0, i64 %81
  %83 = load i64, ptr %82, align 8, !tbaa !5
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %83)
  br label %87

85:                                               ; preds = %71, %67, %62
  %86 = call i32 @puts(ptr noundef @.str.2)
  br label %87

87:                                               ; preds = %85, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %58, !llvm.loop !14

88:                                               ; preds = %58
  br label %54, !llvm.loop !15

89:                                               ; preds = %54
  ret i32 0
}

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

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

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

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

declare i32 @puts(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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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
@k = external dso_local global i32, align 4
@a = external dso_local local_unnamed_addr global [101 x [101 x i64]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i64 1, ptr @a, align 16, !tbaa !5
  br label %5

.preheader18:                                     ; preds = %.loopexit34
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %.preheader, label %._crit_edge

5:                                                ; preds = %0, %.loopexit34
  %indvars.iv27 = phi i64 [ 1, %0 ], [ %indvars.iv.next28, %.loopexit34 ]
  %indvars.iv25 = phi i64 [ 2, %0 ], [ %indvars.iv.next26, %.loopexit34 ]
  %6 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %indvars.iv27
  store i64 1, ptr %6, align 8, !tbaa !5
  %7 = add nsw i64 %indvars.iv27, -1
  %.phi.trans.insert = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %7, i64 0
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  %min.iters.check = icmp ult i64 %indvars.iv27, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %5
  %.ph = phi i64 [ %.pre, %5 ], [ %vector.recur.extract, %middle.block ]
  %indvars.iv.ph = phi i64 [ 1, %5 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %5
  %n.vec = and i64 %indvars.iv27, 9223372036854775804
  %ind.end = or disjoint i64 %n.vec, 1
  %vector.recur.init = insertelement <2 x i64> poison, i64 %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x i64> [ %vector.recur.init, %vector.ph ], [ %wide.load33, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %8 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %7, i64 %offset.idx
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <2 x i64>, ptr %8, align 8, !tbaa !5
  %wide.load33 = load <2 x i64>, ptr %9, align 8, !tbaa !5
  %10 = shufflevector <2 x i64> %vector.recur, <2 x i64> %wide.load, <2 x i32> <i32 1, i32 2>
  %11 = shufflevector <2 x i64> %wide.load, <2 x i64> %wide.load33, <2 x i32> <i32 1, i32 2>
  %12 = add nsw <2 x i64> %10, %wide.load
  %13 = add nsw <2 x i64> %11, %wide.load33
  %14 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %indvars.iv27, i64 %offset.idx
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <2 x i64> %12, ptr %14, align 8, !tbaa !5
  store <2 x i64> %13, ptr %15, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <2 x i64> %wide.load33, i64 1
  %cmp.n = icmp eq i64 %indvars.iv27, %n.vec
  br i1 %cmp.n, label %.loopexit34, label %scalar.ph.preheader

.loopexit34:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next28, 101
  br i1 %exitcond32.not, label %.preheader18, label %5, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %17 = phi i64 [ %19, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %18 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %7, i64 %indvars.iv
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add nsw i64 %17, %19
  %21 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %indvars.iv27, i64 %indvars.iv
  store i64 %20, ptr %21, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv25
  br i1 %exitcond.not, label %.loopexit34, label %scalar.ph, !llvm.loop !14

.loopexit:                                        ; preds = %43, %.preheader
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %.preheader, label %._crit_edge, !llvm.loop !15

.preheader:                                       ; preds = %.preheader18, %.loopexit
  %24 = load i32, ptr @k, align 4, !tbaa !16
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr @k, align 4, !tbaa !16
  %.not21 = icmp eq i32 %24, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %43
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %27 = load i32, ptr %1, align 4, !tbaa !16
  %28 = load i32, ptr %2, align 4
  %.not16 = icmp slt i32 %27, %28
  br i1 %.not16, label %41, label %29

29:                                               ; preds = %.lr.ph
  %30 = load i32, ptr @n, align 4, !tbaa !16
  %31 = icmp sle i32 %27, %30
  %32 = icmp sgt i32 %28, 0
  %or.cond = and i1 %32, %31
  br i1 %or.cond, label %33, label %41

33:                                               ; preds = %29
  %34 = add nsw i32 %27, -1
  %35 = sext i32 %34 to i64
  %36 = add nsw i32 %28, -1
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds [101 x [101 x i64]], ptr @a, i64 0, i64 %35, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %39)
  br label %43

41:                                               ; preds = %29, %.lr.ph
  %42 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %43

43:                                               ; preds = %41, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %44 = load i32, ptr @k, align 4, !tbaa !16
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr @k, align 4, !tbaa !16
  %.not = icmp eq i32 %44, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit, %.preheader18
  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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree norecurse nounwind 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !10}


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