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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @m, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %16, %0
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  %11 = mul nsw i32 %8, %10
  %12 = ashr i32 %11, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %7
  br label %16

16:                                               ; preds = %15
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @m, align 4, !tbaa !5
  br label %7, !llvm.loop !9

19:                                               ; preds = %7
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @m, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([50001 x i32], ptr getelementptr inbounds ([316 x [50001 x i32]], ptr @f, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %90, %19
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

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

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

28:                                               ; preds = %86, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %89

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %33
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %41
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [50001 x i32], ptr %42, i64 0, i64 %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [50001 x i32], ptr %50, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %47, i32 noundef %54)
  br label %55

55:                                               ; preds = %39, %33
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr @m, align 4, !tbaa !5
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %60, label %85

60:                                               ; preds = %55
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = icmp sle i32 %64, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %60
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %70
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %72, %73
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [50001 x i32], ptr %71, i64 0, i64 %76
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %79
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [50001 x i32], ptr %80, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %77, i32 noundef %84)
  br label %85

85:                                               ; preds = %67, %60, %55
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %4, align 4, !tbaa !5
  br label %28, !llvm.loop !11

89:                                               ; preds = %32
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !12

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

94:                                               ; preds = %107, %93
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = load i32, ptr @m, align 4, !tbaa !5
  %97 = icmp sle i32 %95, %96
  br i1 %97, label %99, label %98

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

99:                                               ; preds = %94
  %100 = load i32, ptr %5, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %101
  %103 = load i32, ptr @n, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [50001 x i32], ptr %102, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %106)
  br label %107

107:                                              ; preds = %99
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %5, align 4, !tbaa !5
  br label %94, !llvm.loop !13

110:                                              ; preds = %98
  %111 = load i32, ptr @ans, align 4, !tbaa !5
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %111)
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress 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 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = distinct !{!12, !10}
!13 = distinct !{!13, !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 local_unnamed_addr global i32, align 4
@f = external dso_local global [316 x [50001 x i32]], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind 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)
  %2 = load i32, ptr @n, align 4
  br label %3

3:                                                ; preds = %3, %0
  %storemerge = phi i32 [ 1, %0 ], [ %4, %3 ]
  %4 = add nuw nsw i32 %storemerge, 1
  %5 = mul nuw nsw i32 %4, %storemerge
  %6 = lshr i32 %5, 1
  %.not = icmp sgt i32 %6, %2
  br i1 %.not, label %7, label %3, !llvm.loop !5

7:                                                ; preds = %3
  %8 = add nsw i32 %storemerge, -1
  store i32 %8, ptr @m, align 4, !tbaa !7
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 200008), align 8, !tbaa !7
  %.not2838 = icmp ult i32 %storemerge, 2
  br i1 %.not2838, label %._crit_edge43, label %.preheader34.lr.ph

.preheader34.lr.ph:                               ; preds = %7
  %9 = icmp slt i32 %2, 1
  br i1 %9, label %.preheader, label %.preheader34

.preheader34:                                     ; preds = %.preheader34.lr.ph, %._crit_edge
  %10 = phi i32 [ %14, %._crit_edge ], [ %8, %.preheader34.lr.ph ]
  %11 = phi i32 [ %15, %._crit_edge ], [ %2, %.preheader34.lr.ph ]
  %12 = phi i32 [ %16, %._crit_edge ], [ %2, %.preheader34.lr.ph ]
  %indvars.iv46 = phi i64 [ %.pre54, %._crit_edge ], [ 1, %.preheader34.lr.ph ]
  %.not3036 = icmp slt i32 %12, 1
  %.pre54 = add nuw nsw i64 %indvars.iv46, 1
  br i1 %.not3036, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %._crit_edge, %.preheader34.lr.ph
  %13 = phi i32 [ %8, %.preheader34.lr.ph ], [ %14, %._crit_edge ]
  %.not2940 = icmp slt i32 %13, 1
  br i1 %.not2940, label %._crit_edge43, label %.lr.ph42

._crit_edge.loopexit:                             ; preds = %36
  %.pre53 = load i32, ptr @m, align 4, !tbaa !7
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader34, %._crit_edge.loopexit
  %14 = phi i32 [ %.pre53, %._crit_edge.loopexit ], [ %10, %.preheader34 ]
  %15 = phi i32 [ %37, %._crit_edge.loopexit ], [ %11, %.preheader34 ]
  %16 = phi i32 [ %37, %._crit_edge.loopexit ], [ %12, %.preheader34 ]
  %17 = sext i32 %14 to i64
  %.not28.not = icmp slt i64 %indvars.iv46, %17
  br i1 %.not28.not, label %.preheader34, label %.preheader, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader34, %36
  %18 = phi i32 [ %37, %36 ], [ %11, %.preheader34 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %36 ], [ 1, %.preheader34 ]
  %19 = phi i32 [ %37, %36 ], [ %12, %.preheader34 ]
  %20 = add nuw nsw i64 %indvars.iv, %indvars.iv46
  %21 = trunc nuw i64 %20 to i32
  %.not31 = icmp slt i32 %19, %21
  br i1 %.not31, label %26, label %22

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %indvars.iv46, i64 %20
  %24 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %indvars.iv46, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !7
  tail call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %23, i32 noundef %25)
  %.pre = load i32, ptr @n, align 4
  br label %26

26:                                               ; preds = %22, %.lr.ph
  %27 = phi i32 [ %.pre, %22 ], [ %18, %.lr.ph ]
  %28 = phi i32 [ %.pre, %22 ], [ %19, %.lr.ph ]
  %29 = load i32, ptr @m, align 4, !tbaa !7
  %30 = sext i32 %29 to i64
  %.not32.not = icmp slt i64 %indvars.iv46, %30
  %.not33.not = icmp sgt i32 %28, %21
  %or.cond = select i1 %.not32.not, i1 %.not33.not, i1 false
  br i1 %or.cond, label %31, label %36

31:                                               ; preds = %26
  %32 = add nuw nsw i64 %20, 1
  %33 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %.pre54, i64 %32
  %34 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %indvars.iv46, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !7
  tail call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %33, i32 noundef %35)
  %.pre52 = load i32, ptr @n, align 4
  br label %36

36:                                               ; preds = %26, %31
  %37 = phi i32 [ %27, %26 ], [ %.pre52, %31 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = sext i32 %37 to i64
  %.not30.not = icmp slt i64 %indvars.iv, %38
  br i1 %.not30.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge43:                                    ; preds = %.lr.ph42, %7, %.preheader
  %39 = load i32, ptr @ans, align 4, !tbaa !7
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %39)
  ret i32 0

.lr.ph42:                                         ; preds = %.preheader, %.lr.ph42
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %.lr.ph42 ], [ 1, %.preheader ]
  %41 = load i32, ptr @n, align 4, !tbaa !7
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [316 x [50001 x i32]], ptr @f, i64 0, i64 %indvars.iv49, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !7
  tail call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %44)
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %45 = load i32, ptr @m, align 4, !tbaa !7
  %46 = sext i32 %45 to i64
  %.not29.not = icmp slt i64 %indvars.iv49, %46
  br i1 %.not29.not, label %.lr.ph42, label %._crit_edge43, !llvm.loop !14
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #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" }

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


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