; LLVM IR from tangjz/acm-icpc :: lydsy (3114)

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

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

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

11:                                               ; preds = %6
  store i32 1, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @n, align 4, !tbaa !5
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m)
  br label %13

13:                                               ; preds = %60, %11
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @m, align 4, !tbaa !5
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %75

17:                                               ; preds = %13
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 1, ptr @now, align 4, !tbaa !5
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @a, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %41, %17
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr @k, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load i32, ptr @now, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = load i32, ptr @a, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %26, %28
  %30 = srem i64 %29, 1000000007
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr @now, align 4, !tbaa !5
  %32 = load i32, ptr @now, align 4, !tbaa !5
  %33 = load i32, ptr @tmp, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr @tmp, align 4, !tbaa !5
  %35 = load i32, ptr @tmp, align 4, !tbaa !5
  %36 = icmp sge i32 %35, 1000000007
  br i1 %36, label %37, label %40

37:                                               ; preds = %24
  %38 = load i32, ptr @tmp, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1000000007
  store i32 %39, ptr @tmp, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %37, %24
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %19, !llvm.loop !9

44:                                               ; preds = %23
  %45 = load i32, ptr @now, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = load i32, ptr @k, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = mul nsw i64 %46, %48
  %50 = srem i64 %49, 1000000007
  %51 = load i32, ptr @tmp, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = add nsw i64 %52, %50
  %54 = trunc i64 %53 to i32
  store i32 %54, ptr @tmp, align 4, !tbaa !5
  %55 = load i32, ptr @tmp, align 4, !tbaa !5
  %56 = icmp sge i32 %55, 1000000007
  br i1 %56, label %57, label %60

57:                                               ; preds = %44
  %58 = load i32, ptr @tmp, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1000000007
  store i32 %59, ptr @tmp, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %57, %44
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = load i32, ptr @tmp, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = mul nsw i64 %62, %64
  %66 = srem i64 %65, 1000000007
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr @ans, align 4, !tbaa !5
  %68 = load i32, ptr @n, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = load i32, ptr @now, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = mul nsw i64 %69, %71
  %73 = srem i64 %72, 1000000007
  %74 = trunc i64 %73 to i32
  store i32 %74, ptr @n, align 4, !tbaa !5
  br label %13, !llvm.loop !11

75:                                               ; preds = %13
  %76 = load i32, ptr @n, align 4, !tbaa !5
  %77 = load i32, ptr @ans, align 4, !tbaa !5
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr @ans, align 4, !tbaa !5
  %79 = load i32, ptr @ans, align 4, !tbaa !5
  %80 = icmp sge i32 %79, 1000000007
  br i1 %80, label %81, label %84

81:                                               ; preds = %75
  %82 = load i32, ptr @ans, align 4, !tbaa !5
  %83 = sub nsw i32 %82, 1000000007
  store i32 %83, ptr @ans, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %81, %75
  %85 = load i32, ptr %2, align 4, !tbaa !5
  %86 = load i32, ptr @ans, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %85, i32 noundef %86)
  br label %88

88:                                               ; preds = %84
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !12

91:                                               ; preds = %10
  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

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 = { 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
@m = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@now = external dso_local local_unnamed_addr global i32, align 4
@tmp = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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
  %.not25 = icmp slt i32 %2, 1
  br i1 %.not25, label %._crit_edge29, label %.lr.ph28

._crit_edge29:                                    ; preds = %._crit_edge24, %0
  ret i32 0

.lr.ph28:                                         ; preds = %0, %._crit_edge24
  %.0526 = phi i32 [ %63, %._crit_edge24 ], [ 1, %0 ]
  store i32 1, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @n, align 4, !tbaa !5
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @m, align 4, !tbaa !5
  %.not1021 = icmp eq i32 %4, 0
  br i1 %.not1021, label %.lr.ph28.._crit_edge24_crit_edge, label %.lr.ph23

.lr.ph28.._crit_edge24_crit_edge:                 ; preds = %.lr.ph28
  %.pre31 = load i32, ptr @n, align 4, !tbaa !5
  %.pre32 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge24

.lr.ph23:                                         ; preds = %.lr.ph28, %18
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 1, ptr @now, align 4, !tbaa !5
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a, ptr noundef nonnull @k)
  %7 = load i32, ptr @k, align 4, !tbaa !5
  %.not1117 = icmp slt i32 %7, 1
  br i1 %.not1117, label %.lr.ph23._crit_edge, label %.lr.ph

.lr.ph23._crit_edge:                              ; preds = %.lr.ph23
  %.pre = load i32, ptr @now, align 4, !tbaa !5
  %.pre30 = load i32, ptr @tmp, align 4, !tbaa !5
  br label %18

.lr.ph:                                           ; preds = %.lr.ph23
  %tmp.promoted = load i32, ptr @tmp, align 4, !tbaa !5
  %now.promoted = load i32, ptr @now, align 4, !tbaa !5
  %8 = load i32, ptr @a, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %xtraiter = and i32 %7, 1
  %10 = icmp eq i32 %7, 1
  br i1 %10, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i32 %7, 2147483646
  br label %42

