; LLVM IR from tangjz/acm-icpc :: codechef/MAY18 (DBFB)

; 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
@m = external dso_local global i32, align 4
@cur = external dso_local global i32, align 4
@pre = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@sum = 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 [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
  %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)
  br label %6

6:                                                ; preds = %81, %0
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %103

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m, ptr noundef @n)
  store i32 1, ptr @pre, align 4, !tbaa !5
  store i32 0, ptr @cur, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %28, %10
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %31

17:                                               ; preds = %12
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @cur, ptr noundef nonnull align 4 dereferenceable(4) @pre) #4
  %18 = load i32, ptr @pre, align 4, !tbaa !5
  %19 = load i32, ptr @cur, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr @cur, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 1000000007
  br i1 %21, label %22, label %26

22:                                               ; preds = %17
  %23 = load i32, ptr @cur, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1000000007
  store i32 %24, ptr @cur, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br label %26

26:                                               ; preds = %22, %17
  %27 = phi i1 [ false, %17 ], [ %25, %22 ]
  br label %28

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

31:                                               ; preds = %16
  store i32 0, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %32

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

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

37:                                               ; preds = %32
  %38 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = load i32, ptr @sum, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr @sum, align 4, !tbaa !5
  %42 = icmp sge i32 %41, 1000000007
  br i1 %42, label %43, label %47

43:                                               ; preds = %37
  %44 = load i32, ptr @sum, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1000000007
  store i32 %45, ptr @sum, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br label %47

47:                                               ; preds = %43, %37
  %48 = phi i1 [ false, %37 ], [ %46, %43 ]
  br label %49

49:                                               ; preds = %47
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %32, !llvm.loop !11

52:                                               ; preds = %36
  %53 = load i32, ptr @sum, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = mul nsw i64 1, %54
  %56 = load i32, ptr @pre, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %55, %57
  %59 = srem i64 %58, 1000000007
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %78, %52
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

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

66:                                               ; preds = %61
  %67 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %68 = load i32, ptr @x, align 4, !tbaa !5
  %69 = load i32, ptr @sum, align 4, !tbaa !5
  %70 = add nsw i32 %69, %68
  store i32 %70, ptr @sum, align 4, !tbaa !5
  %71 = icmp sge i32 %70, 1000000007
  br i1 %71, label %72, label %76

72:                                               ; preds = %66
  %73 = load i32, ptr @sum, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1000000007
  store i32 %74, ptr @sum, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br label %76

76:                                               ; preds = %72, %66
  %77 = phi i1 [ false, %66 ], [ %75, %72 ]
  br label %78

78:                                               ; preds = %76
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %4, align 4, !tbaa !5
  br label %61, !llvm.loop !12

81:                                               ; preds = %65
  %82 = load i32, ptr @ans, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = load i32, ptr @sum, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = mul nsw i64 1, %85
  %87 = load i32, ptr @cur, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = mul nsw i64 %86, %88
  %90 = add nsw i64 %83, %89
  %91 = srem i64 %90, 1000000007
  %92 = trunc i64 %91 to i32
  store i32 %92, ptr @ans, align 4, !tbaa !5
  %93 = load i32, ptr @ans, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = mul nsw i64 1, %94
  %96 = load i32, ptr @m, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = mul nsw i64 %95, %97
  %99 = srem i64 %98, 1000000007
  %100 = trunc i64 %99 to i32
  store i32 %100, ptr @ans, align 4, !tbaa !5
  %101 = load i32, ptr @ans, align 4, !tbaa !5
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %101)
  br label %6, !llvm.loop !13

103:                                              ; preds = %6
  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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

