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

; 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
@t = external dso_local global i32, align 4
@pw = external dso_local global [100001 x i32], align 16
@m = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@f = external dso_local global [100001 x i32], align 16
@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 [6 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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @t)
  store i32 1, ptr @pw, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %24, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 100001
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = mul nsw i32 %17, %18
  %20 = srem i32 %19, 10000
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  br label %24

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

27:                                               ; preds = %11
  br label %28

28:                                               ; preds = %122, %27
  %29 = load i32, ptr @t, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @t, align 4, !tbaa !5
  %31 = icmp ne i32 %29, 0
  br i1 %31, label %32, label %125

32:                                               ; preds = %28
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %44, %32
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %47

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @a, i64 %41
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %42)
  br label %44

44:                                               ; preds = %39
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %34, !llvm.loop !11

47:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %95, %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %98

53:                                               ; preds = %48
  br label %54

54:                                               ; preds = %69, %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %54
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp ne i32 %61, %65
  br label %67

67:                                               ; preds = %57, %54
  %68 = phi i1 [ false, %54 ], [ %66, %57 ]
  br i1 %68, label %69, label %74

69:                                               ; preds = %67
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  store i32 %73, ptr %5, align 4, !tbaa !5
  br label %54, !llvm.loop !12

74:                                               ; preds = %67
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = icmp eq i32 %78, %82
  br i1 %83, label %84, label %87

84:                                               ; preds = %74
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %5, align 4, !tbaa !5
  br label %89

87:                                               ; preds = %74
  %88 = load i32, ptr %5, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %87, %84
  %90 = phi i32 [ %86, %84 ], [ %88, %87 ]
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %93
  store i32 %90, ptr %94, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %89
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %4, align 4, !tbaa !5
  br label %48, !llvm.loop !13

98:                                               ; preds = %52
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %99 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %99, ptr %6, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %117, %98
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %104, label %103

103:                                              ; preds = %100
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %122

104:                                              ; preds = %100
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = load i32, ptr @ans, align 4, !tbaa !5
  %110 = add nsw i32 %109, %108
  store i32 %110, ptr @ans, align 4, !tbaa !5
  %111 = load i32, ptr @ans, align 4, !tbaa !5
  %112 = icmp sge i32 %111, 10000
  br i1 %112, label %113, label %116

113:                                              ; preds = %104
  %114 = load i32, ptr @ans, align 4, !tbaa !5
  %115 = sub nsw i32 %114, 10000
  store i32 %115, ptr @ans, align 4, !tbaa !5
  br label %116

116:                                              ; preds = %113, %104
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %6, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %119
  %121 = load i32, ptr %120, align 4, !tbaa !5
  store i32 %121, ptr %6, align 4, !tbaa !5
  br label %100, !llvm.loop !14

122:                                              ; preds = %103
  %123 = load i32, ptr @ans, align 4, !tbaa !5
  %124 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %123)
  br label %28, !llvm.loop !15

125:                                              ; preds = %28
  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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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
@t = external dso_local global i32, align 4
@pw = external dso_local local_unnamed_addr global [100001 x i32], align 16
@m = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@f = external dso_local local_unnamed_addr global [100001 x i32], align 16
@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 [6 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 @n, ptr noundef nonnull @t)
  store i32 1, ptr @pw, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  br label %5

.preheader30:                                     ; preds = %5
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not49 = icmp eq i32 %3, 0
  br i1 %.not49, label %._crit_edge51, label %.lr.ph50

5:                                                ; preds = %5, %0
  %6 = phi i32 [ 1, %0 ], [ %11, %5 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %5 ]
  %7 = mul nsw i32 %2, %6
  %8 = srem i32 %7, 10000
  %9 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %indvars.iv
  store i32 %8, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = mul nsw i32 %2, %8
  %11 = srem i32 %10, 10000
  %12 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %indvars.iv.next
  store i32 %11, ptr %12, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 100001
  br i1 %exitcond.not.1, label %.preheader30, label %5, !llvm.loop !9

