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

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

@inv = external dso_local global [1000001 x i32], align 16
@ans = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 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
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = load i64, ptr @m, align 8, !tbaa !5
  %6 = icmp sgt i64 %4, %5
  br i1 %6, label %7, label %17

7:                                                ; preds = %0
  %8 = load i64, ptr @n, align 8, !tbaa !5
  %9 = load i64, ptr @m, align 8, !tbaa !5
  %10 = add nsw i64 %8, %9
  store i64 %10, ptr @n, align 8, !tbaa !5
  %11 = load i64, ptr @n, align 8, !tbaa !5
  %12 = load i64, ptr @m, align 8, !tbaa !5
  %13 = sub nsw i64 %11, %12
  store i64 %13, ptr @m, align 8, !tbaa !5
  %14 = load i64, ptr @n, align 8, !tbaa !5
  %15 = load i64, ptr @m, align 8, !tbaa !5
  %16 = sub nsw i64 %14, %15
  store i64 %16, ptr @n, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %7, %0
  %18 = load i64, ptr @n, align 8, !tbaa !5
  %19 = load i64, ptr @m, align 8, !tbaa !5
  %20 = add nsw i64 %18, %19
  %21 = add nsw i64 %20, 1
  %22 = srem i64 %21, 1000000007
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr @ans, align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds ([1000001 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %67, %17
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr @n, align 8, !tbaa !5
  %28 = icmp sle i64 %26, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %24
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = sdiv i64 1000000007, %32
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = srem i32 1000000007, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %33, %39
  %41 = srem i64 %40, 1000000007
  %42 = sub nsw i64 1000000007, %41
  %43 = trunc i64 %42 to i32
  %44 = load i32, ptr %2, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !9
  %47 = load i64, ptr @n, align 8, !tbaa !5
  %48 = load i64, ptr @m, align 8, !tbaa !5
  %49 = add nsw i64 %47, %48
  %50 = add nsw i64 %49, 2
  %51 = load i32, ptr %2, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = sub nsw i64 %50, %52
  %54 = srem i64 %53, 1000000007
  %55 = load i32, ptr @ans, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %54, %56
  %58 = srem i64 %57, 1000000007
  %59 = load i32, ptr %2, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = mul nsw i64 %58, %63
  %65 = srem i64 %64, 1000000007
  %66 = trunc i64 %65 to i32
  store i32 %66, ptr @ans, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %30
  %68 = load i32, ptr %2, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %2, align 4, !tbaa !9
  br label %24, !llvm.loop !11

70:                                               ; preds = %29
  %71 = load i32, ptr @ans, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = load i64, ptr @m, align 8, !tbaa !5
  %74 = add nsw i64 %72, %73
  %75 = srem i64 %74, 1000000007
  %76 = trunc i64 %75 to i32
  store i32 %76, ptr @ans, align 4, !tbaa !9
  %77 = load i32, ptr @ans, align 4, !tbaa !9
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %77)
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@inv = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 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 i64, ptr @n, align 8, !tbaa !5
  %3 = load i64, ptr @m, align 8, !tbaa !5
  %4 = icmp sgt i64 %2, %3
  %5 = add nsw i64 %3, %2
  br i1 %4, label %6, label %._crit_edge13

6:                                                ; preds = %0
  store i64 %2, ptr @m, align 8, !tbaa !5
  store i64 %3, ptr @n, align 8, !tbaa !5
  br label %._crit_edge13

._crit_edge13:                                    ; preds = %0, %6
  %7 = phi i64 [ %2, %6 ], [ %3, %0 ]
  %8 = phi i64 [ %3, %6 ], [ %2, %0 ]
  %9 = add nsw i64 %5, 1
  %10 = srem i64 %9, 1000000007
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !9
  %.not10 = icmp slt i64 %8, 2
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %._crit_edge13
  %11 = add nsw i64 %5, 2
  br label %17

._crit_edge:                                      ; preds = %17, %._crit_edge13
  %12 = phi i64 [ %10, %._crit_edge13 ], [ %37, %17 ]
  %13 = add nsw i64 %7, %12
  %14 = srem i64 %13, 1000000007
  %15 = trunc nsw i64 %14 to i32
  store i32 %15, ptr @ans, align 4, !tbaa !9
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %15)
  ret i32 0

17:                                               ; preds = %.lr.ph, %17
  %indvars.iv = phi i64 [ 2, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %18 = phi i64 [ %10, %.lr.ph ], [ %37, %17 ]
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = udiv i32 1000000007, %19
  %.zext = zext nneg i32 %20 to i64
  %21 = urem i32 1000000007, %19
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %25, %.zext
  %27 = srem i64 %26, 1000000007
  %28 = trunc nsw i64 %27 to i32
  %29 = sub nsw i32 1000000007, %28
  %30 = getelementptr inbounds [1000001 x i32], ptr @inv, i64 0, i64 %indvars.iv
  store i32 %29, ptr %30, align 4, !tbaa !9
  %31 = sub i64 %11, %indvars.iv
  %32 = srem i64 %31, 1000000007
  %33 = mul nsw i64 %32, %18
  %34 = srem i64 %33, 1000000007
  %35 = zext nneg i32 %29 to i64
  %36 = mul nsw i64 %34, %35
  %37 = srem i64 %36, 1000000007
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv, %8
  br i1 %exitcond, label %._crit_edge, label %17, !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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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