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

; 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
@dx = external dso_local global i32, align 4
@dy = external dso_local global i32, align 4
@f = external dso_local global [2333333 x i32], align 16
@cnt = external dso_local global [2333333 x i32], align 16
@ans = external dso_local global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @dx, ptr noundef @dy)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %40, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr @dx, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sge i32 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %13
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sub nsw i32 %26, %25
  store i32 %27, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %24, %13
  %29 = load i32, ptr @dy, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %28
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sub nsw i32 %37, %36
  store i32 %38, ptr %4, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %35, %28
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

43:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  br label %44

44:                                               ; preds = %95, %43
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %98

48:                                               ; preds = %44
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5, ptr noundef %6)
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sub nsw i32 %54, %53
  store i32 %55, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %48
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %6, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %58, %48
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2333333 x i32], ptr @cnt, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %65, align 4, !tbaa !5
  %68 = load i32, ptr @ans, align 4, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2333333 x i32], ptr @cnt, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp slt i32 %68, %72
  br i1 %73, label %74, label %94

74:                                               ; preds = %62
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [2333333 x i32], ptr @cnt, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  store i32 %78, ptr @ans, align 4, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %79, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 1), align 4, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = add nsw i32 %80, %84
  store i32 %85, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 2), align 4, !tbaa !5
  %86 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 2), align 4, !tbaa !5
  %87 = load i32, ptr @n, align 4, !tbaa !5
  %88 = icmp sge i32 %86, %87
  br i1 %88, label %89, label %93

89:                                               ; preds = %74
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 2), align 4, !tbaa !5
  %92 = sub nsw i32 %91, %90
  store i32 %92, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 2), align 4, !tbaa !5
  br label %93

93:                                               ; preds = %89, %74
  br label %94

94:                                               ; preds = %93, %62
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr @m, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr @m, align 4, !tbaa !5
  br label %44, !llvm.loop !11

98:                                               ; preds = %47
  %99 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 1), align 4, !tbaa !5
  %100 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @ans, i64 0, i64 2), align 4, !tbaa !5
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %99, i32 noundef %100)
  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
@dx = external dso_local global i32, align 4
@dy = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@cnt = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@ans = external dso_local local_unnamed_addr global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %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 @dx, ptr noundef nonnull @dy)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %6 = load i32, ptr @dx, align 4, !tbaa !5
  %7 = load i32, ptr @dy, align 4, !tbaa !5
  %xtraiter = and i32 %4, 1
  %8 = icmp eq i32 %4, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i32 %4, 2147483646
  br label %11

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %11
  %9 = sext i32 %spec.select.1 to i64
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph
  %.029.unr = phi i32 [ 0, %.lr.ph ], [ %.1.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01028.unr = phi i64 [ 0, %.lr.ph ], [ %9, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %10 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %.01028.unr
  store i32 %.029.unr, ptr %10, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %.pr = load i32, ptr @m, align 4, !tbaa !5
  %.not30 = icmp eq i32 %.pr, 0
  br i1 %.not30, label %._crit_edge33, label %.lr.ph32

11:                                               ; preds = %11, %.lr.ph.new
  %.029 = phi i32 [ 0, %.lr.ph.new ], [ %.1.1, %11 ]
  %.01028 = phi i32 [ 0, %.lr.ph.new ], [ %spec.select.1, %11 ]
  %niter = phi i32 [ 0, %.lr.ph.new ], [ %niter.next.1, %11 ]
  %12 = sext i32 %.01028 to i64
  %13 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %12
  store i32 %.029, ptr %13, align 4, !tbaa !5
  %14 = add nsw i32 %6, %.01028
  %.not24 = icmp slt i32 %14, %4
  %15 = select i1 %.not24, i32 0, i32 %4
  %spec.select = sub nsw i32 %14, %15
  %16 = add nsw i32 %7, %.029
  %.not25 = icmp slt i32 %16, %4
  %17 = select i1 %.not25, i32 0, i32 %4
  %.1 = sub nsw i32 %16, %17
  %18 = sext i32 %spec.select to i64
  %19 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %18
  store i32 %.1, ptr %19, align 4, !tbaa !5
  %20 = add nsw i32 %6, %spec.select
  %.not24.1 = icmp slt i32 %20, %4
  %21 = select i1 %.not24.1, i32 0, i32 %4
  %spec.select.1 = sub nsw i32 %20, %21
  %22 = add nsw i32 %7, %.1
  %.not25.1 = icmp slt i32 %22, %4
  %23 = select i1 %.not25.1, i32 0, i32 %4
  %.1.1 = sub nsw i32 %22, %23
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %11, !llvm.loop !9

._crit_edge33:                                    ; preds = %50, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !5
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 4, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %24, i32 noundef %25)
  ret i32 0

.lr.ph32:                                         ; preds = %._crit_edge, %50
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2333333 x i32], ptr @f, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sub nsw i32 %32, %31
  store i32 %33, ptr %2, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %.lr.ph32
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = add nsw i32 %36, %33
  store i32 %37, ptr %2, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %35, %.lr.ph32
  %39 = phi i32 [ %37, %35 ], [ %33, %.lr.ph32 ]
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2333333 x i32], ptr @cnt, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !5
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %.not26 = icmp sgt i32 %44, %42
  br i1 %.not26, label %50, label %45

45:                                               ; preds = %38
  store i32 %43, ptr @ans, align 4, !tbaa !5
  store i32 %28, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !5
  %46 = add nsw i32 %39, %31
  store i32 %46, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 4, !tbaa !5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %.not23 = icmp slt i32 %46, %47
  br i1 %.not23, label %50, label %48

48:                                               ; preds = %45
  %49 = sub nsw i32 %46, %47
  store i32 %49, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 4, !tbaa !5
  br label %50

50:                                               ; preds = %38, %48, %45
  %51 = load i32, ptr @m, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %52, 0
  br i1 %.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !11
}

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

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

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

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


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