._crit_edge.unr-lcssa:                            ; preds = %42, %.lr.ph
  %.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %53, %42 ]
  %spec.select14.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %spec.select14.1, %42 ]
  %.unr = phi i32 [ %now.promoted, %.lr.ph ], [ %53, %42 ]
  %spec.select141618.unr = phi i32 [ %tmp.promoted, %.lr.ph ], [ %spec.select14.1, %42 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %11 = sext i32 %.unr to i64
  %12 = mul nsw i64 %9, %11
  %13 = srem i64 %12, 1000000007
  %14 = trunc nsw i64 %13 to i32
  %15 = add nsw i32 %spec.select141618.unr, %14
  %16 = icmp sgt i32 %15, 1000000006
  %17 = add nsw i32 %15, -1000000007
  %spec.select14.epil = select i1 %16, i32 %17, i32 %15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %14, %._crit_edge.epilog-lcssa ]
  %spec.select14.lcssa = phi i32 [ %spec.select14.lcssa.ph, %._crit_edge.unr-lcssa ], [ %spec.select14.epil, %._crit_edge.epilog-lcssa ]
  store i32 %.lcssa, ptr @now, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %.lr.ph23._crit_edge, %._crit_edge
  %19 = phi i32 [ %.pre30, %.lr.ph23._crit_edge ], [ %spec.select14.lcssa, %._crit_edge ]
  %20 = phi i32 [ %.pre, %.lr.ph23._crit_edge ], [ %.lcssa, %._crit_edge ]
  %21 = sext i32 %20 to i64
  %22 = sext i32 %7 to i64
  %23 = mul nsw i64 %21, %22
  %24 = srem i64 %23, 1000000007
  %25 = trunc nsw i64 %24 to i32
  %26 = add i32 %19, %25
  %27 = icmp sgt i32 %26, 1000000006
  %28 = add nsw i32 %26, -1000000007
  %spec.select = select i1 %27, i32 %28, i32 %26
  store i32 %spec.select, ptr @tmp, align 4, !tbaa !5
  %29 = load i32, ptr @ans, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = sext i32 %spec.select to i64
  %32 = mul nsw i64 %31, %30
  %33 = srem i64 %32, 1000000007
  %34 = trunc nsw i64 %33 to i32
  store i32 %34, ptr @ans, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul nsw i64 %36, %21
  %38 = srem i64 %37, 1000000007
  %39 = trunc nsw i64 %38 to i32
  store i32 %39, ptr @n, align 4, !tbaa !5
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @m, align 4, !tbaa !5
  %.not10 = icmp eq i32 %40, 0
  br i1 %.not10, label %._crit_edge24, label %.lr.ph23, !llvm.loop !9

42:                                               ; preds = %42, %.lr.ph.new
  %43 = phi i32 [ %now.promoted, %.lr.ph.new ], [ %53, %42 ]
  %spec.select141618 = phi i32 [ %tmp.promoted, %.lr.ph.new ], [ %spec.select14.1, %42 ]
  %niter = phi i32 [ 0, %.lr.ph.new ], [ %niter.next.1, %42 ]
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %9, %44
  %46 = srem i64 %45, 1000000007
  %47 = trunc nsw i64 %46 to i32
  %48 = add nsw i32 %spec.select141618, %47
  %49 = icmp sgt i32 %48, 1000000006
  %50 = add nsw i32 %48, -1000000007
  %spec.select14 = select i1 %49, i32 %50, i32 %48
  %51 = mul nsw i64 %46, %9
  %52 = srem i64 %51, 1000000007
  %53 = trunc nsw i64 %52 to i32
  %54 = add nsw i32 %spec.select14, %53
  %55 = icmp sgt i32 %54, 1000000006
  %56 = add nsw i32 %54, -1000000007
  %spec.select14.1 = select i1 %55, i32 %56, i32 %54
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %42, !llvm.loop !11

._crit_edge24:                                    ; preds = %18, %.lr.ph28.._crit_edge24_crit_edge
  %57 = phi i32 [ %.pre32, %.lr.ph28.._crit_edge24_crit_edge ], [ %34, %18 ]
  %58 = phi i32 [ %.pre31, %.lr.ph28.._crit_edge24_crit_edge ], [ %39, %18 ]
  %59 = add nsw i32 %57, %58
  %60 = icmp sgt i32 %59, 1000000006
  %61 = add nsw i32 %59, -1000000007
  %spec.select15 = select i1 %60, i32 %61, i32 %59
  store i32 %spec.select15, ptr @ans, align 4, !tbaa !5
  %62 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.0526, i32 noundef %spec.select15)
  %63 = add nuw nsw i32 %.0526, 1
  %64 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.0526, %64
  br i1 %.not.not, label %.lr.ph28, label %._crit_edge29, !llvm.loop !12
}

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

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

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

!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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass