; LLVM IR from tangjz/acm-icpc :: codeforces/gym/104068G.ll (Z7preparev)

; 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"

@bin = external dso_local global [5 x [1000001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7preparev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %13, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1000001
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %11
  store i32 1, ptr %12, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %9
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !9

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

17:                                               ; preds = %69, %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 5
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %22 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %22, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %65, %21
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 1000001
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %23
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000001 x i32], ptr %31, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000001 x i32], ptr %39, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %36, %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000001 x i32], ptr %48, i64 0, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !5
  %52 = icmp sge i32 %45, 998244353
  br i1 %52, label %53, label %63

53:                                               ; preds = %27
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1000001 x i32], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sub nsw i32 %60, 998244353
  store i32 %61, ptr %59, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br label %63

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

65:                                               ; preds = %63
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !11

68:                                               ; preds = %26
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %2, align 4, !tbaa !5
  br label %17, !llvm.loop !12

72:                                               ; preds = %20
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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"

@bin = external dso_local local_unnamed_addr global [5 x [1000001 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7preparev() local_unnamed_addr #0 {
vector.ph:
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.4, %vector.body ]
  %0 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %index
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %0, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %1, align 16, !tbaa !5
  %index.next = add nuw nsw i64 %index, 8
  %2 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %index.next
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %2, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %3, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 16
  %4 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %index.next.1
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %4, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %5, align 16, !tbaa !5
  %index.next.2 = add nuw nsw i64 %index, 24
  %6 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %index.next.2
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %6, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %7, align 16, !tbaa !5
  %index.next.3 = add nuw nsw i64 %index, 32
  %8 = getelementptr inbounds [1000001 x i32], ptr @bin, i64 0, i64 %index.next.3
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %8, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %9, align 16, !tbaa !5
  %index.next.4 = add nuw nsw i64 %index, 40
  %10 = icmp eq i64 %index.next.4, 1000000
  br i1 %10, label %scalar.ph, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %vector.body
  store i32 1, ptr getelementptr inbounds (i8, ptr @bin, i64 4000000), align 16, !tbaa !5
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @bin, i64 4000004), align 4, !tbaa !5
  br label %59

.preheader.1:                                     ; preds = %59
  %.pre32 = load i32, ptr getelementptr inbounds (i8, ptr @bin, i64 8000012), align 4, !tbaa !5
  br label %11

11:                                               ; preds = %20, %.preheader.1
  %12 = phi i32 [ %.pre32, %.preheader.1 ], [ %spec.select.1.1, %20 ]
  %indvars.iv26.1 = phi i64 [ 2, %.preheader.1 ], [ %indvars.iv.next27.1.1, %20 ]
  %13 = add nsw i64 %indvars.iv26.1, -1
  %14 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 1, i64 %13
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %16 = add nsw i32 %12, %15
  %17 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 2, i64 %indvars.iv26.1
  %18 = icmp sgt i32 %16, 998244352
  %19 = add nsw i32 %16, -998244353
  %spec.select.1 = select i1 %18, i32 %19, i32 %16
  store i32 %spec.select.1, ptr %17, align 8, !tbaa !5
  %exitcond29.1.not = icmp eq i64 %indvars.iv26.1, 1000000
  br i1 %exitcond29.1.not, label %.preheader.2, label %20, !llvm.loop !13

20:                                               ; preds = %11
  %indvars.iv.next27.1 = or disjoint i64 %indvars.iv26.1, 1
  %21 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 1, i64 %indvars.iv26.1
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %spec.select.1, %22
  %24 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 2, i64 %indvars.iv.next27.1
  %25 = icmp sgt i32 %23, 998244352
  %26 = add nsw i32 %23, -998244353
  %spec.select.1.1 = select i1 %25, i32 %26, i32 %23
  store i32 %spec.select.1.1, ptr %24, align 4, !tbaa !5
  %indvars.iv.next27.1.1 = add nuw nsw i64 %indvars.iv26.1, 2
  br label %11

.preheader.2:                                     ; preds = %11
  %.pre33 = load i32, ptr getelementptr inbounds (i8, ptr @bin, i64 12000020), align 4, !tbaa !5
  br label %27

