; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2018-19/Jan 2019/Plat/tracking2.ll (Z5genDPii)

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

@K = external dso_local global i32, align 4
@dp = external dso_local global [100001 x i32], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3mulEiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp2ADERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3SUBERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3MULERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5modOp2poEiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5genDPii(i32 noundef %0, i32 noundef %1) #2 {
  %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 %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sub nsw i32 1000000000, %8
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 1, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %48, %2
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %51

16:                                               ; preds = %10
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = call noundef i32 @_ZN5modOp3MULERiii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %17, i32 noundef 1000000007)
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr @K, align 4, !tbaa !5
  %21 = sub nsw i32 %19, %20
  %22 = sub nsw i32 %21, 1
  %23 = icmp sge i32 %22, 0
  br i1 %23, label %24, label %37

24:                                               ; preds = %16
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr @K, align 4, !tbaa !5
  %27 = call noundef i32 @_ZN5modOp2poEiii(i32 noundef %25, i32 noundef %26, i32 noundef 1000000007)
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr @K, align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = call noundef i32 @_ZN5modOp3mulEiii(i32 noundef %27, i32 noundef %34, i32 noundef 1000000007)
  %36 = call noundef i32 @_ZN5modOp3SUBERiii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %35, i32 noundef 1000000007)
  br label %37

37:                                               ; preds = %24, %16
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = call noundef i32 @_ZN5modOp2ADERiii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %42, i32 noundef 1000000007)
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %37
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %10, !llvm.loop !9

51:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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


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

@K = external dso_local local_unnamed_addr global i32, align 4
@dp = external dso_local local_unnamed_addr global [100001 x i32], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3mulEiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp2ADERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3SUBERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5modOp3MULERiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5modOp2poEiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5genDPii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %4 = sub nsw i32 1000000000, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  store i32 1, ptr @dp, align 16, !tbaa !5
  %.not10 = icmp slt i32 %1, 1
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %20, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %indvars12 = trunc i64 %indvars.iv to i32
  %6 = call noundef i32 @_ZN5modOp3MULERiii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %4, i32 noundef 1000000007)
  %7 = load i32, ptr @K, align 4, !tbaa !5
  %8 = sub i32 %7, %indvars12
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %20

10:                                               ; preds = %.lr.ph
  %11 = call noundef i32 @_ZN5modOp2poEiii(i32 noundef %4, i32 noundef %7, i32 noundef 1000000007)
  %12 = load i32, ptr @K, align 4, !tbaa !5
  %13 = xor i32 %12, -1
  %14 = add i32 %indvars12, %13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = call noundef i32 @_ZN5modOp3mulEiii(i32 noundef %11, i32 noundef %17, i32 noundef 1000000007)
  %19 = call noundef i32 @_ZN5modOp3SUBERiii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %18, i32 noundef 1000000007)
  br label %20

20:                                               ; preds = %10, %.lr.ph
  %21 = add nsw i64 %indvars.iv, -1
  %22 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = call noundef i32 @_ZN5modOp2ADERiii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %23, i32 noundef 1000000007)
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = getelementptr inbounds [100001 x i32], ptr @dp, i64 0, i64 %indvars.iv
  store i32 %25, ptr %26, align 4, !tbaa !5
  %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_edge, label %.lr.ph, !llvm.loop !9
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass