; LLVM IR from tangjz/acm-icpc :: codeforces/complete (718A)

; 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 [200002 x i8], align 16
@.str = 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef getelementptr inbounds (i8, ptr @str, i64 1))
  store i8 48, ptr @str, align 16, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %6

6:                                                ; preds = %22, %0
  %7 = load i32, ptr %2, align 4, !tbaa !8
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %19

12:                                               ; preds = %6
  %13 = load i32, ptr %2, align 4, !tbaa !8
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  %18 = icmp ne i32 %17, 46
  br label %19

19:                                               ; preds = %12, %6
  %20 = phi i1 [ false, %6 ], [ %18, %12 ]
  br i1 %20, label %21, label %25

21:                                               ; preds = %19
  br label %22

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

25:                                               ; preds = %19
  br label %26

26:                                               ; preds = %42, %25
  %27 = load i32, ptr %2, align 4, !tbaa !8
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %39

32:                                               ; preds = %26
  %33 = load i32, ptr %2, align 4, !tbaa !8
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = sext i8 %36 to i32
  %38 = icmp slt i32 %37, 53
  br label %39

39:                                               ; preds = %32, %26
  %40 = phi i1 [ false, %26 ], [ %38, %32 ]
  br i1 %40, label %41, label %45

41:                                               ; preds = %39
  br label %42

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

45:                                               ; preds = %39
  br label %46

46:                                               ; preds = %116, %45
  %47 = load i32, ptr %2, align 4, !tbaa !8
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !5
  %51 = sext i8 %50 to i32
  %52 = icmp ne i32 %51, 46
  br i1 %52, label %53, label %63

53:                                               ; preds = %46
  %54 = load i32, ptr %2, align 4, !tbaa !8
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !5
  %58 = sext i8 %57 to i32
  %59 = icmp sge i32 %58, 53
  br i1 %59, label %60, label %63

60:                                               ; preds = %53
  %61 = load i32, ptr @m, align 4, !tbaa !8
  %62 = icmp sgt i32 %61, 0
  br label %63

63:                                               ; preds = %60, %53, %46
  %64 = phi i1 [ false, %53 ], [ false, %46 ], [ %62, %60 ]
  br i1 %64, label %65, label %121

65:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %66 = load i32, ptr %2, align 4, !tbaa !8
  %67 = sub nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !5
  %71 = sext i8 %70 to i32
  %72 = icmp eq i32 %71, 46
  br i1 %72, label %73, label %76

73:                                               ; preds = %65
  %74 = load i32, ptr %2, align 4, !tbaa !8
  %75 = sub nsw i32 %74, 2
  br label %79

76:                                               ; preds = %65
  %77 = load i32, ptr %2, align 4, !tbaa !8
  %78 = sub nsw i32 %77, 1
  br label %79

79:                                               ; preds = %76, %73
  %80 = phi i32 [ %75, %73 ], [ %78, %76 ]
  store i32 %80, ptr %3, align 4, !tbaa !8
  %81 = load i32, ptr %3, align 4, !tbaa !8
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !5
  %85 = add i8 %84, 1
  store i8 %85, ptr %83, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %86 = load i32, ptr %3, align 4, !tbaa !8
  store i32 %86, ptr %4, align 4, !tbaa !8
  br label %87

87:                                               ; preds = %109, %79
  %88 = load i32, ptr %4, align 4, !tbaa !8
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %89
  %91 = load i8, ptr %90, align 1, !tbaa !5
  %92 = sext i8 %91 to i32
  %93 = icmp sgt i32 %92, 57
  br i1 %93, label %95, label %94

94:                                               ; preds = %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %112

95:                                               ; preds = %87
  %96 = load i32, ptr %4, align 4, !tbaa !8
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %97
  %99 = load i8, ptr %98, align 1, !tbaa !5
  %100 = sext i8 %99 to i32
  %101 = sub nsw i32 %100, 10
  %102 = trunc i32 %101 to i8
  store i8 %102, ptr %98, align 1, !tbaa !5
  %103 = load i32, ptr %4, align 4, !tbaa !8
  %104 = sub nsw i32 %103, 1
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %105
  %107 = load i8, ptr %106, align 1, !tbaa !5
  %108 = add i8 %107, 1
  store i8 %108, ptr %106, align 1, !tbaa !5
  br label %109

109:                                              ; preds = %95
  %110 = load i32, ptr %4, align 4, !tbaa !8
  %111 = add nsw i32 %110, -1
  store i32 %111, ptr %4, align 4, !tbaa !8
  br label %87, !llvm.loop !13

112:                                              ; preds = %94
  %113 = load i32, ptr %2, align 4, !tbaa !8
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %114
  store i8 0, ptr %115, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %116

116:                                              ; preds = %112
  %117 = load i32, ptr %2, align 4, !tbaa !8
  %118 = add nsw i32 %117, -1
  store i32 %118, ptr %2, align 4, !tbaa !8
  %119 = load i32, ptr @m, align 4, !tbaa !8
  %120 = add nsw i32 %119, -1
  store i32 %120, ptr @m, align 4, !tbaa !8
  br label %46, !llvm.loop !14

121:                                              ; preds = %63
  %122 = load i32, ptr %2, align 4, !tbaa !8
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %123
  %125 = load i8, ptr %124, align 1, !tbaa !5
  %126 = sext i8 %125 to i32
  %127 = icmp eq i32 %126, 46
  br i1 %127, label %128, label %132

128:                                              ; preds = %121
  %129 = load i32, ptr %2, align 4, !tbaa !8
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %130
  store i8 0, ptr %131, align 1, !tbaa !5
  br label %132