; 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 = { inlinehint mustprogress 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 #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}
!13 = distinct !{!13, !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
@m = external dso_local global i32, align 4
@cur = external dso_local global i32, align 4
@pre = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@sum = 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 [4 x i8], align 1

; Function Attrs: mustprogress 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
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not24 = icmp eq i32 %2, 0
  br i1 %.not24, label %._crit_edge27, label %.lr.ph26

.lr.ph26:                                         ; preds = %0, %._crit_edge23
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m, ptr noundef nonnull @n)
  store i32 1, ptr @pre, align 4, !tbaa !5
  store i32 0, ptr @cur, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph26
  %7 = phi i32 [ 1, %.lr.ph26 ], [ %10, %.lr.ph ]
  store i32 0, ptr @sum, align 4, !tbaa !5
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph18, label %._crit_edge19

.lr.ph:                                           ; preds = %.lr.ph26, %.lr.ph
  %.0715 = phi i32 [ %15, %.lr.ph ], [ 1, %.lr.ph26 ]
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @cur, ptr noundef nonnull align 4 dereferenceable(4) @pre) #3
  %10 = load i32, ptr @pre, align 4, !tbaa !5
  %11 = load i32, ptr @cur, align 4, !tbaa !5
  %12 = add nsw i32 %11, %10
  %13 = icmp sgt i32 %12, 1000000006
  %14 = add nsw i32 %12, -1000000007
  %spec.select = select i1 %13, i32 %14, i32 %12
  store i32 %spec.select, ptr @cur, align 4, !tbaa !5
  %15 = add nuw nsw i32 %.0715, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge19.loopexit:                           ; preds = %.lr.ph18
  %.pre = load i32, ptr @pre, align 4, !tbaa !5
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %._crit_edge19.loopexit, %._crit_edge
  %18 = phi i32 [ %34, %._crit_edge19.loopexit ], [ %8, %._crit_edge ]
  %19 = phi i32 [ %.pre, %._crit_edge19.loopexit ], [ %7, %._crit_edge ]
  %20 = phi i32 [ %spec.select13, %._crit_edge19.loopexit ], [ 0, %._crit_edge ]
  %21 = sext i32 %20 to i64
  %22 = sext i32 %19 to i64
  %23 = mul nsw i64 %22, %21
  %24 = srem i64 %23, 1000000007
  %25 = trunc nsw i64 %24 to i32
  store i32 %25, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @sum, align 4, !tbaa !5
  %26 = icmp sgt i32 %18, 0
  br i1 %26, label %.lr.ph22, label %._crit_edge23

.lr.ph18:                                         ; preds = %._crit_edge, %.lr.ph18
  %.0616 = phi i32 [ %33, %.lr.ph18 ], [ 0, %._crit_edge ]
  %27 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %28 = load i32, ptr @x, align 4, !tbaa !5
  %29 = load i32, ptr @sum, align 4, !tbaa !5
  %30 = add nsw i32 %29, %28
  %31 = icmp sgt i32 %30, 1000000006
  %32 = add nsw i32 %30, -1000000007
  %spec.select13 = select i1 %31, i32 %32, i32 %30
  store i32 %spec.select13, ptr @sum, align 4, !tbaa !5
  %33 = add nuw nsw i32 %.0616, 1
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %.lr.ph18, label %._crit_edge19.loopexit, !llvm.loop !11

._crit_edge23.loopexit:                           ; preds = %.lr.ph22
  %.pre29 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit, %._crit_edge19
  %36 = phi i32 [ 0, %._crit_edge19 ], [ %spec.select14, %._crit_edge23.loopexit ]
  %37 = phi i32 [ %25, %._crit_edge19 ], [ %.pre29, %._crit_edge23.loopexit ]
  %.lcssa = phi i32 [ %18, %._crit_edge19 ], [ %59, %._crit_edge23.loopexit ]
  %38 = sext i32 %37 to i64
  %39 = sext i32 %36 to i64
  %40 = load i32, ptr @cur, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %41, %39
  %43 = add nsw i64 %42, %38
  %44 = srem i64 %43, 1000000007
  %45 = sext i32 %.lcssa to i64
  %46 = mul nsw i64 %44, %45
  %47 = srem i64 %46, 1000000007
  %48 = trunc nsw i64 %47 to i32
  store i32 %48, ptr @ans, align 4, !tbaa !5
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %48)
  %50 = load i32, ptr @t, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %50, 0
  br i1 %.not, label %._crit_edge27, label %.lr.ph26, !llvm.loop !12

.lr.ph22:                                         ; preds = %._crit_edge19, %.lr.ph22
  %.020 = phi i32 [ %58, %.lr.ph22 ], [ 0, %._crit_edge19 ]
  %52 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %53 = load i32, ptr @x, align 4, !tbaa !5
  %54 = load i32, ptr @sum, align 4, !tbaa !5
  %55 = add nsw i32 %54, %53
  %56 = icmp sgt i32 %55, 1000000006
  %57 = add nsw i32 %55, -1000000007
  %spec.select14 = select i1 %56, i32 %57, i32 %55
  store i32 %spec.select14, ptr @sum, align 4, !tbaa !5
  %58 = add nuw nsw i32 %.020, 1
  %59 = load i32, ptr @m, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %.lr.ph22, label %._crit_edge23.loopexit, !llvm.loop !13

._crit_edge27:                                    ; preds = %._crit_edge23, %0
  ret i32 0
}

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

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

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

attributes #0 = { mustprogress 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" }
attributes #2 = { inlinehint mustprogress 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 #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}


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