; LLVM IR from kazunetakahashi/atcoder :: 2019/0217_nikkei2019-final/E.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 i64, align 8
@K = external dso_local global i64, align 8
@L = external dso_local global i64, align 8
@memo = external dso_local global [100010 x i64], align 16
@DP = external dso_local global [5010 x [5010 x i64]], align 16
@DP2 = external dso_local global [5010 x [5010 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z5poweri(i32 noundef) #0

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

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

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

8:                                                ; preds = %4
  %9 = load i32, ptr %1, align 4, !tbaa !9
  %10 = sub nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100010 x i64], ptr @memo, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = mul nsw i64 %13, 2
  %15 = load i32, ptr %1, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i64], ptr @memo, i64 0, i64 %16
  store i64 %14, ptr %17, align 8, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100010 x i64], ptr @memo, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = srem i64 %21, 1000000007
  store i64 %22, ptr %20, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %8
  %24 = load i32, ptr %1, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %1, align 4, !tbaa !9
  br label %4, !llvm.loop !11

26:                                               ; preds = %7
  %27 = load i64, ptr @N, align 8, !tbaa !5
  %28 = load i64, ptr @K, align 8, !tbaa !5
  %29 = sub nsw i64 %27, %28
  store i64 %29, ptr @L, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %42, %26
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr @L, align 8, !tbaa !5
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %45

36:                                               ; preds = %30
  %37 = load i32, ptr %2, align 4, !tbaa !9
  %38 = call noundef i64 @_Z5poweri(i32 noundef %37)
  %39 = load i32, ptr %2, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %40
  store i64 %38, ptr %41, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %36
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %2, align 4, !tbaa !9
  br label %30, !llvm.loop !13

45:                                               ; preds = %35
  %46 = load i64, ptr @DP, align 16, !tbaa !5
  store i64 %46, ptr @DP2, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %72, %45
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = load i64, ptr @L, align 8, !tbaa !5
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %75

53:                                               ; preds = %47
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = add nsw i64 %58, %62
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %65
  store i64 %63, ptr %66, align 8, !tbaa !5
  %67 = load i32, ptr %3, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = srem i64 %70, 1000000007
  store i64 %71, ptr %69, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %53
  %73 = load i32, ptr %3, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %3, align 4, !tbaa !9
  br label %47, !llvm.loop !14

75:                                               ; preds = %52
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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 i64, align 8
@K = external dso_local local_unnamed_addr global i64, align 8
@L = external dso_local local_unnamed_addr global i64, align 8
@memo = external dso_local local_unnamed_addr global [100010 x i64], align 16
@DP = external dso_local local_unnamed_addr global [5010 x [5010 x i64]], align 16
@DP2 = external dso_local local_unnamed_addr global [5010 x [5010 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z5poweri(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  store i64 1, ptr @memo, align 16, !tbaa !5
  br label %7

1:                                                ; preds = %7
  %2 = load i64, ptr @N, align 8, !tbaa !5
  %3 = load i64, ptr @K, align 8, !tbaa !5
  %4 = sub nsw i64 %2, %3
  store i64 %4, ptr @L, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %1
  %6 = load i64, ptr @DP, align 16, !tbaa !5
  store i64 %6, ptr @DP2, align 16, !tbaa !5
  br label %._crit_edge24

7:                                                ; preds = %12, %0
  %8 = phi i64 [ 1, %0 ], [ %15, %12 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %12 ]
  %9 = shl nsw i64 %8, 1
  %10 = getelementptr inbounds [100010 x i64], ptr @memo, i64 0, i64 %indvars.iv
  %11 = srem i64 %9, 1000000007
  store i64 %11, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100010
  br i1 %exitcond.not, label %1, label %12, !llvm.loop !9

12:                                               ; preds = %7
  %13 = shl nsw i64 %11, 1
  %14 = getelementptr inbounds [100010 x i64], ptr @memo, i64 0, i64 %indvars.iv.next
  %15 = srem i64 %13, 1000000007
  store i64 %15, ptr %14, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %7

._crit_edge:                                      ; preds = %.lr.ph
  %16 = load i64, ptr @DP, align 16, !tbaa !5
  store i64 %16, ptr @DP2, align 16, !tbaa !5
  %17 = icmp sgt i64 %23, 1
  br i1 %17, label %.lr.ph23.preheader, label %._crit_edge24

.lr.ph23.preheader:                               ; preds = %._crit_edge
  %18 = add nsw i64 %23, -1
  %xtraiter = and i64 %18, 1
  %19 = icmp eq i64 %23, 2
  br i1 %19, label %._crit_edge24.loopexit.unr-lcssa, label %.lr.ph23.preheader.new

.lr.ph23.preheader.new:                           ; preds = %.lr.ph23.preheader
  %unroll_iter = and i64 %18, -2
  br label %.lr.ph23

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph ], [ 0, %1 ]
  %20 = trunc nuw nsw i64 %indvars.iv27 to i32
  %21 = tail call noundef i64 @_Z5poweri(i32 noundef %20)
  %22 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %indvars.iv27
  store i64 %21, ptr %22, align 8, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %23 = load i64, ptr @L, align 8, !tbaa !5
  %24 = icmp sgt i64 %23, %indvars.iv.next28
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge24.loopexit.unr-lcssa:                 ; preds = %.lr.ph23, %.lr.ph23.preheader
  %.unr = phi i64 [ %16, %.lr.ph23.preheader ], [ %40, %.lr.ph23 ]
  %indvars.iv30.unr = phi i64 [ 1, %.lr.ph23.preheader ], [ %indvars.iv.next31.1, %.lr.ph23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge24, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %._crit_edge24.loopexit.unr-lcssa
  %25 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %indvars.iv30.unr
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = add nsw i64 %26, %.unr
  %28 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %indvars.iv30.unr
  %29 = srem i64 %27, 1000000007
  store i64 %29, ptr %28, align 8, !tbaa !5
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %.lr.ph23.epil, %._crit_edge24.loopexit.unr-lcssa, %._crit_edge.thread, %._crit_edge
  ret void

.lr.ph23:                                         ; preds = %.lr.ph23, %.lr.ph23.preheader.new
  %30 = phi i64 [ %16, %.lr.ph23.preheader.new ], [ %40, %.lr.ph23 ]
  %indvars.iv30 = phi i64 [ 1, %.lr.ph23.preheader.new ], [ %indvars.iv.next31.1, %.lr.ph23 ]
  %niter = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %niter.next.1, %.lr.ph23 ]
  %31 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %indvars.iv30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %30
  %34 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %indvars.iv30
  %35 = srem i64 %33, 1000000007
  store i64 %35, ptr %34, align 8, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %36 = getelementptr inbounds [5010 x i64], ptr @DP, i64 0, i64 %indvars.iv.next31
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = add nsw i64 %37, %35
  %39 = getelementptr inbounds [5010 x i64], ptr @DP2, i64 0, i64 %indvars.iv.next31
  %40 = srem i64 %38, 1000000007
  store i64 %40, ptr %39, align 8, !tbaa !5
  %indvars.iv.next31.1 = add nuw nsw i64 %indvars.iv30, 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 %._crit_edge24.loopexit.unr-lcssa, label %.lr.ph23, !llvm.loop !12
}

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

!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 = !{!"long long", !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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass