; LLVM IR from tangjz/acm-icpc :: codeforces/complete (543A)

; 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
@b = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@f = external dso_local global [555 x [555 x i32]], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @b, ptr noundef @mod)
  store i32 1, ptr @f, 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 %10

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

14:                                               ; preds = %10
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %57

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %50, %15
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %23 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %23, ptr %6, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %46, %22
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr @b, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %49

29:                                               ; preds = %24
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [555 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sub nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [555 x i32], ptr %39, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %35, i32 noundef %45)
  br label %46

46:                                               ; preds = %29
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !5
  br label %24, !llvm.loop !9

49:                                               ; preds = %28
  br label %50

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

53:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !12

57:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %71, %57
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = load i32, ptr @b, align 4, !tbaa !5
  %61 = icmp sle i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %74

63:                                               ; preds = %58
  %64 = load i32, ptr @m, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %65
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [555 x i32], ptr %66, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %7, i32 noundef %70)
  br label %71

71:                                               ; preds = %63
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %8, align 4, !tbaa !5
  br label %58, !llvm.loop !13

74:                                               ; preds = %62
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %75)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %77 = load i32, ptr %1, align 4
  ret i32 %77
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

declare i32 @printf(ptr noundef, ...) #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 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@f = external dso_local global [555 x [555 x i32]], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

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

._crit_edge31:                                    ; preds = %._crit_edge26, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @b, align 4, !tbaa !5
  %.not1732 = icmp slt i32 %5, 0
  br i1 %.not1732, label %._crit_edge36, label %.lr.ph35

.lr.ph30:                                         ; preds = %0, %._crit_edge26
  %.01628 = phi i32 [ %11, %._crit_edge26 ], [ 1, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %.not1822 = icmp slt i32 %7, 1
  br i1 %.not1822, label %._crit_edge26, label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph30
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr @b, align 4, !tbaa !5
  %10 = icmp sgt i32 %8, %9
  br i1 %10, label %._crit_edge26, label %.lr.ph25.split

._crit_edge26:                                    ; preds = %._crit_edge, %.lr.ph25, %.lr.ph30
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %11 = add nuw nsw i32 %.01628, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01628, %12
  br i1 %.not.not, label %.lr.ph30, label %._crit_edge31, !llvm.loop !9

.lr.ph25.split:                                   ; preds = %.lr.ph25, %._crit_edge
  %13 = phi i32 [ %18, %._crit_edge ], [ %7, %.lr.ph25 ]
  %14 = phi i32 [ %19, %._crit_edge ], [ %9, %.lr.ph25 ]
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %._crit_edge ], [ 1, %.lr.ph25 ]
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %.not1920 = icmp sgt i32 %15, %14
  br i1 %.not1920, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph25.split
  %16 = add nsw i64 %indvars.iv39, -1
  %17 = sext i32 %15 to i64
  br label %21

._crit_edge.loopexit:                             ; preds = %21
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph25.split
  %18 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %13, %.lr.ph25.split ]
  %19 = phi i32 [ %28, %._crit_edge.loopexit ], [ %14, %.lr.ph25.split ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %20 = sext i32 %18 to i64
  %.not18.not = icmp slt i64 %indvars.iv39, %20
  br i1 %.not18.not, label %.lr.ph25.split, label %._crit_edge26, !llvm.loop !11

21:                                               ; preds = %.lr.ph, %21
  %indvars.iv = phi i64 [ %17, %.lr.ph ], [ %indvars.iv.next, %21 ]
  %22 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %indvars.iv39, i64 %indvars.iv
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = sub nsw i64 %indvars.iv, %24
  %26 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %16, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %22, i32 noundef %27)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %28 = load i32, ptr @b, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %.not19.not = icmp slt i64 %indvars.iv, %29
  br i1 %.not19.not, label %21, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge36.loopexit:                           ; preds = %.lr.ph35
  %.pre45 = load i32, ptr %2, align 4, !tbaa !5
  br label %._crit_edge36

._crit_edge36:                                    ; preds = %._crit_edge36.loopexit, %._crit_edge31
  %30 = phi i32 [ %.pre45, %._crit_edge36.loopexit ], [ 0, %._crit_edge31 ]
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %30)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret i32 0

.lr.ph35:                                         ; preds = %._crit_edge31, %.lr.ph35
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.lr.ph35 ], [ 0, %._crit_edge31 ]
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [555 x [555 x i32]], ptr @f, i64 0, i64 %33, i64 %indvars.iv42
  %35 = load i32, ptr %34, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %35)
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %36 = load i32, ptr @b, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %.not17.not = icmp slt i64 %indvars.iv42, %37
  br i1 %.not17.not, label %.lr.ph35, label %._crit_edge36.loopexit, !llvm.loop !14
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; 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" }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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