; LLVM IR from tangjz/acm-icpc :: codeforces/complete (701B)

; 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
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@cR = external dso_local global i64, align 8
@cC = external dso_local global i64, align 8
@row = external dso_local global [100001 x i8], align 16
@col = external dso_local global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  store i64 %4, ptr @cC, align 8, !tbaa !9
  store i64 %4, ptr @cR, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %31, %0
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @m, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %45

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x, ptr noundef @y)
  %11 = load i32, ptr @x, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100001 x i8], ptr @row, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11, !range !13, !noundef !14
  %15 = trunc i8 %14 to i1
  br i1 %15, label %19, label %16

16:                                               ; preds = %9
  %17 = load i64, ptr @cR, align 8, !tbaa !9
  %18 = add nsw i64 %17, -1
  store i64 %18, ptr @cR, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %16, %9
  %20 = load i32, ptr @x, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i8], ptr @row, i64 0, i64 %21
  store i8 1, ptr %22, align 1, !tbaa !11
  %23 = load i32, ptr @y, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i8], ptr @col, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11, !range !13, !noundef !14
  %27 = trunc i8 %26 to i1
  br i1 %27, label %31, label %28

28:                                               ; preds = %19
  %29 = load i64, ptr @cC, align 8, !tbaa !9
  %30 = add nsw i64 %29, -1
  store i64 %30, ptr @cC, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %28, %19
  %32 = load i32, ptr @y, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100001 x i8], ptr @col, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !11
  %35 = load i64, ptr @cR, align 8, !tbaa !9
  %36 = load i64, ptr @cC, align 8, !tbaa !9
  %37 = mul nsw i64 %35, %36
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = icmp eq i32 %38, -1
  %40 = zext i1 %39 to i64
  %41 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !15
  %43 = sext i8 %42 to i32
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %37, i32 noundef %43)
  br label %5, !llvm.loop !16

45:                                               ; preds = %5
  ret i32 0
}

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

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

!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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@cR = external dso_local local_unnamed_addr global i64, align 8
@cC = external dso_local local_unnamed_addr global i64, align 8
@row = external dso_local local_unnamed_addr global [100001 x i8], align 16
@col = external dso_local local_unnamed_addr global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 = sext i32 %2 to i64
  store i64 %3, ptr @cC, align 8, !tbaa !9
  store i64 %3, ptr @cR, align 8, !tbaa !9
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @m, align 4, !tbaa !5
  %.not1 = icmp eq i32 %4, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %23
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %7 = load i32, ptr @x, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100001 x i8], ptr @row, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = load i64, ptr @cR, align 8, !tbaa !9
  %14 = add nsw i64 %13, -1
  store i64 %14, ptr @cR, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %12, %.lr.ph
  store i8 1, ptr %9, align 1, !tbaa !11
  %16 = load i32, ptr @y, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i8], ptr @col, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11, !range !13, !noundef !14
  %20 = trunc nuw i8 %19 to i1
  %.pre = load i64, ptr @cC, align 8, !tbaa !9
  br i1 %20, label %23, label %21

21:                                               ; preds = %15
  %22 = add nsw i64 %.pre, -1
  store i64 %22, ptr @cC, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %21, %15
  %24 = phi i64 [ %22, %21 ], [ %.pre, %15 ]
  store i8 1, ptr %18, align 1, !tbaa !11
  %25 = load i64, ptr @cR, align 8, !tbaa !9
  %26 = mul nsw i64 %24, %25
  %27 = load i32, ptr @m, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -1
  %29 = zext i1 %28 to i64
  %30 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = sext i8 %31 to i32
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %26, i32 noundef %32)
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %34, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %23, %0
  ret i32 0
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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