; LLVM IR from tangjz/acm-icpc :: 51nod (1416)

; 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
@str = external dso_local global [55 x [55 x i8]], align 16
@vis = external dso_local global [55 x [55 x i8]], align 16
@.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 [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef, 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 i8, align 1
  %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 = %75, %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 %81

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

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

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

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [55 x [55 x i8]], ptr @str, i64 0, i64 %18
  %20 = getelementptr inbounds [55 x i8], ptr %19, i64 0, i64 0
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %20)
  br label %22

22:                                               ; preds = %16
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

25:                                               ; preds = %15
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 3025, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #5
  store i8 1, ptr %3, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %72, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  br label %33

33:                                               ; preds = %30, %26
  %34 = phi i1 [ false, %26 ], [ %32, %30 ]
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %68, %36
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %37
  %42 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %43 = trunc i8 %42 to i1
  br label %44

44:                                               ; preds = %41, %37
  %45 = phi i1 [ false, %37 ], [ %43, %41 ]
  br i1 %45, label %47, label %46

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

47:                                               ; preds = %44
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [55 x [55 x i8]], ptr @vis, i64 0, i64 %49
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [55 x i8], ptr %50, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11, !range !13, !noundef !14
  %55 = trunc i8 %54 to i1
  br i1 %55, label %67, label %56

56:                                               ; preds = %47
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_Z3dfsiii(i32 noundef %57, i32 noundef %58, i32 noundef -1)
  %60 = zext i1 %59 to i32
  %61 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %62 = trunc i8 %61 to i1
  %63 = zext i1 %62 to i32
  %64 = and i32 %63, %60
  %65 = icmp ne i32 %64, 0
  %66 = zext i1 %65 to i8
  store i8 %66, ptr %3, align 1, !tbaa !11
  br label %67

67:                                               ; preds = %56, %47
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %6, align 4, !tbaa !5
  br label %37, !llvm.loop !15

71:                                               ; preds = %46
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !16

75:                                               ; preds = %35
  %76 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %77 = trunc i8 %76 to i1
  %78 = zext i1 %77 to i64
  %79 = select i1 %77, ptr @.str.2, ptr @.str.3
  %80 = call i32 @puts(ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #5
  br label %7, !llvm.loop !17

81:                                               ; 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !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
@str = external dso_local global [55 x [55 x i8]], align 16
@vis = external dso_local local_unnamed_addr global [55 x [55 x i8]], align 16
@.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 [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef, 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 %.preheader18, label %._crit_edge28

.preheader18:                                     ; preds = %0, %18
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3025) @vis, i8 0, i64 3025, i1 false)
  br label %._crit_edge26.thread

._crit_edge:                                      ; preds = %.lr.ph
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3025) @vis, i8 0, i64 3025, i1 false)
  %5 = icmp sgt i32 %8, 0
  br i1 %5, label %.preheader.preheader, label %._crit_edge26.thread

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

.lr.ph:                                           ; preds = %.preheader18, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader18 ]
  %6 = getelementptr inbounds [55 x [55 x i8]], ptr @str, i64 0, i64 %indvars.iv
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge23
  %11 = phi i32 [ %8, %.preheader.preheader ], [ %23, %._crit_edge23 ]
  %12 = phi i32 [ %.pre, %.preheader.preheader ], [ %24, %._crit_edge23 ]
  %13 = phi i32 [ %.pre, %.preheader.preheader ], [ %25, %._crit_edge23 ]
  %indvars.iv33 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next34, %._crit_edge23 ]
  %.01624 = phi i8 [ 1, %.preheader.preheader ], [ %.1.lcssa, %._crit_edge23 ]
  %14 = icmp sgt i32 %13, 0
  %15 = trunc nuw i8 %.01624 to i1
  %16 = select i1 %14, i1 %15, i1 false
  br i1 %16, label %.lr.ph22, label %._crit_edge23

.lr.ph22:                                         ; preds = %.preheader
  %17 = trunc nuw nsw i64 %indvars.iv33 to i32
  br label %29

._crit_edge26:                                    ; preds = %._crit_edge23
  br i1 %cond.fr, label %._crit_edge26.thread, label %18

._crit_edge26.thread:                             ; preds = %._crit_edge.thread, %._crit_edge, %._crit_edge26
  br label %18

18:                                               ; preds = %._crit_edge26, %._crit_edge26.thread
  %19 = phi ptr [ @.str.2, %._crit_edge26.thread ], [ @.str.3, %._crit_edge26 ]
  %20 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %19)
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %.preheader18, label %._crit_edge28, !llvm.loop !11

._crit_edge23.loopexit:                           ; preds = %38
  %.pre36 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit, %.preheader
  %.pre-phi = phi i1 [ %42, %._crit_edge23.loopexit ], [ %15, %.preheader ]
  %23 = phi i32 [ %.pre36, %._crit_edge23.loopexit ], [ %11, %.preheader ]
  %24 = phi i32 [ %39, %._crit_edge23.loopexit ], [ %12, %.preheader ]
  %25 = phi i32 [ %39, %._crit_edge23.loopexit ], [ %13, %.preheader ]
  %.1.lcssa = phi i8 [ %.2, %._crit_edge23.loopexit ], [ %.01624, %.preheader ]
  %cond.fr = freeze i1 %.pre-phi
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %26 = sext i32 %23 to i64
  %27 = icmp slt i64 %indvars.iv.next34, %26
  %28 = and i1 %27, %cond.fr
  br i1 %28, label %.preheader, label %._crit_edge26, !llvm.loop !12

29:                                               ; preds = %.lr.ph22, %38
  %30 = phi i32 [ %12, %.lr.ph22 ], [ %39, %38 ]
  %indvars.iv31 = phi i64 [ 0, %.lr.ph22 ], [ %indvars.iv.next32, %38 ]
  %.120 = phi i8 [ %.01624, %.lr.ph22 ], [ %.2, %38 ]
  %31 = getelementptr inbounds [55 x [55 x i8]], ptr @vis, i64 0, i64 %indvars.iv33, i64 %indvars.iv31
  %32 = load i8, ptr %31, align 1, !tbaa !13, !range !15, !noundef !16
  %33 = trunc nuw i8 %32 to i1
  br i1 %33, label %38, label %34

34:                                               ; preds = %29
  %35 = trunc nuw nsw i64 %indvars.iv31 to i32
  %36 = tail call noundef zeroext i1 @_Z3dfsiii(i32 noundef %17, i32 noundef %35, i32 noundef -1)
  %37 = zext i1 %36 to i8
  %.pre35 = load i32, ptr @m, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %29, %34
  %39 = phi i32 [ %30, %29 ], [ %.pre35, %34 ]
  %.2 = phi i8 [ %.120, %29 ], [ %37, %34 ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next32, %40
  %42 = trunc nuw i8 %.2 to i1
  %43 = select i1 %41, i1 %42, i1 false
  br i1 %43, label %29, label %._crit_edge23.loopexit, !llvm.loop !17

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


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