; LLVM IR from tangjz/acm-icpc :: codeforces/complete (932E)

; 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
@a = external dso_local global [5001 x i32], align 16
@s = external dso_local global [5001 x i32], align 16
@.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 nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  store i32 1, ptr @s, align 16, !tbaa !5
  store i32 1, ptr @a, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %62, %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
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %65

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sub nsw i32 %21, %22
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %24, 1
  %26 = mul nsw i64 %20, %25
  %27 = srem i64 %26, 1000000007
  %28 = trunc i64 %27 to i32
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %32 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %32, ptr %4, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %58, %14
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp sge i32 %34, 1
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %61

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %45, %50
  %52 = add nsw i64 %43, %51
  %53 = srem i64 %52, 1000000007
  %54 = trunc i64 %53 to i32
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !5
  br label %58

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

61:                                               ; preds = %36
  store i32 0, ptr @s, align 16, !tbaa !5
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

65:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %66 = load i32, ptr @n, align 4, !tbaa !5
  %67 = call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %66)
  store i32 %67, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %94, %65
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = load i32, ptr @m, align 4, !tbaa !5
  %71 = icmp sle i32 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %68
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %102

73:                                               ; preds = %68
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = mul nsw i64 %80, %85
  %87 = srem i64 %86, 1000000007
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = mul nsw i64 %87, %89
  %91 = add nsw i64 %75, %90
  %92 = srem i64 %91, 1000000007
  %93 = trunc i64 %92 to i32
  store i32 %93, ptr %5, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %73
  %95 = load i32, ptr %7, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %7, align 4, !tbaa !5
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = mul nsw i64 %98, 500000004
  %100 = srem i64 %99, 1000000007
  %101 = trunc i64 %100 to i32
  store i32 %101, ptr %6, align 4, !tbaa !5
  br label %68, !llvm.loop !12

102:                                              ; preds = %72
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %103)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %105 = load i32, ptr %1, align 4
  ret i32 %105
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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}
!12 = distinct !{!12, !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
@a = external dso_local local_unnamed_addr global [5001 x i32], align 16
@s = external dso_local local_unnamed_addr global [5001 x i32], align 16
@.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 nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  store i32 1, ptr @s, align 16, !tbaa !5
  store i32 1, ptr @a, align 16, !tbaa !5
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %.not27 = icmp slt i32 %2, 1
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %3 = sext i32 %.pre to i64
  %4 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %4 to i64
  br label %8

._crit_edge:                                      ; preds = %.unr-lcssa, %0
  %5 = tail call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %.pre)
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %.not2529 = icmp slt i32 %6, 0
  br i1 %.not2529, label %._crit_edge35, label %.lr.ph34.preheader

.lr.ph34.preheader:                               ; preds = %._crit_edge
  %7 = add nuw i32 %6, 1
  %wide.trip.count45 = zext i32 %7 to i64
  br label %.lr.ph34

8:                                                ; preds = %.lr.ph, %.unr-lcssa
  %indvar = phi i64 [ 0, %.lr.ph ], [ %indvar.next, %.unr-lcssa ]
  %9 = phi i64 [ 1, %.lr.ph ], [ %13, %.unr-lcssa ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %.unr-lcssa ]
  %10 = sub nsw i64 %3, %indvars.iv
  %11 = add nsw i64 %10, 1
  %12 = mul nsw i64 %11, %9
  %13 = srem i64 %12, 1000000007
  %14 = trunc nsw i64 %13 to i32
  %15 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = and i64 %indvar, 1
  %lcmp.mod.not.not = icmp eq i64 %16, 0
  br i1 %lcmp.mod.not.not, label %.prol.loopexit.unr-lcssa, label %.prol.loopexit

.prol.loopexit.unr-lcssa:                         ; preds = %8
  %indvars.iv.next37.prol = add nsw i64 %indvars.iv, -1
  %17 = and i64 %indvars.iv.next37.prol, 4294967295
  %18 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %indvars.iv, %23
  %25 = add nsw i64 %24, %20
  %26 = srem i64 %25, 1000000007
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr %21, align 4, !tbaa !5
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %8
  %indvars.iv36.unr = phi i64 [ %indvars.iv, %8 ], [ %indvars.iv.next37.prol, %.prol.loopexit.unr-lcssa ]
  %28 = icmp eq i64 %indvar, 0
  br i1 %28, label %.unr-lcssa, label %.new

.unr-lcssa:                                       ; preds = %.new, %.prol.loopexit
  store i32 0, ptr @s, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond.not, label %._crit_edge, label %8, !llvm.loop !9

.new:                                             ; preds = %.prol.loopexit, %.new
  %indvars.iv36 = phi i64 [ %indvars.iv.next37.1, %.new ], [ %indvars.iv36.unr, %.prol.loopexit ]
  %indvars.iv.next37 = add nsw i64 %indvars.iv36, -1
  %29 = and i64 %indvars.iv.next37, 4294967295
  %30 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %indvars.iv36
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %indvars.iv36, %35
  %37 = add nsw i64 %36, %32
  %38 = srem i64 %37, 1000000007
  %39 = trunc nsw i64 %38 to i32
  store i32 %39, ptr %33, align 4, !tbaa !5
  %indvars.iv.next37.1 = add nsw i64 %indvars.iv36, -2
  %40 = and i64 %indvars.iv.next37.1, 4294967295
  %41 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %indvars.iv.next37
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %indvars.iv.next37, %46
  %48 = add nsw i64 %47, %43
  %49 = srem i64 %48, 1000000007
  %50 = trunc nsw i64 %49 to i32
  store i32 %50, ptr %44, align 4, !tbaa !5
  %51 = icmp sgt i64 %indvars.iv36, 2
  br i1 %51, label %.new, label %.unr-lcssa, !llvm.loop !11

._crit_edge35.loopexit:                           ; preds = %.lr.ph34
  %52 = trunc nsw i64 %65 to i32
  br label %._crit_edge35

._crit_edge35:                                    ; preds = %._crit_edge35.loopexit, %._crit_edge
  %.022.lcssa = phi i32 [ 0, %._crit_edge ], [ %52, %._crit_edge35.loopexit ]
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.022.lcssa)
  ret i32 0

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %.lr.ph34
  %indvars.iv41 = phi i64 [ 0, %.lr.ph34.preheader ], [ %indvars.iv.next42, %.lr.ph34 ]
  %.02131 = phi i32 [ %5, %.lr.ph34.preheader ], [ %68, %.lr.ph34 ]
  %.02230 = phi i64 [ 0, %.lr.ph34.preheader ], [ %65, %.lr.ph34 ]
  %54 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv41
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5001 x i32], ptr @s, i64 0, i64 %indvars.iv41
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %59, %56
  %61 = srem i64 %60, 1000000007
  %62 = sext i32 %.02131 to i64
  %63 = mul nsw i64 %61, %62
  %64 = add nsw i64 %63, %.02230
  %65 = srem i64 %64, 1000000007
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %66 = mul nsw i64 %62, 500000004
  %67 = srem i64 %66, 1000000007
  %68 = trunc nsw i64 %67 to i32
  %exitcond46.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count45
  br i1 %exitcond46.not, label %._crit_edge35.loopexit, label %.lr.ph34, !llvm.loop !12
}

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

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

attributes #0 = { 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 #1 = { 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 #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}
!12 = distinct !{!12, !10}


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