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

; 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
@f = external dso_local global [1000001 x i32], align 16
@s = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = 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
  %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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @s)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

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

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %62

13:                                               ; preds = %8
  br label %14

14:                                               ; preds = %32, %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %29

17:                                               ; preds = %14
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %22, %27
  br label %29

29:                                               ; preds = %17, %14
  %30 = phi i1 [ false, %14 ], [ %28, %17 ]
  br i1 %30, label %31, label %37

31:                                               ; preds = %29
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !10

37:                                               ; preds = %29
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %42, %47
  br i1 %48, label %49, label %52

49:                                               ; preds = %37
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %53

52:                                               ; preds = %37
  br label %53

53:                                               ; preds = %52, %49
  %54 = phi i32 [ %51, %49 ], [ 0, %52 ]
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %57
  store i32 %54, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %53
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !12

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

63:                                               ; preds = %103, %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = icmp sle i32 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %106

68:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sub nsw i32 %70, %74
  %76 = sdiv i32 %69, %75
  store i32 %76, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sub nsw i32 %78, %82
  %84 = srem i32 %77, %83
  store i32 %84, ptr %6, align 4, !tbaa !5
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = load i32, ptr @m, align 4, !tbaa !5
  %87 = srem i32 %85, %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = icmp sgt i32 %88, 0
  %90 = zext i1 %89 to i32
  %91 = add nsw i32 %87, %90
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = load i32, ptr @m, align 4, !tbaa !5
  %94 = sdiv i32 %92, %93
  %95 = icmp sle i32 %91, %94
  %96 = zext i1 %95 to i64
  %97 = getelementptr inbounds [3 x i8], ptr @.str.1, i64 0, i64 %96
  %98 = load i8, ptr %97, align 1, !tbaa !9
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = sub nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %101
  store i8 %98, ptr %102, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %103

103:                                              ; preds = %68
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %4, align 4, !tbaa !5
  br label %63, !llvm.loop !13

106:                                              ; preds = %67
  %107 = call i32 @puts(ptr noundef @s)
  ret i32 0
}

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

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

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

declare i32 @puts(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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !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
@f = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@s = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = 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, ptr noundef nonnull @s)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.preheader27.preheader, label %.preheader

.preheader27.preheader:                           ; preds = %0
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.preheader27

.preheader27:                                     ; preds = %.preheader27.preheader, %.critedge
  %indvars.iv = phi i64 [ 1, %.preheader27.preheader ], [ %indvars.iv.next, %.critedge ]
  %.02232 = phi i32 [ 0, %.preheader27.preheader ], [ %spec.select, %.critedge ]
  %.not2428 = icmp eq i32 %.02232, 0
  %.phi.trans.insert = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %indvars.iv
  %.pre = load i8, ptr %.phi.trans.insert, align 1, !tbaa !9
  br i1 %.not2428, label %.critedge, label %.lr.ph

.preheader:                                       ; preds = %.critedge, %0
  %.not35 = icmp slt i32 %2, 1
  br i1 %.not35, label %._crit_edge, label %.lr.ph37

.lr.ph37:                                         ; preds = %.preheader
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nuw i32 %2, 1
  %wide.trip.count42 = zext i32 %5 to i64
  br label %19

.lr.ph:                                           ; preds = %.preheader27, %9
  %.129 = phi i32 [ %11, %9 ], [ %.02232, %.preheader27 ]
  %6 = sext i32 %.129 to i64
  %7 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %.not25 = icmp eq i8 %.pre, %8
  br i1 %.not25, label %.critedge, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %6
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %.critedge, label %.lr.ph, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph, %9, %.preheader27
  %.1.lcssa = phi i32 [ 0, %.preheader27 ], [ 0, %9 ], [ %.129, %.lr.ph ]
  %12 = sext i32 %.1.lcssa to i64
  %13 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = icmp eq i8 %.pre, %14
  %16 = add nsw i32 %.1.lcssa, 1
  %spec.select = select i1 %15, i32 %16, i32 %.1.lcssa
  %spec.select26 = select i1 %15, i32 %16, i32 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %indvars.iv.next
  store i32 %spec.select26, ptr %17, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.preheader27, !llvm.loop !12

._crit_edge:                                      ; preds = %19, %.preheader
  %18 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @s)
  ret i32 0

19:                                               ; preds = %.lr.ph37, %19
  %indvars.iv39 = phi i64 [ 1, %.lr.ph37 ], [ %indvars.iv.next40, %19 ]
  %20 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %indvars.iv39
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = trunc nuw nsw i64 %indvars.iv39 to i32
  %23 = sub nsw i32 %22, %21
  %24 = sdiv i32 %22, %23
  %25 = srem i32 %22, %23
  %26 = srem i32 %24, %4
  %27 = icmp ne i32 %25, 0
  %28 = zext i1 %27 to i32
  %29 = add nsw i32 %26, %28
  %30 = sdiv i32 %24, %4
  %31 = icmp sle i32 %29, %30
  %32 = zext i1 %31 to i64
  %33 = getelementptr inbounds [3 x i8], ptr @.str.1, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = add nsw i64 %indvars.iv39, -1
  %36 = getelementptr inbounds [1000001 x i8], ptr @s, i64 0, i64 %35
  store i8 %34, ptr %36, align 1, !tbaa !9
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge, label %19, !llvm.loop !13
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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