; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1153)

; 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
@g = external dso_local global [12 x [12 x i32]], align 16
@flag = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [5 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
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(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
  store i32 0, ptr %1, align 4
  br label %7

7:                                                ; preds = %78, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %9 = icmp eq i32 %8, 2
  br i1 %9, label %10, label %84

10:                                               ; preds = %7
  call void @llvm.memset.p0.i64(ptr align 16 @g, i8 0, i64 576, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %11

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

15:                                               ; preds = %11
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %45

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

17:                                               ; preds = %38, %16
  %18 = load i32, ptr %4, 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 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %41

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [12 x [12 x i32]], ptr @g, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [12 x i32], ptr %25, i64 0, i64 %27
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %28)
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [12 x [12 x i32]], ptr @g, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [12 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = xor i32 %36, 1
  store i32 %37, ptr %35, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %22
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !9

41:                                               ; preds = %21
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !11

45:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %75, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %78

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %70, %51
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr @m, align 4, !tbaa !5
  %55 = icmp sle i32 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 13, ptr %3, align 4
  br label %73

57:                                               ; preds = %52
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [12 x [12 x i32]], ptr @g, i64 0, i64 %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [12 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = icmp eq i32 %64, 2
  br i1 %65, label %66, label %69

66:                                               ; preds = %57
  store i8 0, ptr @flag, align 1, !tbaa !12
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %67, i32 noundef %68)
  store i32 13, ptr %3, align 4
  br label %73

69:                                               ; preds = %57
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !5
  br label %52, !llvm.loop !14

73:                                               ; preds = %66, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !15

78:                                               ; preds = %50
  %79 = load i8, ptr @flag, align 1, !tbaa !12, !range !16, !noundef !17
  %80 = trunc i8 %79 to i1
  %81 = zext i1 %80 to i64
  %82 = select i1 %80, ptr @.str.2, ptr @.str.3
  %83 = call i32 @puts(ptr noundef %82)
  br label %7, !llvm.loop !18

84:                                               ; preds = %7
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare i32 @puts(ptr noundef) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !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
@g = external dso_local global [12 x [12 x i32]], align 16
@flag = external dso_local local_unnamed_addr global i8, align 1
@.str = external hidden unnamed_addr constant [5 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
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse 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)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %0, %._crit_edge35
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(576) @g, i8 0, i64 576, i1 false)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not27 = icmp slt i32 %3, 1
  %4 = load i32, ptr @m, align 4
  %5 = icmp slt i32 %4, 1
  %or.cond = select i1 %.not27, i1 true, i1 %5
  br i1 %or.cond, label %._crit_edge35, label %.preheader22

.preheader23:                                     ; preds = %._crit_edge
  %.not1932 = icmp slt i32 %9, 1
  %.pr = load i32, ptr @m, align 4
  %6 = icmp slt i32 %.pr, 1
  %or.cond61 = select i1 %.not1932, i1 true, i1 %6
  br i1 %or.cond61, label %._crit_edge35, label %.preheader

.preheader22:                                     ; preds = %.lr.ph37, %._crit_edge
  %7 = phi i32 [ %9, %._crit_edge ], [ %3, %.lr.ph37 ]
  %8 = phi i32 [ %10, %._crit_edge ], [ %4, %.lr.ph37 ]
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %._crit_edge ], [ 1, %.lr.ph37 ]
  %.not2125 = icmp slt i32 %8, 1
  br i1 %.not2125, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader22
  %9 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %7, %.preheader22 ]
  %10 = phi i32 [ %16, %._crit_edge.loopexit ], [ %8, %.preheader22 ]
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %11 = sext i32 %9 to i64
  %.not.not = icmp slt i64 %indvars.iv43, %11
  br i1 %.not.not, label %.preheader22, label %.preheader23, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader22 ]
  %12 = getelementptr inbounds [12 x [12 x i32]], ptr @g, i64 0, i64 %indvars.iv43, i64 %indvars.iv
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %12)
  %14 = load i32, ptr %12, align 4, !tbaa !5
  %15 = xor i32 %14, 1
  store i32 %15, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %.not21.not = icmp slt i64 %indvars.iv, %17
  br i1 %.not21.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

.preheader:                                       ; preds = %.preheader23, %.loopexit
  %18 = phi i32 [ %35, %.loopexit ], [ %9, %.preheader23 ]
  %19 = phi i32 [ %36, %.loopexit ], [ %.pr, %.preheader23 ]
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %.loopexit ], [ 1, %.preheader23 ]
  %.not2029 = icmp slt i32 %19, 1
  br i1 %.not2029, label %.loopexit, label %.lr.ph31

.lr.ph31:                                         ; preds = %.preheader
  %20 = add nuw i32 %19, 1
  %wide.trip.count = zext i32 %20 to i64
  br label %27

._crit_edge35:                                    ; preds = %.loopexit, %.lr.ph37, %.preheader23
  %21 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %22 = trunc nuw i8 %21 to i1
  %23 = select i1 %22, ptr @.str.2, ptr @.str.3
  %24 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %23)
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %.lr.ph37, label %._crit_edge38, !llvm.loop !17

27:                                               ; preds = %.lr.ph31, %34
  %indvars.iv46 = phi i64 [ 1, %.lr.ph31 ], [ %indvars.iv.next47, %34 ]
  %28 = getelementptr inbounds [12 x [12 x i32]], ptr @g, i64 0, i64 %indvars.iv49, i64 %indvars.iv46
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 2
  br i1 %30, label %31, label %34

31:                                               ; preds = %27
  %32 = trunc nuw nsw i64 %indvars.iv46 to i32
  store i8 0, ptr @flag, align 1, !tbaa !13
  %33 = trunc nuw nsw i64 %indvars.iv49 to i32
  tail call void @_Z3dfsii(i32 noundef %33, i32 noundef %32)
  %.pre52 = load i32, ptr @m, align 4, !tbaa !5
  %.pre54 = load i32, ptr @n, align 4, !tbaa !5
  br label %.loopexit

34:                                               ; preds = %27
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %27, !llvm.loop !18

.loopexit:                                        ; preds = %34, %.preheader, %31
  %35 = phi i32 [ %18, %.preheader ], [ %.pre54, %31 ], [ %18, %34 ]
  %36 = phi i32 [ %19, %.preheader ], [ %.pre52, %31 ], [ %19, %34 ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %37 = sext i32 %35 to i64
  %.not19.not = icmp slt i64 %indvars.iv49, %37
  br i1 %.not19.not, label %.preheader, label %._crit_edge35, !llvm.loop !19

._crit_edge38:                                    ; preds = %._crit_edge35, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { mustprogress 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 = { 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 nounwind willreturn memory(argmem: write) }

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


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