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

; 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
@e = external dso_local global [21 x i32], align 16
@bits = external dso_local global [1048577 x i32], align 16
@f = 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 [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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  br label %9

9:                                                ; preds = %13, %0
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @m, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %24

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %3, align 4, !tbaa !5
  %17 = shl i32 1, %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [21 x i32], ptr @e, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = or i32 %22, %17
  store i32 %23, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %9, !llvm.loop !9

24:                                               ; preds = %9
  store i32 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %25

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

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

31:                                               ; preds = %25
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = ashr i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1048577 x i32], ptr @bits, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = and i32 %37, 1
  %39 = add nsw i32 %36, %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1048577 x i32], ptr @bits, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1048577 x i32], ptr @bits, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [21 x i32], ptr @e, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = and i32 %43, %51
  store i32 %52, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  br label %53

53:                                               ; preds = %83, %31
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %57, label %56

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

57:                                               ; preds = %53
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sub nsw i32 0, %59
  %61 = and i32 %58, %60
  store i32 %61, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = xor i32 %62, %63
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = add nsw i32 %71, %67
  store i32 %72, ptr %70, align 4, !tbaa !5
  %73 = icmp sge i32 %72, 998244353
  br i1 %73, label %74, label %81

74:                                               ; preds = %57
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = sub nsw i32 %78, 998244353
  store i32 %79, ptr %77, align 4, !tbaa !5
  %80 = icmp ne i32 %79, 0
  br label %81

81:                                               ; preds = %74, %57
  %82 = phi i1 [ false, %57 ], [ %80, %74 ]
  br label %83

83:                                               ; preds = %81
  %84 = load i32, ptr %7, align 4, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = xor i32 %85, %84
  store i32 %86, ptr %6, align 4, !tbaa !5
  br label %53, !llvm.loop !11

87:                                               ; preds = %56
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %4, align 4, !tbaa !5
  br label %25, !llvm.loop !12

91:                                               ; preds = %30
  %92 = load i32, ptr @n, align 4, !tbaa !5
  %93 = shl i32 1, %92
  %94 = sub nsw i32 %93, 1
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %97)
  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 @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 = { 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
@e = external dso_local local_unnamed_addr global [21 x i32], align 16
@bits = external dso_local local_unnamed_addr global [1048577 x i32], align 16
@f = 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 [4 x i8], align 1

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  %9 = shl nuw i32 1, %8
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [21 x i32], ptr @e, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = or i32 %14, %9
  store i32 %15, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  store i32 1, ptr @f, align 16, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = shl nuw i32 1, %18
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %.lr.ph29.preheader, label %._crit_edge30

.lr.ph29.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %19 to i64
  br label %.lr.ph29

._crit_edge30:                                    ; preds = %._crit_edge25, %._crit_edge
  %21 = add nsw i32 %19, -1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %24)
  ret i32 0

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %._crit_edge25
  %indvars.iv = phi i64 [ 1, %.lr.ph29.preheader ], [ %indvars.iv.next, %._crit_edge25 ]
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  %27 = lshr i64 %indvars.iv, 1
  %28 = and i64 %27, 2147483647
  %29 = getelementptr inbounds [1048577 x i32], ptr @bits, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = and i32 %26, 1
  %32 = add nsw i32 %30, %31
  %33 = getelementptr inbounds [1048577 x i32], ptr @bits, i64 0, i64 %indvars.iv
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = add nsw i32 %32, -1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [21 x i32], ptr @e, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = and i32 %37, %26
  %.not1921 = icmp eq i32 %38, 0
  br i1 %.not1921, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %.lr.ph29
  %39 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %indvars.iv
  %.promoted = load i32, ptr %39, align 4, !tbaa !5
  br label %40

._crit_edge25:                                    ; preds = %40, %.lr.ph29
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge30, label %.lr.ph29, !llvm.loop !11

40:                                               ; preds = %.lr.ph24, %40
  %spec.select26 = phi i32 [ %.promoted, %.lr.ph24 ], [ %spec.select, %40 ]
  %.01622 = phi i32 [ %38, %.lr.ph24 ], [ %50, %40 ]
  %41 = sub nsw i32 0, %.01622
  %42 = and i32 %.01622, %41
  %43 = xor i32 %42, %26
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1048577 x i32], ptr @f, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %spec.select26, %46
  %48 = icmp sgt i32 %47, 998244352
  %49 = add nsw i32 %47, -998244353
  %spec.select = select i1 %48, i32 %49, i32 %47
  store i32 %spec.select, ptr %39, align 4, !tbaa !5
  %50 = xor i32 %42, %.01622
  %.not19 = icmp eq i32 %42, %.01622
  br i1 %.not19, label %._crit_edge25, label %40, !llvm.loop !12
}

; 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: nofree nounwind
declare noundef i32 @printf(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" }
attributes #2 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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