; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Other/DIBZ2016/DZ16SHOP/A.ll (Z12reinitializei)

; 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
@match = external dso_local global [310 x [310 x i32]], align 16

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

7:                                                ; preds = %29, %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

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

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

13:                                               ; preds = %25, %12
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [310 x [310 x i32]], ptr @match, i64 0, i64 %20
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [310 x i32], ptr %21, i64 0, i64 %23
  store i32 0, ptr %24, align 4, !tbaa !5
  br label %25

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

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !11

32:                                               ; preds = %11
  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}


; 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 local_unnamed_addr global i32, align 4
@match = external dso_local local_unnamed_addr global [310 x [310 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z12reinitializei(i32 noundef %0) local_unnamed_addr #0 {
  store i32 %0, ptr @n, align 4, !tbaa !5
  %.not11 = icmp slt i32 %0, 1
  br i1 %.not11, label %._crit_edge13, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %2 = zext nneg i32 %0 to i64
  %3 = shl nuw nsw i64 %2, 2
  %xtraiter = and i64 %2, 7
  %4 = icmp ult i32 %0, 8
  br i1 %4, label %._crit_edge13.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %2, 2147483640
  br label %.preheader

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %indvar = phi i64 [ 0, %.preheader.preheader.new ], [ %indvar.next.7, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.7, %.preheader ]
  %5 = mul nuw nsw i64 %indvar, 1240
  %gep = getelementptr i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 %5
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep, i8 0, i64 %3, i1 false), !tbaa !5
  %6 = mul nuw i64 %indvar, 1240
  %gep15 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 1240), i64 %6
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep15, i8 0, i64 %3, i1 false), !tbaa !5
  %7 = mul nuw i64 %indvar, 1240
  %gep16 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 2480), i64 %7
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep16, i8 0, i64 %3, i1 false), !tbaa !5
  %8 = mul nuw i64 %indvar, 1240
  %gep17 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 3720), i64 %8
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep17, i8 0, i64 %3, i1 false), !tbaa !5
  %9 = mul nuw i64 %indvar, 1240
  %gep18 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 4960), i64 %9
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep18, i8 0, i64 %3, i1 false), !tbaa !5
  %10 = mul nuw i64 %indvar, 1240
  %gep19 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 6200), i64 %10
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep19, i8 0, i64 %3, i1 false), !tbaa !5
  %11 = mul nuw i64 %indvar, 1240
  %gep20 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 7440), i64 %11
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep20, i8 0, i64 %3, i1 false), !tbaa !5
  %12 = mul nuw i64 %indvar, 1240
  %gep21 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 8680), i64 %12
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep21, i8 0, i64 %3, i1 false), !tbaa !5
  %indvar.next.7 = add nuw nsw i64 %indvar, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge13.loopexit.unr-lcssa, label %.preheader, !llvm.loop !9

._crit_edge13.loopexit.unr-lcssa:                 ; preds = %.preheader, %.preheader.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.preheader ], [ %indvar.next.7, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge13, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge13.loopexit.unr-lcssa, %.preheader.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.epil ], [ %indvar.unr, %._crit_edge13.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge13.loopexit.unr-lcssa ]
  %13 = mul nuw nsw i64 %indvar.epil, 1240
  %gep.epil = getelementptr i8, ptr getelementptr inbounds (i8, ptr @match, i64 1244), i64 %13
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep.epil, i8 0, i64 %3, i1 false), !tbaa !5
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge13, label %.preheader.epil, !llvm.loop !11

._crit_edge13:                                    ; preds = %._crit_edge13.loopexit.unr-lcssa, %.preheader.epil, %1
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !12}
!12 = !{!"llvm.loop.unroll.disable"}


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