132:                                              ; preds = %128, %121
  %133 = load i8, ptr @str, align 16, !tbaa !5
  %134 = sext i8 %133 to i32
  %135 = icmp eq i32 %134, 48
  %136 = zext i1 %135 to i64
  %137 = select i1 %135, ptr getelementptr inbounds (i8, ptr @str, i64 1), ptr @str
  %138 = call i32 @puts(ptr noundef %137)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

declare i32 @puts(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


; 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 [200002 x i8], align 16
@.str = 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull getelementptr inbounds (i8, ptr @str, i64 1))
  store i8 48, ptr @str, align 16, !tbaa !5
  br label %2

2:                                                ; preds = %4, %0
  %3 = phi i8 [ %.pre, %4 ], [ 48, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %4 ], [ 0, %0 ]
  switch i8 %3, label %4 [
    i8 0, label %.critedge.preheader
    i8 46, label %.critedge.preheader
  ]

.critedge.preheader:                              ; preds = %2, %2
  br label %.critedge

4:                                                ; preds = %2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.phi.trans.insert = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %indvars.iv.next
  %.pre = load i8, ptr %.phi.trans.insert, align 1, !tbaa !5
  br label %2, !llvm.loop !8

.critedge:                                        ; preds = %.critedge.preheader, %.critedge
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.critedge ], [ %indvars.iv, %.critedge.preheader ]
  %5 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %indvars.iv42
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not32 = icmp ne i8 %6, 0
  %7 = icmp slt i8 %6, 53
  %or.cond34 = and i1 %.not32, %7
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  br i1 %or.cond34, label %.critedge, label %.critedge2.preheader, !llvm.loop !10

.critedge2.preheader:                             ; preds = %.critedge
  %8 = and i64 %indvars.iv42, 4294967295
  %9 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not3337 = icmp eq i8 %10, 46
  br i1 %.not3337, label %.critedge2._crit_edge, label %.lr.ph39.preheader

.lr.ph39.preheader:                               ; preds = %.critedge2.preheader
  %11 = trunc nuw nsw i64 %indvars.iv42 to i32
  %m.promoted = load i32, ptr @m, align 4
  br label %.lr.ph39

.lr.ph39:                                         ; preds = %.lr.ph39.preheader, %.critedge2
  %indvars.iv47 = phi i64 [ %indvars.iv42, %.lr.ph39.preheader ], [ %indvars.iv.next48, %.critedge2 ]
  %12 = phi i8 [ %10, %.lr.ph39.preheader ], [ %31, %.critedge2 ]
  %13 = phi ptr [ %9, %.lr.ph39.preheader ], [ %19, %.critedge2 ]
  %.238 = phi i32 [ %11, %.lr.ph39.preheader ], [ %18, %.critedge2 ]
  %14 = phi i32 [ %m.promoted, %.lr.ph39.preheader ], [ %30, %.critedge2 ]
  %15 = icmp sgt i8 %12, 52
  %16 = icmp sgt i32 %14, 0
  %or.cond = select i1 %15, i1 %16, i1 false
  br i1 %or.cond, label %17, label %.critedge4

17:                                               ; preds = %.lr.ph39
  %indvars.iv.next48 = add nsw i64 %indvars.iv47, -1
  %18 = add nsw i32 %.238, -1
  %19 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %indvars.iv.next48
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = icmp eq i8 %20, 46
  %22 = trunc i64 %indvars.iv47 to i32
  %23 = add i32 %22, -2
  %24 = select i1 %21, i32 %23, i32 %18
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = add i8 %27, 1
  store i8 %28, ptr %26, align 1, !tbaa !5
  %29 = icmp sgt i8 %28, 57
  br i1 %29, label %.lr.ph, label %.critedge2

.critedge2:                                       ; preds = %.lr.ph, %17
  store i8 0, ptr %13, align 1, !tbaa !5
  %30 = add nsw i32 %14, -1
  store i32 %30, ptr @m, align 4, !tbaa !11
  %31 = load i8, ptr %19, align 1, !tbaa !5
  %.not33 = icmp eq i8 %31, 46
  br i1 %.not33, label %.critedge2._crit_edge, label %.lr.ph39, !llvm.loop !13

.lr.ph:                                           ; preds = %17, %.lr.ph
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %.lr.ph ], [ %25, %17 ]
  %32 = phi i8 [ %37, %.lr.ph ], [ %28, %17 ]
  %33 = phi ptr [ %35, %.lr.ph ], [ %26, %17 ]
  %34 = add nsw i8 %32, -10
  store i8 %34, ptr %33, align 1, !tbaa !5
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, -1
  %35 = getelementptr inbounds [200002 x i8], ptr @str, i64 0, i64 %indvars.iv.next46
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = add i8 %36, 1
  store i8 %37, ptr %35, align 1, !tbaa !5
  %38 = icmp sgt i8 %37, 57
  br i1 %38, label %.lr.ph, label %.critedge2, !llvm.loop !14

.critedge2._crit_edge:                            ; preds = %.critedge2, %.critedge2.preheader
  %.lcssa = phi ptr [ %9, %.critedge2.preheader ], [ %19, %.critedge2 ]
  store i8 0, ptr %.lcssa, align 1, !tbaa !5
  br label %.critedge4

.critedge4:                                       ; preds = %.lr.ph39, %.critedge2._crit_edge
  %39 = load i8, ptr @str, align 16, !tbaa !5
  %40 = icmp eq i8 %39, 48
  %41 = select i1 %40, ptr getelementptr inbounds (i8, ptr @str, i64 1), ptr @str
  %42 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %41)
  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 @puts(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = distinct !{!13, !9}
!14 = distinct !{!14, !9}


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