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

; 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
@m = external dso_local global i32, align 4
@inv = external dso_local global [1000 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 [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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @m, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([1000 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %31, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sdiv i32 1000000007, %15
  %17 = sext i32 %16 to i64
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = srem i32 1000000007, %18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %17, %23
  %25 = srem i64 %24, 1000000007
  %26 = sub nsw i64 1000000007, %25
  %27 = trunc i64 %26 to i32
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %14
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

34:                                               ; preds = %13
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %35

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

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %60

40:                                               ; preds = %35
  %41 = load i32, ptr @ans, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %42, %46
  %48 = srem i64 %47, 1000000007
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = mul nsw i64 %48, %53
  %55 = srem i64 %54, 1000000007
  %56 = trunc i64 %55 to i32
  store i32 %56, ptr @ans, align 4, !tbaa !5
  br label %57

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

60:                                               ; preds = %39
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %61)
  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}


; 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
@m = external dso_local global i32, align 4
@inv = external dso_local local_unnamed_addr global [1000 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 [4 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 @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @m, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  %.not.not11 = icmp sgt i32 %4, 2
  br i1 %.not.not11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  store i32 1, ptr @ans, align 4, !tbaa !5
  %.not10.not13 = icmp sgt i32 %4, 1
  br i1 %.not10.not13, label %.lr.ph16.preheader, label %31

.lr.ph16.preheader:                               ; preds = %._crit_edge
  %6 = sext i32 %3 to i64
  %wide.trip.count22 = zext nneg i32 %4 to i64
  %7 = add nsw i64 %wide.trip.count22, -1
  %xtraiter = and i64 %7, 1
  %8 = icmp eq i32 %4, 2
  br i1 %8, label %._crit_edge17.unr-lcssa, label %.lr.ph16.preheader.new

.lr.ph16.preheader.new:                           ; preds = %.lr.ph16.preheader
  %unroll_iter = and i64 %7, -2
  br label %.lr.ph16

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = udiv i32 1000000007, %9
  %11 = zext nneg i32 %10 to i64
  %12 = urem i32 1000000007, %9
  %13 = zext nneg i32 %12 to i64
  %14 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul nsw i64 %16, %11
  %18 = srem i64 %17, 1000000007
  %19 = trunc nsw i64 %18 to i32
  %20 = sub nsw i32 1000000007, %19
  %21 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %indvars.iv
  store i32 %20, ptr %21, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge17.unr-lcssa:                          ; preds = %.lr.ph16, %.lr.ph16.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph16.preheader ], [ %50, %.lr.ph16 ]
  %indvars.iv19.unr = phi i64 [ 1, %.lr.ph16.preheader ], [ %indvars.iv.next20.1, %.lr.ph16 ]
  %.unr = phi i64 [ 1, %.lr.ph16.preheader ], [ %50, %.lr.ph16 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge17, label %.lr.ph16.epil

.lr.ph16.epil:                                    ; preds = %._crit_edge17.unr-lcssa
  %22 = add nsw i64 %indvars.iv19.unr, %6
  %23 = mul nsw i64 %.unr, %22
  %24 = srem i64 %23, 1000000007
  %25 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %indvars.iv19.unr
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = mul nsw i64 %24, %27
  %29 = srem i64 %28, 1000000007
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %._crit_edge17.unr-lcssa, %.lr.ph16.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge17.unr-lcssa ], [ %29, %.lr.ph16.epil ]
  %30 = trunc nsw i64 %.lcssa to i32
  store i32 %30, ptr @ans, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %._crit_edge17, %._crit_edge
  %32 = phi i32 [ %30, %._crit_edge17 ], [ 1, %._crit_edge ]
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %32)
  ret i32 0

.lr.ph16:                                         ; preds = %.lr.ph16, %.lr.ph16.preheader.new
  %indvars.iv19 = phi i64 [ 1, %.lr.ph16.preheader.new ], [ %indvars.iv.next20.1, %.lr.ph16 ]
  %34 = phi i64 [ 1, %.lr.ph16.preheader.new ], [ %50, %.lr.ph16 ]
  %niter = phi i64 [ 0, %.lr.ph16.preheader.new ], [ %niter.next.1, %.lr.ph16 ]
  %35 = add nsw i64 %indvars.iv19, %6
  %36 = mul nsw i64 %34, %35
  %37 = srem i64 %36, 1000000007
  %38 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %indvars.iv19
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %37, %40
  %42 = srem i64 %41, 1000000007
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %43 = add nsw i64 %indvars.iv.next20, %6
  %44 = mul nsw i64 %42, %43
  %45 = srem i64 %44, 1000000007
  %46 = getelementptr inbounds [1000 x i32], ptr @inv, i64 0, i64 %indvars.iv.next20
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = mul nsw i64 %45, %48
  %50 = srem i64 %49, 1000000007
  %indvars.iv.next20.1 = add nuw nsw i64 %indvars.iv19, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge17.unr-lcssa, label %.lr.ph16, !llvm.loop !11
}

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


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