; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Codeforces Round #271 (Div. 2)/D. Flowers.ll (Z3prel)

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

@dp = external dso_local global [100007 x i64], 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
define dso_local void @_Z3prel(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  store i64 1, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %34, %1
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp slt i64 %6, 100007
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = sub nsw i64 %10, 1
  %12 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %14
  store i64 %13, ptr %15, align 8, !tbaa !5
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = icmp sge i64 %16, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %9
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = sub nsw i64 %20, 1
  %22 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = sub nsw i64 %24, %25
  %27 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i64 %23, %28
  %30 = srem i64 %29, 1000000007
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %31
  store i64 %30, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %19, %9
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %3, align 8, !tbaa !5
  br label %5, !llvm.loop !9

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

38:                                               ; preds = %51, %37
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp slt i64 %39, 100007
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %38
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = sub nsw i64 %43, 1
  %45 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = add nsw i64 %49, %46
  store i64 %50, ptr %48, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %42
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %4, align 8, !tbaa !5
  br label %38, !llvm.loop !11

54:                                               ; preds = %41
  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 = { 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", !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"

@dp = external dso_local local_unnamed_addr global [100007 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prel(i64 noundef %0) local_unnamed_addr #0 {
  store i64 1, ptr @dp, align 16, !tbaa !5
  br label %2

2:                                                ; preds = %1, %11
  %3 = phi i64 [ 1, %1 ], [ %12, %11 ]
  %.01416 = phi i64 [ 1, %1 ], [ %13, %11 ]
  %4 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %.01416
  store i64 %3, ptr %4, align 8, !tbaa !5
  %.not = icmp slt i64 %.01416, %0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %2
  %6 = sub nsw i64 %.01416, %0
  %7 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add nsw i64 %8, %3
  %10 = srem i64 %9, 1000000007
  store i64 %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %2, %5
  %12 = phi i64 [ %3, %2 ], [ %10, %5 ]
  %13 = add nuw nsw i64 %.01416, 1
  %exitcond.not = icmp eq i64 %13, 100007
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !9

14:                                               ; preds = %.preheader
  ret void

.preheader:                                       ; preds = %11, %.preheader
  %15 = phi i64 [ %22, %.preheader ], [ 1, %11 ]
  %.017 = phi i64 [ %23, %.preheader ], [ 1, %11 ]
  %16 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %.017
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = add nsw i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !5
  %19 = add nuw nsw i64 %.017, 1
  %20 = getelementptr inbounds [100007 x i64], ptr @dp, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = add nsw i64 %21, %18
  store i64 %22, ptr %20, align 8, !tbaa !5
  %23 = add nuw nsw i64 %.017, 2
  %exitcond18.not.1 = icmp eq i64 %23, 100007
  br i1 %exitcond18.not.1, label %14, label %.preheader, !llvm.loop !11
}

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 = !{!"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}


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