27:                                               ; preds = %27, %.preheader.2
  %28 = phi i32 [ %.pre33, %.preheader.2 ], [ %spec.select.2.1, %27 ]
  %indvars.iv26.2 = phi i64 [ 3, %.preheader.2 ], [ %indvars.iv.next27.2.1, %27 ]
  %29 = add nsw i64 %indvars.iv26.2, -1
  %30 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 2, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %28, %31
  %33 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 3, i64 %indvars.iv26.2
  %34 = icmp sgt i32 %32, 998244352
  %35 = add nsw i32 %32, -998244353
  %spec.select.2 = select i1 %34, i32 %35, i32 %32
  store i32 %spec.select.2, ptr %33, align 4, !tbaa !5
  %indvars.iv.next27.2 = add nuw nsw i64 %indvars.iv26.2, 1
  %36 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 2, i64 %indvars.iv26.2
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %spec.select.2, %37
  %39 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 3, i64 %indvars.iv.next27.2
  %40 = icmp sgt i32 %38, 998244352
  %41 = add nsw i32 %38, -998244353
  %spec.select.2.1 = select i1 %40, i32 %41, i32 %38
  store i32 %spec.select.2.1, ptr %39, align 4, !tbaa !5
  %indvars.iv.next27.2.1 = add nuw nsw i64 %indvars.iv26.2, 2
  %exitcond29.2.not.1 = icmp eq i64 %indvars.iv.next27.2.1, 1000001
  br i1 %exitcond29.2.not.1, label %.preheader.3, label %27, !llvm.loop !13

.preheader.3:                                     ; preds = %27
  %.pre34 = load i32, ptr getelementptr inbounds (i8, ptr @bin, i64 16000028), align 4, !tbaa !5
  br label %42

42:                                               ; preds = %51, %.preheader.3
  %43 = phi i32 [ %.pre34, %.preheader.3 ], [ %spec.select.3.1, %51 ]
  %indvars.iv26.3 = phi i64 [ 4, %.preheader.3 ], [ %indvars.iv.next27.3.1, %51 ]
  %44 = add nsw i64 %indvars.iv26.3, -1
  %45 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 3, i64 %44
  %46 = load i32, ptr %45, align 8, !tbaa !5
  %47 = add nsw i32 %43, %46
  %48 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 4, i64 %indvars.iv26.3
  %49 = icmp sgt i32 %47, 998244352
  %50 = add nsw i32 %47, -998244353
  %spec.select.3 = select i1 %49, i32 %50, i32 %47
  store i32 %spec.select.3, ptr %48, align 8, !tbaa !5
  %exitcond29.3.not = icmp eq i64 %indvars.iv26.3, 1000000
  br i1 %exitcond29.3.not, label %58, label %51, !llvm.loop !13

51:                                               ; preds = %42
  %indvars.iv.next27.3 = or disjoint i64 %indvars.iv26.3, 1
  %52 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 3, i64 %indvars.iv26.3
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %spec.select.3, %53
  %55 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 4, i64 %indvars.iv.next27.3
  %56 = icmp sgt i32 %54, 998244352
  %57 = add nsw i32 %54, -998244353
  %spec.select.3.1 = select i1 %56, i32 %57, i32 %54
  store i32 %spec.select.3.1, ptr %55, align 4, !tbaa !5
  %indvars.iv.next27.3.1 = add nuw nsw i64 %indvars.iv26.3, 2
  br label %42

58:                                               ; preds = %42
  ret void

59:                                               ; preds = %59, %scalar.ph
  %60 = phi i32 [ %.pre, %scalar.ph ], [ %spec.select.136, %59 ]
  %indvars.iv26 = phi i64 [ 1, %scalar.ph ], [ %indvars.iv.next27.137, %59 ]
  %61 = add nsw i64 %indvars.iv26, -1
  %62 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = add nsw i32 %60, %63
  %65 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 1, i64 %indvars.iv26
  %66 = icmp sgt i32 %64, 998244352
  %67 = add nsw i32 %64, -998244353
  %spec.select = select i1 %66, i32 %67, i32 %64
  store i32 %spec.select, ptr %65, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %68 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 0, i64 %indvars.iv26
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = add nsw i32 %spec.select, %69
  %71 = getelementptr inbounds [5 x [1000001 x i32]], ptr @bin, i64 0, i64 1, i64 %indvars.iv.next27
  %72 = icmp sgt i32 %70, 998244352
  %73 = add nsw i32 %70, -998244353
  %spec.select.136 = select i1 %72, i32 %73, i32 %70
  store i32 %spec.select.136, ptr %71, align 4, !tbaa !5
  %indvars.iv.next27.137 = add nuw nsw i64 %indvars.iv26, 2
  %exitcond29.not.1 = icmp eq i64 %indvars.iv.next27.137, 1000001
  br i1 %exitcond29.not.1, label %.preheader.1, label %59, !llvm.loop !13
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass