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

; 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
@all = external dso_local global i32, align 4
@f = external dso_local global [1048577 x i32], align 16
@cnt = external dso_local global [1048577 x i32], 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 [4 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
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = shl i32 1, %7
  %9 = sub nsw i32 %8, 1
  store i32 %9, ptr @all, 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 %10

10:                                               ; preds = %30, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @all, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = ashr i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = and i32 %21, 1
  %23 = add nsw i32 %20, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %25
  store i32 %23, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %28
  store i32 -1061109567, ptr %29, align 4, !tbaa !5
  br label %30

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

33:                                               ; preds = %14
  br label %34

34:                                               ; preds = %74, %33
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr @m, align 4, !tbaa !5
  %37 = icmp ne i32 %35, 0
  br i1 %37, label %38, label %75

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = shl i32 1, %41
  store i32 %42, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %71, %38
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr @all, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %74

48:                                               ; preds = %43
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = and i32 %49, %50
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %70

53:                                               ; preds = %48
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = xor i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = ashr i32 %63, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %62, %68
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %56, i32 noundef %69)
  br label %70

70:                                               ; preds = %53, %48
  br label %71

71:                                               ; preds = %70
  %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 %43, !llvm.loop !11

74:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %34, !llvm.loop !12

75:                                               ; preds = %34
  %76 = load i32, ptr @all, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %79)
  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

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

declare i32 @printf(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 = { inlinehint 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 #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}


; 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
@all = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local global [1048577 x i32], align 16
@cnt = external dso_local local_unnamed_addr global [1048577 x i32], 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 [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %3
  %4 = xor i32 %notmask, -1
  store i32 %4, ptr @all, align 4, !tbaa !5
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %5 = tail call i32 @llvm.umax.i32(i32 %4, i32 1)
  %umax33 = zext nneg i32 %5 to i64
  %xtraiter = and i64 %umax33, 1
  %6 = icmp ugt i32 %notmask, -3
  br i1 %6, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %umax33, 2147483646
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa
  %7 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %8 = lshr i64 %indvars.iv.unr, 1
  %9 = and i64 %8, 2147483647
  %10 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = and i32 %7, 1
  %13 = add nsw i32 %11, %12
  %14 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %indvars.iv.unr
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %indvars.iv.unr
  store i32 -1061109567, ptr %15, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %0
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr @m, align 4, !tbaa !5
  %.not1523 = icmp eq i32 %16, 0
  br i1 %.not1523, label %._crit_edge25, label %.lr.ph24

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %18 = lshr i64 %indvars.iv, 1
  %19 = and i64 %18, 2147483647
  %20 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %indvars.iv
  store i32 -1061109567, ptr %24, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = lshr i64 %indvars.iv.next, 1
  %26 = and i64 %25, 2147483647
  %27 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %indvars.iv.next
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %indvars.iv.next
  store i32 -1061109567, ptr %30, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

.lr.ph24:                                         ; preds = %.preheader, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = add nsw i32 %32, -1
  %34 = shl nuw i32 1, %33
  %35 = load i32, ptr @all, align 4, !tbaa !5
  %.not1620 = icmp slt i32 %35, 1
  br i1 %.not1620, label %._crit_edge, label %.lr.ph22

._crit_edge:                                      ; preds = %54, %.lr.ph24
  %36 = phi i32 [ %35, %.lr.ph24 ], [ %55, %54 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @m, align 4, !tbaa !5
  %.not15 = icmp eq i32 %37, 0
  br i1 %.not15, label %._crit_edge25, label %.lr.ph24, !llvm.loop !11

.lr.ph22:                                         ; preds = %.lr.ph24, %54
  %39 = phi i32 [ %55, %54 ], [ %35, %.lr.ph24 ]
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %54 ], [ 1, %.lr.ph24 ]
  %40 = trunc nuw nsw i64 %indvars.iv27 to i32
  %41 = and i32 %34, %40
  %.not17 = icmp eq i32 %41, 0
  br i1 %.not17, label %54, label %42

42:                                               ; preds = %.lr.ph22
  %43 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %indvars.iv27
  %44 = xor i32 %34, %40
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = lshr i32 %40, %48
  %50 = zext nneg i32 %49 to i64
  %51 = getelementptr inbounds [1048577 x i32], ptr @cnt, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, %47
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %43, i32 noundef %53)
  %.pre = load i32, ptr @all, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %.lr.ph22, %42
  %55 = phi i32 [ %39, %.lr.ph22 ], [ %.pre, %42 ]
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %56 = sext i32 %55 to i64
  %.not16.not = icmp slt i64 %indvars.iv27, %56
  br i1 %.not16.not, label %.lr.ph22, label %._crit_edge, !llvm.loop !12

._crit_edge25:                                    ; preds = %._crit_edge, %.preheader
  %57 = phi i32 [ %4, %.preheader ], [ %36, %._crit_edge ]
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %60)
  ret i32 0
}

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

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

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

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

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

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

attributes #0 = { 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 #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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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