; LLVM IR from tangjz/acm-icpc :: 51nod (1969)

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

@sz = external dso_local global [2 x i32], align 4
@f = external dso_local global [2 x [30001 x i32]], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@base = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %58, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = mul nsw i32 3, %5
  %7 = sub nsw i32 %6, 1
  %8 = mul nsw i32 %4, %7
  %9 = ashr i32 %8, 1
  %10 = icmp slt i32 %9, 1000000007
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %3
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = mul nsw i32 3, %14
  %16 = sub nsw i32 %15, 1
  %17 = mul nsw i32 %13, %16
  %18 = ashr i32 %17, 1
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = and i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2 x [30001 x i32]], ptr @f, i64 0, i64 %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = and i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2 x i32], ptr @sz, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [30001 x i32], ptr %22, i64 0, i64 %29
  store i32 %18, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = mul nsw i32 3, %32
  %34 = add nsw i32 %33, 1
  %35 = mul nsw i32 %31, %34
  %36 = ashr i32 %35, 1
  %37 = icmp slt i32 %36, 1000000007
  br i1 %37, label %38, label %57

38:                                               ; preds = %12
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = mul nsw i32 3, %40
  %42 = add nsw i32 %41, 1
  %43 = mul nsw i32 %39, %42
  %44 = ashr i32 %43, 1
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = and i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x [30001 x i32]], ptr @f, i64 0, i64 %47
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = and i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2 x i32], ptr @sz, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !5
  %55 = sext i32 %53 to i64
  %56 = getelementptr inbounds [30001 x i32], ptr %48, i64 0, i64 %55
  store i32 %44, ptr %56, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %38, %12
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !9

61:                                               ; preds = %11
  %62 = load i32, ptr @sz, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr @f, i64 %63
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @f, ptr noundef %64)
  %65 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @sz, i64 0, i64 1), align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr getelementptr inbounds ([2 x [30001 x i32]], ptr @f, i64 0, i64 1), i64 %66
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds ([2 x [30001 x i32]], ptr @f, i64 0, i64 1), ptr noundef %67)
  %68 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t, ptr noundef @base)
  br label %69

69:                                               ; preds = %94, %61
  %70 = load i32, ptr @t, align 4, !tbaa !5
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr @t, align 4, !tbaa !5
  %72 = icmp ne i32 %70, 0
  br i1 %72, label %73, label %105

73:                                               ; preds = %69
  %74 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = load i32, ptr @sz, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr @f, i64 %77
  %79 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @f, ptr noundef %78, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = icmp eq i32 %75, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %73
  store i32 1, ptr @n, align 4, !tbaa !5
  br label %94

83:                                               ; preds = %73
  %84 = load i32, ptr @n, align 4, !tbaa !5
  %85 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @sz, i64 0, i64 1), align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr getelementptr inbounds ([2 x [30001 x i32]], ptr @f, i64 0, i64 1), i64 %86
  %88 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds ([2 x [30001 x i32]], ptr @f, i64 0, i64 1), ptr noundef %87, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = icmp eq i32 %84, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %83
  store i32 998244352, ptr @n, align 4, !tbaa !5
  br label %93

92:                                               ; preds = %83
  store i32 0, ptr @n, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %92, %91
  br label %94

94:                                               ; preds = %93, %82
  %95 = load i32, ptr @ans, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = load i32, ptr @base, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = mul nsw i64 %96, %98
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = add nsw i64 %99, %101
  %103 = srem i64 %102, 1000000007
  %104 = trunc i64 %103 to i32
  store i32 %104, ptr @ans, align 4, !tbaa !5
  br label %69, !llvm.loop !11

105:                                              ; preds = %69
  %106 = load i32, ptr @ans, align 4, !tbaa !5
  %107 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %106)
  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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2

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

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


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

@sz = external dso_local local_unnamed_addr global [2 x i32], align 4
@f = external dso_local global [2 x [30001 x i32]], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@base = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = 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 {
  br label %11

1:                                                ; preds = %29
  %2 = load i32, ptr @sz, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds i32, ptr @f, i64 %3
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @f, ptr noundef nonnull %4)
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @sz, i64 4), align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i32, ptr getelementptr inbounds (i8, ptr @f, i64 120004), i64 %6
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @f, i64 120004), ptr noundef nonnull %7)
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t, ptr noundef nonnull @base)
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %.not16 = icmp eq i32 %9, 0
  br i1 %.not16, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %1
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge

11:                                               ; preds = %0, %29
  %12 = phi i32 [ 0, %0 ], [ %34, %29 ]
  %13 = phi i32 [ 0, %0 ], [ %31, %29 ]
  %.015 = phi i32 [ 0, %0 ], [ %30, %29 ]
  %14 = and i32 %.015, 1
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [2 x i32], ptr @sz, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [2 x [30001 x i32]], ptr @f, i64 0, i64 %15, i64 %19
  store i32 %12, ptr %20, align 4, !tbaa !5
  %21 = add nuw nsw i32 %13, 1
  %22 = mul nuw nsw i32 %21, %.015
  %23 = icmp ult i32 %22, 2000000014
  br i1 %23, label %24, label %29

24:                                               ; preds = %11
  %25 = lshr i32 %22, 1
  %26 = add nsw i32 %17, 2
  store i32 %26, ptr %16, align 4, !tbaa !5
  %27 = sext i32 %18 to i64
  %28 = getelementptr inbounds [2 x [30001 x i32]], ptr @f, i64 0, i64 %15, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %11, %24
  %30 = add nuw nsw i32 %.015, 1
  %31 = mul nuw nsw i32 %30, 3
  %32 = add nsw i32 %31, -1
  %33 = mul nsw i32 %32, %30
  %34 = ashr i32 %33, 1
  %35 = icmp slt i32 %34, 1000000007
  br i1 %35, label %11, label %1, !llvm.loop !9

.lr.ph:                                           ; preds = %1, %52
  %36 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = load i32, ptr @sz, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr @f, i64 %39
  %41 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @f, ptr noundef nonnull %40, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %37, %42
  br i1 %43, label %52, label %44

44:                                               ; preds = %.lr.ph
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = load i32, ptr getelementptr inbounds (i8, ptr @sz, i64 4), align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr getelementptr inbounds (i8, ptr @f, i64 120004), i64 %47
  %49 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @f, i64 120004), ptr noundef nonnull %48, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp eq i32 %45, %50
  %. = select i1 %51, i32 998244352, i32 0
  %.17 = select i1 %51, i64 998244352, i64 0
  br label %52

52:                                               ; preds = %44, %.lr.ph
  %.sink = phi i32 [ 1, %.lr.ph ], [ %., %44 ]
  %53 = phi i64 [ 1, %.lr.ph ], [ %.17, %44 ]
  store i32 %.sink, ptr @n, align 4, !tbaa !5
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = load i32, ptr @base, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %57, %55
  %59 = add nsw i64 %58, %53
  %60 = srem i64 %59, 1000000007
  %61 = trunc nsw i64 %60 to i32
  store i32 %61, ptr @ans, align 4, !tbaa !5
  %62 = load i32, ptr @t, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %62, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %52, %.._crit_edge_crit_edge
  %64 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %61, %52 ]
  %65 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %64)
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

!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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass