; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0828_ARC060/E3.ll (Z4initv)

; 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
@x = external dso_local global [100010 x i32], align 16
@L = external dso_local global i32, align 4
@memo = external dso_local global [100010 x [18 x i32]], align 16

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

3:                                                ; preds = %32, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %33

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sub nsw i32 %11, %15
  %17 = load i32, ptr @L, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %29

19:                                               ; preds = %7
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %24
  %26 = getelementptr inbounds [18 x i32], ptr %25, i64 0, i64 0
  store i32 %22, ptr %26, align 8, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %1, align 4, !tbaa !5
  br label %32

29:                                               ; preds = %7
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %29, %19
  br label %3, !llvm.loop !9

33:                                               ; preds = %3
  br label %34

34:                                               ; preds = %38, %33
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = load i32, ptr @N, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %47

38:                                               ; preds = %34
  %39 = load i32, ptr @N, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %42
  %44 = getelementptr inbounds [18 x i32], ptr %43, i64 0, i64 0
  store i32 %40, ptr %44, align 8, !tbaa !5
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %1, align 4, !tbaa !5
  br label %34, !llvm.loop !11

47:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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
@x = external dso_local local_unnamed_addr global [100010 x i32], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@memo = external dso_local local_unnamed_addr global [100010 x [18 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %0
  %3 = load i32, ptr @L, align 4, !tbaa !5
  br label %11

.preheader:                                       ; preds = %26, %0
  %.011.lcssa = phi i32 [ 0, %0 ], [ %.112, %26 ]
  %4 = icmp slt i32 %.011.lcssa, %1
  br i1 %4, label %.lr.ph18, label %._crit_edge

.lr.ph18:                                         ; preds = %.preheader
  %5 = add nsw i32 %1, -1
  %6 = sext i32 %.011.lcssa to i64
  %wide.trip.count = sext i32 %1 to i64
  %7 = sub nsw i64 %wide.trip.count, %6
  %xtraiter = and i64 %7, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph18, %.prol.preheader
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.prol.preheader ], [ %6, %.lr.ph18 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph18 ]
  %8 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %indvars.iv.prol
  store i32 %5, ptr %8, align 8, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !9

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph18
  %indvars.iv.unr = phi i64 [ %6, %.lr.ph18 ], [ %indvars.iv.next.prol, %.prol.preheader ]
  %9 = sub nsw i64 %6, %wide.trip.count
  %10 = icmp ugt i64 %9, -4
  br i1 %10, label %._crit_edge, label %.lr.ph18.new

11:                                               ; preds = %.lr.ph, %26
  %.015 = phi i32 [ 1, %.lr.ph ], [ %.1, %26 ]
  %.01114 = phi i32 [ 0, %.lr.ph ], [ %.112, %26 ]
  %12 = sext i32 %.015 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %.01114 to i64
  %16 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sub nsw i32 %14, %17
  %19 = icmp sgt i32 %18, %3
  br i1 %19, label %20, label %24

20:                                               ; preds = %11
  %21 = add nsw i32 %.015, -1
  %22 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %15
  store i32 %21, ptr %22, align 8, !tbaa !5
  %23 = add nsw i32 %.01114, 1
  br label %26

24:                                               ; preds = %11
  %25 = add nsw i32 %.015, 1
  br label %26

26:                                               ; preds = %24, %20
  %.112 = phi i32 [ %23, %20 ], [ %.01114, %24 ]
  %.1 = phi i32 [ %21, %20 ], [ %25, %24 ]
  %27 = icmp slt i32 %.1, %1
  br i1 %27, label %11, label %.preheader, !llvm.loop !11

.lr.ph18.new:                                     ; preds = %.prol.loopexit, %.lr.ph18.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph18.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %28 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %indvars.iv
  store i32 %5, ptr %28, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %29 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %indvars.iv.next
  store i32 %5, ptr %29, align 8, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %30 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %indvars.iv.next.1
  store i32 %5, ptr %30, align 8, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %31 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %indvars.iv.next.2
  store i32 %5, ptr %31, align 8, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph18.new, !llvm.loop !13

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph18.new, %.preheader
  ret void
}

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


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