; LLVM IR from tangjz/acm-icpc :: uvalive (6137)

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

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

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

9:                                                ; preds = %6
  store i32 0, ptr getelementptr inbounds ([2 x i32], ptr @sum, i64 0, i64 1), align 4, !tbaa !5
  store i32 0, ptr @sum, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

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

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

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

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

24:                                               ; preds = %14
  call void @llvm.memset.p0.i64(ptr align 16 @match, i8 0, i64 12100, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %25

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

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

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

31:                                               ; preds = %71, %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [55 x [55 x i8]], ptr @str, i64 0, i64 %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [55 x i8], ptr %39, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 88
  br i1 %45, label %46, label %47

46:                                               ; preds = %36
  br label %71

47:                                               ; preds = %36
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = and i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %53, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = xor i32 %58, -1
  %60 = and i32 %59, 1
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %47
  br label %71

63:                                               ; preds = %47
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 3025, i1 false)
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = call noundef zeroext i1 @_Z4pathii(i32 noundef %64, i32 noundef %65)
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = load i32, ptr @ans, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @ans, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %67, %63
  br label %71

71:                                               ; preds = %70, %62, %46
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !12

74:                                               ; preds = %35
  br label %75

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

78:                                               ; preds = %29
  %79 = load i32, ptr @ans, align 4, !tbaa !5
  %80 = load i32, ptr @sum, align 4, !tbaa !5
  %81 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @sum, i64 0, i64 1), align 4, !tbaa !5
  %82 = icmp slt i32 %80, %81
  br i1 %82, label %83, label %85

83:                                               ; preds = %78
  %84 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @sum, i64 0, i64 1), align 4, !tbaa !5
  br label %87

85:                                               ; preds = %78
  %86 = load i32, ptr @sum, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %85, %83
  %88 = phi i32 [ %84, %83 ], [ %86, %85 ]
  %89 = icmp slt i32 %79, %88
  br i1 %89, label %90, label %91

90:                                               ; preds = %87
  br label %92

91:                                               ; preds = %87
  br label %92

92:                                               ; preds = %91, %90
  %93 = phi ptr [ @.str.2, %90 ], [ @.str.3, %91 ]
  %94 = getelementptr inbounds [2 x i8], ptr %93, i64 0, i64 0
  %95 = call i32 @puts(ptr noundef %94)
  br label %6, !llvm.loop !14

96:                                               ; preds = %6
  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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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
@match = external dso_local local_unnamed_addr global [55 x [55 x i32]], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global [2 x 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 [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4pathii(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.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %0, %._crit_edge22
  store i32 0, ptr getelementptr inbounds (i8, ptr @sum, i64 4), align 4, !tbaa !5
  store i32 0, ptr @sum, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  %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 = %.lr.ph24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(12100) @match, i8 0, i64 12100, i1 false)
  br label %._crit_edge22

._crit_edge:                                      ; preds = %.lr.ph
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(12100) @match, i8 0, i64 12100, i1 false)
  %5 = icmp sgt i32 %10, 0
  %6 = load i32, ptr @m, align 4
  %7 = icmp sgt i32 %6, 0
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge22

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

.preheader:                                       ; preds = %._crit_edge, %._crit_edge20
  %13 = phi i32 [ %26, %._crit_edge20 ], [ %10, %._crit_edge ]
  %14 = phi i32 [ %27, %._crit_edge20 ], [ %6, %._crit_edge ]
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %._crit_edge20 ], [ 0, %._crit_edge ]
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph19, label %._crit_edge20

.lr.ph19:                                         ; preds = %.preheader
  %16 = trunc nuw nsw i64 %indvars.iv31 to i32
  br label %30

._crit_edge22:                                    ; preds = %._crit_edge20, %._crit_edge.thread, %._crit_edge
  %17 = load i32, ptr @ans, align 4, !tbaa !5
  %18 = load i32, ptr @sum, align 4
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @sum, i64 4), align 4
  %20 = tail call i32 @llvm.smax.i32(i32 %18, i32 %19)
  %21 = icmp slt i32 %17, %20
  %22 = select i1 %21, ptr @.str.2, ptr @.str.3
  %23 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %22)
  %24 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %.lr.ph24, label %._crit_edge25, !llvm.loop !11

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

._crit_edge20:                                    ; preds = %._crit_edge20.loopexit, %.preheader
  %26 = phi i32 [ %.pre, %._crit_edge20.loopexit ], [ %13, %.preheader ]
  %27 = phi i32 [ %48, %._crit_edge20.loopexit ], [ %14, %.preheader ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %28 = sext i32 %26 to i64
  %29 = icmp slt i64 %indvars.iv.next32, %28
  br i1 %29, label %.preheader, label %._crit_edge22, !llvm.loop !12

30:                                               ; preds = %.lr.ph19, %47
  %indvars.iv28 = phi i64 [ 0, %.lr.ph19 ], [ %indvars.iv.next29, %47 ]
  %31 = getelementptr inbounds [55 x [55 x i8]], ptr @str, i64 0, i64 %indvars.iv31, i64 %indvars.iv28
  %32 = load i8, ptr %31, align 1, !tbaa !14
  %33 = icmp eq i8 %32, 88
  br i1 %33, label %47, label %34

34:                                               ; preds = %30
  %35 = add nuw nsw i64 %indvars.iv28, %indvars.iv31
  %36 = and i64 %35, 1
  %37 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %37, align 4, !tbaa !5
  %40 = and i64 %35, 1
  %.not.not = icmp eq i64 %40, 0
  br i1 %.not.not, label %47, label %41

41:                                               ; preds = %34
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3025) @vis, i8 0, i64 3025, i1 false)
  %42 = trunc nuw nsw i64 %indvars.iv28 to i32
  %43 = tail call noundef zeroext i1 @_Z4pathii(i32 noundef %16, i32 noundef %42)
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr @ans, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @ans, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %41, %44, %34, %30
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %48 = load i32, ptr @m, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %indvars.iv.next29, %49
  br i1 %50, label %30, label %._crit_edge20.loopexit, !llvm.loop !15

._crit_edge25:                                    ; preds = %._crit_edge22, %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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !10}


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