.lr.ph50:                                         ; preds = %.preheader30, %35
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m)
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.preheader29:                                     ; preds = %.lr.ph
  %16 = icmp sgt i32 %19, 1
  br i1 %16, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %.preheader29
  %wide.trip.count = zext nneg i32 %19 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph50, %.lr.ph
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %.lr.ph ], [ 0, %.lr.ph50 ]
  %17 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv54
  %18 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %17)
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next55, %20
  br i1 %21, label %.lr.ph, label %.preheader29, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %indvars.iv57 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next58, %.critedge ]
  %.02140 = phi i32 [ 0, %.preheader.preheader ], [ %33, %.critedge ]
  %.not2733 = icmp eq i32 %.02140, 0
  %.phi.trans.insert = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv57
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br i1 %.not2733, label %.critedge, label %.lr.ph35

._crit_edge:                                      ; preds = %.critedge, %.lr.ph50, %.preheader29
  %.04262 = phi i32 [ %19, %.preheader29 ], [ %14, %.lr.ph50 ], [ %19, %.critedge ]
  store i32 0, ptr @ans, align 4, !tbaa !5
  %.not2643 = icmp eq i32 %.04262, 0
  br i1 %.not2643, label %35, label %.lr.ph47

.lr.ph35:                                         ; preds = %.preheader, %25
  %.134 = phi i32 [ %27, %25 ], [ %.02140, %.preheader ]
  %22 = sext i32 %.134 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not28 = icmp eq i32 %.pre, %24
  br i1 %.not28, label %.critedge, label %25

25:                                               ; preds = %.lr.ph35
  %26 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %22
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not27 = icmp eq i32 %27, 0
  br i1 %.not27, label %.critedge, label %.lr.ph35, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph35, %25, %.preheader
  %.1.lcssa = phi i32 [ 0, %.preheader ], [ 0, %25 ], [ %.134, %.lr.ph35 ]
  %28 = sext i32 %.1.lcssa to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp eq i32 %.pre, %30
  %32 = zext i1 %31 to i32
  %33 = add nsw i32 %.1.lcssa, %32
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %34 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %indvars.iv.next58
  store i32 %33, ptr %34, align 4, !tbaa !5
  %exitcond60.not = icmp eq i64 %indvars.iv.next58, %wide.trip.count
  br i1 %exitcond60.not, label %._crit_edge, label %.preheader, !llvm.loop !13

._crit_edge48:                                    ; preds = %.lr.ph47
  store i32 %spec.select, ptr @ans, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %._crit_edge48, %._crit_edge
  %36 = phi i32 [ %spec.select, %._crit_edge48 ], [ 0, %._crit_edge ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %36)
  %38 = load i32, ptr @t, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %38, 0
  br i1 %.not, label %._crit_edge51, label %.lr.ph50, !llvm.loop !14

.lr.ph47:                                         ; preds = %._crit_edge, %.lr.ph47
  %.045 = phi i32 [ %.0, %.lr.ph47 ], [ %.04262, %._crit_edge ]
  %spec.select4144 = phi i32 [ %spec.select, %.lr.ph47 ], [ 0, %._crit_edge ]
  %40 = sext i32 %.045 to i64
  %41 = getelementptr inbounds [100001 x i32], ptr @pw, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %spec.select4144, %42
  %44 = icmp sgt i32 %43, 9999
  %45 = add nsw i32 %43, -10000
  %spec.select = select i1 %44, i32 %45, i32 %43
  %46 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %40
  %.0 = load i32, ptr %46, align 4, !tbaa !5
  %.not26 = icmp eq i32 %.0, 0
  br i1 %.not26, label %._crit_edge48, label %.lr.ph47, !llvm.loop !15

._crit_edge51:                                    ; preds = %35, %.preheader30
  ret i32 0
}

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


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